Skip to content

feat(widget)!: route through a query parameter and remove hash routing - #155

Merged
Ardnived merged 2 commits into
mainfrom
feat/query-routing
Aug 18, 2026
Merged

Ardnived merged 2 commits into
mainfrom
feat/query-routing

Conversation

@Ardnived

@Ardnived Ardnived commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Closes #154. Stage R of the white-label/SEO programme.

before   your-site.example/classes#!/gb/london
now      your-site.example/classes?atlas=/gb/london

This is the change the rest of the programme rests on. No search engine has ever treated a
fragment as a distinct URL — #! was deprecated in 2015 and dropped in 2018 — so every event on
every embed was the same URL to a crawler. A query string is indexable and needs no server
configuration from the host, which is why it works identically on WordPress, Wix, Weebly and
Joomla.

It removes a class of bug rather than adding a mode

The widget no longer reads or writes the fragment at all. The three-way ours/free/foreign
decision, the blank-widget failure of #92, the two spellings react-router normalised between, and
the entire foreign-anchor branch are gone — along with hash.ts and both its specs.

Three things fixed because the URL is finally real

  • <Link> hrefs are absolute host-origin URLs. Middle-click, "copy link address" and
    open-in-new-tab now work. That is the consequence fix(widget): survive foreign hashes and harden the mount path #92 recorded and feat(widget): make memory-mode routing linkable where it matters #142 explicitly left open,
    closed by createHref rather than by a special case.
  • useShareUrl resolves the event's route, not window.location.href — so sharing from the
    share or registration drawer no longer hands somebody the drawer. Report 115's finding 3, which
    was unfixable while the route lived in a fragment.
  • Sentry gains an atlas.route tag. The route used to be lost because it lived in the
    fragment; it now lives in the query, which hostPageUrl also strips, so the loss became total
    rather than incidental. It is ours rather than the host's, which is exactly why it may be sent
    when their query may not.

The engine

A hand-written History behind react-router's stable Router + Navigator. encodeLocation is
deliberately omitted — the obvious implementation returns the host's pathname and poisons every
route the app derives from location.pathname.

⚠ The trap it exists to avoid, and it fails silently: Router defaults location.key to a
constant, so a history that doesn't mint one per entry collapses every rememberCamera(location.key)
snapshot into a single bucket for the whole session — back-navigation restores the wrong viewport,
nothing else reads key, and every test stays green. mintKey() handles it and the jsdom spec
asserts distinct keys.

(An earlier revision of this description also listed Router returning null on a basename miss.
That is not reachable here — query routing passes no basename, so stripBasename is never
called. It was a real hazard for the planned path mode and becomes live again if that ships.)

Why not a built-in history instead of a hand-written one? React-router ships exactly three, and
none of them routes off a query parameter: UNSAFE_createBrowserHistory (pathname),
UNSAFE_createHashHistory (the fragment we are removing), UNSAFE_createMemoryHistory (no URL).
All three are UNSAFE_-prefixed — explicitly not public API — whereas this implementation depends
only on Router, Navigator, createPath and parsePath, which are public and stable. Adopting a
built-in would therefore increase coupling to react-router internals, not reduce it. The one real
alternative, MemoryRouter plus a URL-syncing effect, is not less custom code: it moves the same
logic into an effect, adds a second source of truth, and loses createHref — which means losing the
middle-click fix above, one of the three things this PR set out to deliver.

Other load-bearing choices: the host's own query parameters and history.state are both preserved
(WordPress's /?p=123 permalinks are precisely this feature's audience); boot writes nothing,
because a query parameter is a cache key and a second URL for one page; and / and , are
restored after encoding so a shared link stays readable.

Scope

Query + memory only. routing=path is accepted, warns through reportIntegrationWarning, and
falls back to query. Its prefix now comes from the client record rather than a script parameter,
and that record arrives after the router must be constructed — so it lands with the canonical
work. 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 breaks on any host with a locale
prefix (wemeditate.com/de/map/gb/london).

