Repository navigation
Description
Summary
Several mount-path defects make the embed fragile on real host pages: a host URL carrying any pre-existing #anchor renders the widget blank; on a clean URL the mount-time hash write pushes a host history entry (first Back press appears to do nothing); a second copy of the embed script throws on customElements.define; a second <sahaj-atlas> instance silently reuses the first's API key and theme singletons; and a throw from Providers/BrandTheme — above the app's error boundary — blanks the widget with no fallback. Two adjacent correctness items ride along: the widget root sets no lang (WCAG 3.1.2 failure for any non-host-language embed) and an un-gated og:locale Helmet write mutates the host <head> in embed mode. Ship-blocker #2 + the §2 reliability gaps of the release-readiness review.
Evidence (verified against the working tree, 2026-08-06)
- Foreign hash → blank widget. The boot guard at
src/Widget.tsx:56–67writes the widget hash only when the hash is empty or exactly#!/#!/. A host URL already carrying#respond,#comment-123,#contactis left untouched; react-router's hash location then strips the!basename, getsnull, and renders nothing. No fallback, no test. - Mount pushes history. The same guard assigns
window.location.hash = ...(src/Widget.tsx:65) on a clean URL — a hash assignment adds a history entry, so the visitor's first Back press appears to do nothing. This contradicts the "never pop/pollute host history" contract the dismissal logic (dismissAction) otherwise carefully honours. - Unguarded define.
customElements.define('sahaj-atlas', …)atsrc/Widget.tsx:101has nocustomElements.get()guard — a second copy of the script (plausible: the docs name two different bundle URLs) throwsNotSupportedErrorin the host console. - Multi-instance fails silently.
src/Widget.tsx:40–42keeps the FIRSTapiKeyfor every later instance, andsrc/config/theme/BrandTheme.tsx:69–79documents the theme-root + system-watcher singletons ("Assumes one widget per page; a second concurrent embed would share these singletons"). - No boundary above Providers/BrandTheme. In
src/App.tsx:68–78the app'sResetErrorBoundarysits insideBrandTheme, so a throw fromProvidersorBrandThemeunmounts the widget silently (it does not take down the host page — but nothing renders and nothing reports). - No
langon the embedded subtree. The theme-root wrapper (src/Widget.tsx:83–88) sets onlyclassName+dir— a French widget on an English host announces with English pronunciation (WCAG 3.1.2). There is also no landmark on the widget root. - Un-gated head write.
src/App.tsx:163–165emits<meta property="og:locale">via Helmet unconditionally — in embed mode that mutates the host page's<head>.
Proposed changes
- Treat a hash that doesn't start with
#!as "no route" and boot atbasePath— without destroying the host's anchor. Options: render offbasePathin-memory until the first in-widget navigation, or defer the#!…hash write to that first navigation. Hard requirement either way: the widget renders AND the host's#anchorstill scroll-works on load. - Never push history at mount: use
history.replaceState(not a hash assignment) for any initial hash write on a clean URL. - Guard the definition: skip
customElements.definewhencustomElements.get('sahaj-atlas')already resolves. - Make multi-instance explicit: a second
<sahaj-atlas>on the same page renders a clear "one atlas per page" notice (orconsole.warn+ no-op) — decided and implemented, never silently running on instance A's key/theme. - Top-level boundary: add a minimal error boundary above
Providers/BrandThemewith a static, translation-free fallback — it must not depend on i18n, the theme engine, or the query client (anything that can itself be what failed). - Widget root a11y: set
lang={activeLocale}(reactive, likedir) on the theme root, and add a landmark —role="region"+ a localizedaria-label— on the widget root. - Gate the head write: emit
og:localeonly whenstandalone. - Extract the hash-classification decision ("foreign / ours / empty") as a pure helper in
src/lib/shape/so the node lane can test it (per.claude/rules/tests.md).
Acceptance criteria
- With the host URL carrying
#respond(and#comment-123), the widget renders its root view atbasePath, and the host page still scrolls to that anchor on load. - On a clean URL, mounting the widget adds no history entry — the first Back press leaves the page.
- A widget hash the visitor already navigated to (
#!/…) still wins at mount — deep links keep working, and a Widget re-render (locale change) never teleports back tobasePath(existingbootedsemantics preserved). - Loading the embed script twice does not throw
NotSupportedError(guarded viacustomElements.get). - A second
<sahaj-atlas>element on the same page produces the chosen explicit behavior (visible notice, orconsole.warn+ no-op) — never a silent run on instance A's API key or theme. - A forced throw from
Providers/BrandThemerenders the static translation-free fallback instead of a blank widget. - The widget root carries
lang(tracks the active locale, updating on language switch),role="region", and a localizedaria-label(new locale key added across all languages viapnpm i18n:add). -
og:localeis emitted only in standalone mode — the embed no longer writes to the host<head>. - Hash classification is a pure helper in
src/lib/shape/with co-located node-lane tests covering: empty hash,#!,#!/, a real widget route (#!/gb/london), foreign anchors (#respond,#comment-123), and hostile input (#!//evil.example,#!javascript:…— composing with the existingsafePathguard). - demo.html-based manual verification list executed and recorded in the implementation report: foreign-anchor URL, clean URL + Back press, double script include, two
<sahaj-atlas>instances, forced provider throw, non-Englishlocaleattribute announced correctly (VoiceOver or equivalent spot check). -
pnpm lint+pnpm typecheck+pnpm test:run+pnpm buildpass. - Write an implementation report to
.claude/reports/92-widget-mount-hardening.md— in the MAIN checkout at /Users/devindra/Documents/Projects/SahajAtlasWeb even when implementing from a worktree (the folder is gitignored) — covering what changed, what was deliberately NOT changed, and which readiness-report findings are resolved.
Files affected
Owned by this ticket:
src/Widget.tsxsrc/App.tsx- New small pure helpers in
src/lib/shape/+ their co-located*.test.ts
Parallel implementation: this ticket OWNS the files listed above; sibling release-hardening tickets are implemented concurrently, so changes outside the owned files must be avoided or kept strictly additive. src/config/theme/BrandTheme.tsx is cited as evidence only — if the multi-instance decision requires touching it, keep the change strictly additive; the new aria-label locale key is additive by nature (pnpm i18n:add across public/locales/*). Note the CSS-scoping sibling ticket may additively add a scope class to this file's theme-root wrapper — leave room for that.
References
.claude/reports/RELEASE_READINESS.md§2 (gaps), §3.1, ship-blocker Community Room not displayed on sahajayoga.ca website #2, Appendix B (local, gitignored — for repo-local implementers; all load-bearing evidence is inlined above)- react-router hash routing:
createHashLocation+stripBasenamereturnnullfor a location outside the basename — the mechanism behind the blank render - WCAG 3.1.2 (Language of Parts); WCAG landmark guidance for embedded regions
.claude/rules/tests.md— node-lane conventions for the pure-helper tests.claude/rules/i18n-and-state.md— the history-aware dismissal contract the mount path currently contradicts- Sibling ticket (same batch):
fix(ui): scope widget css so it cannot restyle the host page
Metadata
Metadata
Assignees
Labels
Type
Fields
Hold Until
Activity
fix(claude): close the gaps /code-review found in the widened list
chore(claude): widen the security-review trigger paths (#139)
feat(widget)!: route through a query parameter and remove hash routing (
feat(widget): implement routing=path (#165)