Repository navigation
Description
Summary
Replace hash routing with query-param routing, so the widget's route lives in the host page's
own URL: https://sahajayoga.nl/classes?atlas=/nl/amsterdam/1204.
This is the change the whole white-label/SEO program rests on. A URL fragment is never indexed
as a distinct URL by any search engine — #! was deprecated in 2015 and dropped in 2018 — so today
every event on every embed is the same URL to a crawler. A query string is a distinct, indexable
URL, needs no wildcard rewrite, and therefore works identically on WordPress, Wix, Weebly and
Joomla. Measured on two live Wix client domains: replaceState does not throw, the param
survives two animation frames and 2.5s of Wix's runtime booting, pushState grows history.length
correctly, and a cold load of ?atlas=/nl/amsterdam/1204 serves the page with the param intact.
It also removes an entire class of bug rather than adding a mode: the widget stops having any
opinion about a host's #anchor. The foreign-fragment branch (#92), the memory-mode consequences
(#115), and the two-spellings problem all go with it.
Stage R of the programme. Full context, evidence and staging:
.claude/reports/whitelabel-seo-program.md §5. Depends on #149 (merged).
Scope
In: query (default) and memory (degradation).
Out — routing=path lands with Stage C, deliberately. Its prefix now comes from the client
record rather than a script parameter, and that record arrives from clients/me after the router
must be constructed. Deriving the prefix from the pathname does not work: a deep link is
<mount>/<route> and splitting them needs the region tree, while the offline shortcut ("the first
two-letter lowercase segment is a country slug") breaks on any host with a locale prefix, e.g.
wemeditate.com/de/map/gb/london. Query covers 21 of the 31 legacy clients; path had exactly one,
and under the programme's C4 that client mounts the widget inside its own SSR page and wants
routing="memory" there anyway.
Until it lands, routing=path must warn and fall back to query — through
reportIntegrationWarning, the channel the loader already uses for host-integration mistakes. It
must not silently behave as query.
No back-compat. An arriving #!/gb/london is ignored; the widget opens at its default route.
No translator, no deletion criterion, nothing to remove later. Safe because the legacy origins still
serve the old build to every live client until #148 Part 2, so no real link is at risk.
What it inherits from #149
Already merged, so this consumes rather than creates it:
ROUTE_PARAM = 'atlas'andresolveRoute(scriptValue, pageSearch)(src/loader/config.ts) — the param name and the page-wins precedence are settled; read the resolved value asconfig.route.config.routing, andsafeLoaderPathguarding every route string.embed.config(src/config/embed.ts) as the boot singleton the widget reads.
Proposed changes
The engine
A custom react-router History. Verified against installed [email protected]:
Router/RouterProps/Navigator are stable public API and Navigator needs only createHref,
go, push, replace. encodeLocation is optional and must be omitted — the naive
implementation returns the host's pathname and poisons every matched route.
New:
src/lib/shape/routing.ts— pure: the?atlas=codec, the mount decision,hrefFor.src/lib/atlas-history.ts—createQueryHistory.src/router.tsx—AtlasRouter, owning the mode switch; used byWidget.tsxandmain.tsx.src/config/routing.tsx—RoutingContextcarryinghrefFor. Not a field onWidgetMode, which is a plain data object stories spread over.
Deleted: src/lib/shape/hash.ts, hash.test.ts, hash.router.test.tsx, claimFragment
(Widget.tsx), HASH_BASE, and the foreign-anchor branch.
Design points that are load-bearing
- One param carrying the whole relative route, nested:
?atlas=/search?center=4.9,52.3%26sort=distance. Flattening would put up to eight foreign params on a WordPress URL and need a projection overuse-filters.ts,use-sort.tsandlistResetKey. The URLs that must be indexable (/nl/amsterdam/1204) carry no nested query at all. - Join with
&when the host page already has a query. WordPress default permalinks are/?p=123, and that is precisely this feature's audience (src/lib/url.ts:38-42). createHrefreturns an absolute URL. This is the entire fix for the middle-click bug that fix(widget): survive foreign hashes and harden the mount path #92 and feat(widget): make memory-mode routing linkable where it matters #142 both deferred (src/config/mode.ts:22-25): in-widget hrefs become real, shareable host-domain URLs. Absolute rather than relative closes a protocol-relative hole on a//-pathname host and makes<base href>irrelevant.- Boot writes nothing. A fragment is never a cache key; a query param is, so writing one at boot gives the host's SEO tooling a second URL for one page. One exception:
AppShell's home-region redirect (src/App.tsx:190-197) must becomereplace: true, or a visitor's first Back press appears to do nothing. - Host
history.stateis merged, never replaced. React-router's own history writes{usr, key, idx}as the whole state;claimFragmentalready preserves host state and that reasoning generalises. - Never write an identical URL.
?qis rewritten per keystroke, so filter churn staysreplace. - Keep
resolveStack(pathname); do not adopt<Routes>/<Route>. The drawer stack renders the whole ancestor chain at once where<Routes>renders one match; nested<Route>+<Outlet>models layout nesting, which this is not; anddismissDepthcounts history, not URL ancestors.resolveStackis also pure and node-testable with no router at all, and the custom history is cheap because nothing matches routes.
⚠ Two traps that fail silently
Routerreturnsnullon a basename miss — this is fix(widget): survive foreign hashes and harden the mount path #92's blank widget with a new face. Guard and report rather than render nothing.location.keydefaults to"default". A history that does not mint a per-entry key collapsesrememberCamera(location.key)into one bucket for the whole session: back-navigation camera restore breaks, and every test stays green.- The internal path is decoded under query routing, so double-encoding is the easiest way to break
liège. Mirrorpath.test.ts's accent case in the codec spec.
Acceptance criteria
- The widget's route lives in
?atlas=on the host page;#!is never written and an arriving fragment is left untouched. - A cold load of
host/page?atlas=/nl/amsterdam/1204opens that route, and the host's other query parameters survive every in-widget navigation. -
<Link>renders an absolute href on the host's origin — middle-click, "copy link address" and open-in-new-tab all work. - Back/forward step through in-widget history;
location.state.depthsurvives, anddismissActionstill never pops the host's own entry. -
location.keydiffers per entry, so the camera-history restore keeps working. - Boot writes nothing to the URL, except the home-region redirect, which is a
replace. -
routing=pathwarns viareportIntegrationWarningand falls back to query. -
hash.ts, both its specs,claimFragmentandHASH_BASEare gone; nothing references a fragment. -
docs/embedding.md's "The URL, and your page's fragment" section is rewritten (it currently carries a note saying it is transitional), andCHANGELOG.mdrecords the URL-shape change. -
pnpm lint && pnpm typecheck && pnpm test:run && pnpm build && pnpm size && pnpm ladle:buildpass. - Write an implementation report to
.claude/reports/<issue-number>-<short-slug>.md.
Test strategy
Node lane carries the bulk: the codec round-trip (accents, &, +, ,, ?, already-encoded
%); safePath rejections ported verbatim from hash.test.ts; hrefFor preserving foreign host
params and refusing a protocol-relative href; the mount decision across modes.
jsdom — one new spec, routing.router.test.tsx, and it is justified by the exact cautionary
tale attached to the spec it replaces: hash.test.ts covered mountRoute exhaustively and still
missed that react-router writes #/!/x rather than #!/x. A custom History is a far larger
foreign contract than a basename was. Assert: <Link>'s absolute href with a foreign param
present · a click pushes and preserves the host's pathname, params and history.state ·
useSearchParams round-trips through the nested value without leaking · popstate restores
location.state.depth · location.key differs per entry · a safePath-rejected value renders
the root, not blank. Then delete hash.router.test.tsx, carrying its lesson forward as the new
file's header.
Browser (Playwright MCP) — a live pushState on a real cross-origin host page, which no lane
can attest.
Files affected
src/lib/shape/routing.ts,src/lib/atlas-history.ts,src/router.tsx,src/config/routing.tsx(new)src/lib/shape/hash.ts+ both specs,claimFragmentinsrc/Widget.tsx(deleted)src/Widget.tsx,src/main.tsx,src/config/mode.ts,src/App.tsxsrc/hooks/use-share-url.ts,src/lib/url.ts— revisit now that the widget's URL is a real onedocs/embedding.md,CHANGELOG.md,.claude/docs/architecture.md,.claude/rules/components.md
References
.claude/reports/whitelabel-seo-program.md§5 — the design and the two decisions above- feat(widget): split the embed into a smart loader and an element bundle #149 / feat(widget): split the embed into a smart loader and an element bundle #150 — the loader and the config surface this consumes
- fix(widget): survive foreign hashes and harden the mount path #92, feat(widget): make memory-mode routing linkable where it matters #115 — the foreign-anchor branch and the
<Link>href bug this removes
Metadata
Metadata
Assignees
Labels
Type
Fields
Hold Until
Activity
docs(embedding): correct what a sandboxed iframe actually blocks
docs(embedding): correct what a sandboxed iframe actually blocks
docs(embedding): correct what a sandboxed iframe actually blocks
docs(embedding): correct what a sandboxed iframe actually blocks
feat(widget): one slot question, and a compact card that works in an …
docs(comments): complete the STE comment sweep across src, tests and …