No back-compat for #! links, deliberately. The legacy origins still serve the old build to
every live client until #148 Part 2, so no real link is at risk, and there is no shim to delete
later.

Verification

lint, typecheck, test:run (1165 passing), build, size, ladle:build green — including a
credentialed build, since CI cannot reproduce the Sentry debug-ID cost (loader 3.4 KiB against
its 3.8 budget).

One new jsdom spec, routing.router.test.tsx, replacing hash.router.test.tsx and inheriting
its lesson: the pure spec covered the old mount decision exhaustively and still missed that
react-router normalised the basename. A custom History is a far larger foreign contract, so ten
agreements are asserted against the real router — the absolute href with a foreign param present,
push preserving the host's pathname/params/state, useSearchParams round-tripping through the
nested value without leaking, distinct keys per entry, and a refused route rendering the fallback
rather than nothing.

Browser-verified on a cross-origin host page carrying its own #respond anchor and ?p=123:
the fragment is untouched, the host parameter survives, boot writes nothing, and routing=path
logs its warning by name.

Docs

docs/embedding.md's URL section is rewritten — it carried a note saying it was transitional, and
this is the change it was waiting for. CHANGELOG.md, CLAUDE.md, architecture.md and four
rules files follow. The security-review trigger paths in finalize-pr were updated too: they still
named src/lib/shape/hash and src/config/privacy, both deleted, so routing changes would have
stopped triggering a review.

🤖 Generated with Claude Code

The widget's route moves from the URL fragment to a query parameter on the
host's own page:

  before   your-site.example/classes#!/gb/london
  now      your-site.example/classes?atlas=/gb/london

This is the change the rest of the SEO programme rests on. No search engine has
ever treated a fragment as a distinct URL — `#!` was deprecated in 2015 and
dropped in 2018 — so every event on every embed was the same URL to a crawler.
A query string is indexable and needs no server configuration from the host,
which is why it works identically on WordPress, Wix, Weebly and Joomla.

It removes a class of bug rather than adding a mode. The widget no longer reads
or writes the fragment at all, so the three-way ours/free/foreign decision, the
blank-widget failure of #92, the two spellings react-router normalised between,
and the whole foreign-anchor branch are simply gone.

Engine: a hand-written `History` behind react-router's stable `Router` +
`Navigator` (`src/lib/atlas-history.ts`, `src/router.tsx`). `encodeLocation` is
deliberately omitted — the obvious implementation returns the host's pathname
and poisons every derived route. Two traps the implementation exists to avoid,
both silent: `Router` returns null on a basename miss (#92's blank widget), and
it defaults `location.key` to a constant, which would collapse every
`rememberCamera` snapshot into one bucket with every test green.

Also fixed, because the URL is now real:

- `<Link>` hrefs are absolute host-origin URLs, so middle-click, "copy link
  address" and open-in-new-tab work. That is the consequence #92 recorded and
  #142 left open, closed by `createHref` rather than by a special case.
- `useShareUrl` resolves the EVENT's route instead of `window.location.href`,
  so sharing from the share or registration drawer no longer hands over the
  drawer. Report 115's finding 3, unfixable while the route was a fragment.
- Sentry gains an `atlas.route` tag. The route used to be lost because it lived
  in the fragment; it now lives in the query, which `hostPageUrl` also strips —
  so the loss became total. It is ours, not the host's, which is why it may be
  sent when their query may not.

Scope: query + memory only. `routing=path` is accepted, warns through
`reportIntegrationWarning` and falls back to query — its prefix comes from the
client record, which arrives after the router must exist, so it lands with the
canonical work. No back-compat for `#!` links, deliberately: the legacy origins
still serve every live client until #148 Part 2, so no real link is at risk.

Verified in a browser on a cross-origin host page carrying its own `#respond`
anchor and `?p=123`: the fragment is untouched, the host parameter survives,
boot writes nothing, and `routing=path` logs its warning by name. The jsdom
spec that replaces `hash.router.test.tsx` drives the real router for the ten
agreements a pure spec cannot attest.

Closes #154

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 18, 2026 •

Copy link
Copy Markdown

Deploying sahajatlas-design with  Cloudflare Pages  Cloudflare Pages

Latest commit: 8a7d8b5
Status: ✅  Deploy successful!
Preview URL: https://cea54153.sahajatlas-design.pages.dev
Branch Preview URL: https://feat-query-routing.sahajatlas-design.pages.dev

View logs

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 18, 2026 •

Copy link
Copy Markdown

Deploying sahajatlas with  Cloudflare Pages  Cloudflare Pages

Latest commit: 8a7d8b5
Status: ✅  Deploy successful!
Preview URL: https://2a29a207.sahajatlas.pages.dev
Branch Preview URL: https://feat-query-routing.sahajatlas.pages.dev

View logs

Two fixes, both about accuracy rather than behaviour.

The `Router`-returns-null-on-a-basename-miss trap was listed as one the query
history exists to avoid. It is not reachable: query routing passes no
`basename`, so `stripBasename` is never called. It was a real hazard for the
PLANNED path mode, which mounts under a prefix, and it becomes live again if
that ships — but claiming it here made the implementation look riskier than it
is and pointed a future reader at the wrong thing. The one trap that IS real
stays, and is asserted: `Router` defaults `location.key` to a constant, which
would collapse every `rememberCamera` snapshot into one bucket.

Also reads our history state once on popstate instead of twice. `currentState()`
MINTS a key when the entry has none — a host-created entry, or one predating the
widget — so calling it twice minted two and used only the first. Harmless today,
and exactly the kind of thing that stops being harmless the moment someone
trusts `idx`.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@Ardnived
Ardnived merged commit 840e311 into main Aug 18, 2026
5 checks passed
@Ardnived
Ardnived deleted the feat/query-routing branch August 18, 2026 18:25
Ardnived added a commit that referenced this pull request Aug 19, 2026
* feat(ui): de-brand the widget and keep host CSS out of it

Stage B of the white-label programme, and the one that states the goal
literally. The loader made the embed cheap (#150) and query routing made it
indexable (#155); this is the part a visitor sees.

**Nothing names the product any more.** The landmark's accessible name, the
"on Sahaj Atlas" link on the share and registration cards, the app-level error
title, the ICS `PRODID`, the page title and the typeface family — all neutral,
across all ten locales. A ratchet spec walks the locale bundles and a named list
of copy-carrying source files and fails if a brand string returns; it also
asserts the pattern leaves `sahaj-atlas`, `sy-atlas` and the origins alone,
because those are DOM identifiers hosts key off rather than copy.

⚠ `UID:event-<id>@atlas.sydevelopers.com` is deliberately unchanged and now says
so at the line: it is the calendar dedupe key, and moving it would make every
previously-exported event reappear as a second entry in somebody's calendar.

**`EventSummary` is deleted**, carrying over the one Atlas-side piece of the
blocked Stage C. It rendered both the brand label and an outbound link to
`event.webUrl` — a link that was never correct, and that becomes a link from the
host's page back to the host's page once canonicals point at the owning client.
Without it the component was a two-call-site alias over `EventFacts`.

**JSON-LD no longer credits We Meditate for every event in the world.** The
organizer comes from the client record and is omitted entirely when unknown: an
absent optional property is better structured data than a confidently false one.

**Host CSS is kept out**, via an unlayered `all: revert` over the scope subtree
plus an inherited-property baseline. Three things about it were verified in a
browser rather than assumed, and two were wrong on the first attempt:

- The baseline was written inside `@layer base` and therefore LOST to the
  unlayered reset directly above it — the widget rendered in the host's font
  with the host's letter-spacing. That is the `@layer` trap the rule's own
  comment warns about, fired at ourselves; it is unlayered now.
- Against a deliberately hostile stylesheet, non-`!important` host rules are
  fully blocked. **`!important` rules are not**, and cannot be: outranking them
  needs `all: revert !important`, which would beat our own styles and leave the
  widget unstyled. Documented for hosts, and the reason #157 exists.
- Cost measured rather than guessed: a forced recalc over 3,200 nodes inside the
  scope is ~2x one outside (41ms vs 20ms over five recalcs). Accepted — full
  recalcs are rare and the list is bounded by MAX_REVEAL.

**And one bug fix that is not branding**: the `theme` localStorage key was the
bare string `theme`, so a host page storing its own preference under that name
had it read and overwritten. Namespaced to `atlas.theme`, with a one-time read
of the old key so nobody loses a choice they already made.

Closes #156
Refs #157

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* fix(test): stop pinning the SPA shell by its brand name

The root smoke spec asserted `<title>Sahaj Atlas`, so de-branding the page title
failed it. The spec was only ever trying to prove "this is our shell rather than
an error page or the SPA fallback" — and a brand string is the wrong anchor for
that, in the worst way: it breaks precisely when the product does what this
programme set out to make it do.

Re-anchored on two structural markers that are actually load-bearing — the
`#syatlas` mount point and the `sy-atlas` scope class on <html> — plus a
non-empty title, which is the part that genuinely distinguishes a rendered shell
from a stray response.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* refactor(event): namespace the calendar UID to the CMS, not the widget host

The back-compat constraint I stated does not apply — the calendar export is not
live, so there are no already-exported entries to keep matching.

Removing it does not make the UID free, though. A different rule survives and is
the stronger one: **it must stay tenant-independent.** The same class can be
exported from several client embeds — a visitor might reach it from the national
site and again from a city one — and those must land in a calendar as ONE entry.
Anything client-derived in this string turns each embed into a separate event
for the same class.

So it moves from `@atlas.sydevelopers.com` to `@cloud.sydevelopers.com`: the
host part is an opaque namespace rather than a link, and the CMS is where the id
actually comes from. The old value pointed at an origin that is being
consolidated (#148) while the canonical moves to per-owner domains — neither of
which should be able to change an identifier whose whole job is to stay put.

The dedupe rule is now asserted rather than only described.

Refs #156

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
Ardnived added a commit that referenced this pull request Aug 25, 2026
* feat(widget): implement routing=path, now that the prefix has a source

`routing=path` has been accepted-and-not-honoured since #155, warning that the
prefix "is not wired up yet". SahajCloud #635 wired it up: `canonical.embed`
names the mount whose URLs a client owns, so the prefix now has exactly one
definition — the same one canonical URLs are composed from, which is why it is
deliberately not a script parameter.

The route becomes the pathname under that prefix (`/map/gb/london`), and the
widget's own state — searched place, filters, sort — goes on the real query
string rather than packed into one parameter. Packing it would defeat the point
of clean paths, and in this mode the host has dedicated the URL space to us. We
touch only parameters we own; a host's `?utm_source` survives every navigation.

**The prefix arrives over the network, after the router must exist.** That was
the sequencing problem #155 deferred on, and the answer is to wait: `AtlasBoot`
reads the client record before constructing the router, and only in path mode.
Query mode — every embed today — never reaches it. Waiting costs nothing in path
mode's own use case, where the host is already server-rendering the content the
visitor is reading. Booting at the root and adopting the URL later was the
alternative, and it puts a visible route change after first paint.

Every way path mode can fail degrades to query and SAYS which: no prefix on the
record, or a page served outside it. That second one is #92's blank widget in a
new form — react-router renders `null` on a basename miss, silently — which is
why the guard is ours rather than `Router`'s `basename`.

**Two bugs here were found in a browser and could not have been found otherwise,
because both produced the same symptom as a legitimate fallback.** The API key
was claimed one component below the prefix read, so the request went out
unauthenticated; and the tree's `QueryClientProvider` lives inside `App`, below
the router this read exists to construct, so `useSuspenseQuery` threw "No
QueryClient set". Each degraded to query while printing a warning that blamed the
client record, which was blameless. The boundary now reports why it fell back, so
the next one names its own cause instead of borrowing that alibi.

Verified against a real host: a wildcard-served subtree at `/pathmode/**` with a
client record carrying `canonical.embed`, and the readiness marker — which
attests the shape the router ACTUALLY used — reading `"routing":"path"` with no
fallback warning. The 22 new specs cover the pure layer, and six drive the real
react-router, per the lesson that a pure spec cannot prove the library agrees.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* fix(widget): claim the filter params path mode was silently dropping

`WIDGET_PARAMS` — the set of query names the path history lifts off the host's
URL and writes back — was hand-listed, and named a `filters` parameter that has
never existed. The seven real ones (`format`, `cadence`, `days`, `time`, `langs`,
`dates`, `region`) went unclaimed, so in `routing=path` every filter a visitor
set would have been discarded on the next navigation.

Found while writing the rule note warning that exactly this list could drift.

Both ways of getting it wrong are silent: a missing name drops the widget's own
state, and a surplus name steals one of the host's parameters. Query mode is
immune — it packs the whole route into a single parameter and never touches
theirs — so nothing else in the app would have gone red either way.

So it is now composed from the modules that own each name (`FILTER_PARAM_KEYS`,
newly exported for it, plus `SORT_PARAM` and `SEARCH_COUNTRY_PARAM`) rather than
restated, and `routing.test.ts` pins the set against those owners in both
directions — every owned name claimed, nothing a host would plausibly own taken.
Confirmed the assertion fails against the hand-listed version.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* fix(widget): triage the path-routing review — two ways it escaped its subtree

**`mountPrefix` root-mounted on any slashless value, which disabled the only
guard confining path mode.** `wemeditate.com`, `map`, a typo — all returned `''`,
and `routeFromPathname` short-circuits its segment-boundary check when the prefix
is empty, so the #92 basename-miss guard could not fire at all. A widget on
`/account/settings` would have adopted that URL as a route and rewritten it on
the first click. A root mount must now be spelled with its slash, exactly as
`splitMountKey` writes it; everything else is refused. `safePath` also moved
BEFORE the trailing-slash strip, since `host//` normalised to `''` and reached
the root-mount answer without ever meeting the guard `//evil.com` exists for.

**The host half of the mount key is now checked, and the docblock claiming it
need not be was wrong.** It argued that being on the wrong host is a
canonical-ownership question. It is a routing question: the prefix is the only
thing tying path mode to a subtree, and a client may nominate one embed while
running others elsewhere.

**`pathHrefFor` let a CMS `webPath` walk out of the mount subtree.** `safePath`
inspects the first two characters, so `/../../wp-admin` is "site-relative" by its
rules and the URL parser then resolves the dot segments. Not an origin escape —
the `pathname` setter cannot change the host — but an href leaving the widget and
a `pushState` renaming the visitor's page. Containment is asserted now.

**Path mode was poisoning the field it reads back.** The embed report files
`window.location`, and in path mode the route IS the pathname — so every
deep-linked route would have been filed as a separate mount, on the record that
is the source of `canonical.embed`. The operator's picker would fill with routes
and the 50-mount cap would be gone in a day. It files the subtree root now;
verified on the wire as `"pathname":"/pathmode"` from `/pathmode/gb/london`.

**`?locale=` is no longer claimed.** It is the widget's parameter but only ever a
page one — nothing writes it back, so claiming it deleted a visitor's language on
their first click, where query mode preserves it.

**The prefix read no longer wraps the application.** `PathPrefix` rendered
`<Atlas>` as its own child, putting the router and all of `App` inside the
boundary — so an unrelated crash was reported as `'path prefix'` and answered by
re-rendering without one, printing a warning that blamed a blameless record. It
also meant a failed BACKGROUND refetch after a reconnect would tear the widget
down and rebuild it in query mode over a path URL. Lifting the answer into state
fixes both: the observer unmounts once resolved.

Three of the six router specs were vacuous — each passed an `initialPath` equal
to the value it asserted, so `read() ?? initialPath` made them green with the
path shape returning nothing. Confirmed: they now fail against a broken read.
Added the case that would have caught the filter bug, plus traversal, host:port
and `?locale=`.

⚠ One fix here broke another case, and only a browser showed it: loosening the
scheme strip to refuse `javascript:` made `//` optional, which parses
`localhost:5173/pathmode` as scheme `localhost:` and host `5173`. A mount key
keeps its port. The `//` is required again, and the slashless rule refuses
`javascript:` anyway.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* test: stop three inherently slow specs flaking under a saturated pool

`href.test.ts` and the two jsdom `CompactEmbedView` specs pass in isolation and
intermittently fail the FULL run, each finishing in 5–7 s against vitest's 5 s
default. The first TypeScript-AST-walks every `src/**/*.tsx` to pin the
JSX-anchor inventory; the other two boot a DOM and mount a Radix dialog.

Pre-existing rather than caused by this branch — a reviewer observed the same two
`CompactEmbedView` failures against `main` — but this branch adds ~40 specs and
so makes it likelier, and a lane that reddens at random trains people to re-run
CI instead of reading it.

Nothing in these specs waits on a network or a timer, so the timeout was never
catching a hang; it was capping how slow an inherently slow spec may be while the
pool is saturated, on a machine faster than the CI runner. Raised to 20 s. The
lane's own speed budget is unchanged and still enforced the way it always was —
by not adding slow specs.

Two consecutive clean full runs.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* docs: retire the claims path routing made false, and name what it claims

Six places still described `routing=path` as unimplemented, including two that a
host reads. The `CHANGELOG` said "accepted but not yet available" about 130 lines
below the entry announcing it works — one unreleased block, so both read as
current. `mountDecision`'s own docblock said "not yet honoured" directly above
the sixty lines that honour it.

`detect.ts` carried an instruction addressed to this commit: restore the
`canonicalViable` exemption for `routing=path` once `mountDecision` honours it.
It is not restored, and the note now says why it never should be. Its stated
premise — that the effective shape was hard-coded — has expired, but the real
reason has not: `fingerprint()` runs in the LOADER at script execution, from
`config.routing` alone, while whether path routing is honoured depends on a
prefix arriving over the network afterwards and on the page matching it. From
there, `routing=path` is a request, not a finding, and exempting on a request is
exactly what let a query-routed mount claim to be canonical.

The host-facing contract also over-promised. `docs/embedding.md` said "anything
else on your URL is preserved" — true in query mode, false in path mode, which
claims twelve names on the pages under the prefix. They are enumerated now,
alongside the note that `locale` is read but never written, and a migration
warning: an already-shared `?atlas=` link opens the root view the day a host
switches, because the route is read from the path from then on.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* test(widget): assert our URLs against the shared canonical contract

SahajCloud composes canonical Atlas URLs; we take them apart again. The rules for
that were written down in `atlas-url-contract.json` when #640 landed, with a
`$comment` instructing all three repos to assert against it byte-identically —
and our side had neither the file nor a test. The plan called it "the one
bidirectional contract" and it was live on one side only.

It has already failed once in exactly the way the fixture exists to catch:
SahajCloud's first builder emitted `?atlas=events%2F12345`, percent-encoded with
no leading slash, which our `safeLoaderPath` refuses outright — so the widget
would have discarded the route and silently opened its default view. That was
caught by hand during a review of the other repo.

The fixture is copied byte-identically and the spec drives both directions over
all 13 emitted cases: every canonical URL parses back to the `webPath` it names
(`routeFromParam` for query, `routeFromPathname` for path), and path mode's own
composer reproduces the URL SahajCloud would have written. All 13 pass today,
which is the first evidence the two halves agree rather than an assumption.

The 8 refusal cases are deliberately not exercised — `expected: null` constrains
SahajCloud's BUILDER, and there is no URL for a parser to be handed, so asserting
anything from this side would be testing our own fake. Their count is pinned
instead, so the file cannot quietly shrink and still look covered.

Drift is a separate, deliberate check (`pnpm sync:atlas-contract`) rather than a
fetch in the unit lane, which must never touch the network — the same split
`pnpm types:cms` uses. Verified it reports clean today and detects a perturbed
version.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* docs: apply the session-reflection fixes

Five changes, each traceable to a specific way this session cost time or let
something through.

**A pipeline's exit status is not the command's.** I made this mistake twice:
`git push … && echo "pushed"` printed "pushed" on a rejected non-fast-forward,
and then `check.sh | grep … && git commit` committed on a RED lane, because `&&`
chained off `grep`. The second one actually let a bad state through, so it is a
hard rule in `finalize-pr` now rather than a note.

**A review finding's suggested fix is a proposal, not a patch.** A Low finding's
suggested regex, applied verbatim, broke every mount key carrying a port — with
lint, typecheck and 1300 specs green. Its premise had also already expired
against a later commit in the same review.

**"Make it fail" is not only for regression specs.** I added that rule last
session and then wrote three vacuous specs for a brand-new feature, because I
read it as covering regressions. `tests.md` also now names the local shape:
`read() ?? fallback` is everywhere here, so a spec asserting the value it passed
as the fallback proves nothing.

**Stubbing `clients/me` is how you see a rendered widget without a backend.** The
seeded local backend rejects every key, and this technique is currently the only
way around it. Three prerequisites are recorded because each cost time: the CORS
header (the API is another origin, and an unheadered fulfill looks exactly like a
rejected key), Playwright matching the most recently registered route first, and
the readiness marker needing to be polled because a later error boundary clears
it.

**The review harness gets a path-mode page** — the one deliberate exception to
its 404 rule, because serving a whole subtree from one document is precisely what
path routing asks of a host. Kept narrow to that prefix; verified the subtree
serves and everything else still 404s.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* refactor(widget): one claimed parameter in both routing modes

Path mode put the widget's state on the host's REAL query string, governed by
`WIDGET_PARAMS` — an allowlist of the twelve names the widget owns. Query mode
packed the whole route into `?atlas=` and claimed one. Two mechanisms for one
job, and the second was the least defensible thing in the design: both ways of
getting that list wrong were silent (a missing name dropped a filter on every
navigation, a surplus one stole a parameter from the host), it had already caused
one such bug, and it forced a host-facing promise into `embedding.md` enumerating
twelve names we take over on their pages.

The rule is now one sentence: **`?atlas=` carries whatever the path does not.** In
query mode the path carries nothing, so the parameter holds the whole route; in
path mode the pathname holds the route's path, so the parameter holds its query.
One claimed name, one encoder, one collision to document, in both modes.

It costs nothing where it matters. The URLs that have to be indexable — a region,
a venue, an event — carry no query at all; every `webPath` in the shared contract
is path-only, and the contract spec still passes unchanged. Filters and a sort
order are a reading position, and `?atlas=sort=soonest` is no worse to look at
than the packed form query mode has always shown.

`WIDGET_PARAMS`, `ownSearch` and the param-juggling in `pathHrefFor` are gone,
along with the `FILTER_PARAM_KEYS` export added last week to feed them. Verified
in a browser: a host page carrying `?q=hostvalue` — a name the old design claimed
— keeps it through a path-mode boot and navigation.

**Path mode also shows a loading state now**, which corrects a claim I made in
the docs. The wait is not an extra round trip: query mode suspends on the very
same `clients/me` request and renders `LoadingFallback` through it. Path mode was
simply rendering `null`, because the theme root and providers live below the
point where it waits. `BootSurface` is the smallest thing that can be styled —
and deliberately not `LoadingFallback`, which calls `useTranslation` and could
suspend inside a Suspense fallback.

⚠ `pnpm size` caught importing `Spinner` from the atoms BARREL: it pulled the
whole tier into the eager graph, 302.2 → 311.9 KiB, over budget. Imported
directly instead. Exactly the failure that gate exists for.

`mountDecision`'s four near-identical returns collapse into one local builder,
which also makes "memory reports the query shape" structural rather than a fact
repeated at each return.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* feat(i18n): follow the page's language, and stop reading it from the record

The widget's content should match the page it is embedded in. `<html lang>` says
that per page, every CMS already sets it, and until now the widget ignored it
entirely — falling through from the client record straight to the visitor's
browser, so a Dutch site could serve a German atlas to a German visitor.

The chain is now: `locale` on the script URL → `?locale=` on the page → the
host's `<html lang>` → the browser → English, with a viewer's own pick from the
settings menu overriding all of it for the session.

**The client record's `locale` is no longer read**, which is the other half of the
same idea: a record-level language says it once for every page a client embeds
on, and then has to be kept in step with a site that may not be monolingual. It
is dropped from the `select` and from `ClientSchema` as well as from `App`, so
nothing can quietly start reading it again — and the schema ignores the field
rather than rejecting it, or a client who has it set would blank the widget over
a setting we deliberately no longer honour.

⚠ **This is NOT i18next's built-in `htmlTag` detector, and that distinction is
load-bearing.** Our own standalone shell is `<html class="sy-atlas" lang="en">` —
a hard-coded placeholder describing nothing — so the built-in would read it and
pin every standalone visitor to English, silently undoing the browser detection
that works today. The scope class is the discriminator: it marks a document as
ours, and a host's page never carries it on `<html>`.

Two silent-failure modes are pinned by specs rather than prose: a name in
`detection.order` that no registered detector answers to is skipped without a
warning, so the order and the registration are asserted to agree; and the
refusal to read our own shell has its own case, since getting it wrong looks
exactly like working software in English.

Host-observable, so it is in CHANGELOG under Changed.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* fix(a11y): declare the language the standalone page is actually in

`index.html` ships `<html lang="en">` and nothing ever corrected it, so a French
visitor to the standalone build got French content announced with English
pronunciation. WCAG 3.1.1 asks a page to declare the language it is in; ours
declared a placeholder.

**`lang` is an OUTPUT here, not an input, and that asymmetry is the whole point.**
Embedded, the host's `<html lang>` describes THEIR content and is evidence the
widget reads (`hostHtmlLangDetector`, added last commit). Standalone, the
document is ours: `index.html`'s `lang="en"` is a pre-hydration default — correct
to ship, since a screen reader needs something before JS runs — and once a
language is resolved it is our job to say so. Same attribute, opposite roles,
decided by whose document it is.

No feedback loop, and that is not luck: the detector refuses to read a document
carrying our own scope class, so writing this back can never become the thing we
detect on the next load. The two changes only compose because that refusal was
built first.

`dir` goes with it, from `i18n.dir()`, so an RTL locale would flip the document
as well as the widget's own subtree — the ten shipped locales are all LTR today,
so this is future-proofing rather than a fix.

Verified in a browser with `navigator.language` overridden to `fr-FR`: content
renders French and `<html lang>` reads `fr`, where it previously read `en`. An
explicit `?locale=de` still wins and reads `de`. ⚠ Worth recording that
`setExtraHTTPHeaders({'Accept-Language': …})` does NOT simulate this — it sets
the header, while the detector reads `navigator.language`, so the first attempt
measured an English browser and looked like a failure.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(widget): route through a query parameter and remove hash routing

1 participant