Repository navigation
feat(widget): implement routing=path - #165
Merged
Merged
Conversation
`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]>
`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]>
… 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]>
`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]>
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]>
Deploying sahajatlas with
|
| Latest commit: |
70f7f23
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://2809d5bf.sahajatlas.pages.dev |
| Branch Preview URL: | https://feat-path-routing.sahajatlas.pages.dev |
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]>
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]>
Deploying sahajatlas-design with
|
| Latest commit: |
70f7f23
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://ab814710.sahajatlas-design.pages.dev |
| Branch Preview URL: | https://feat-path-routing.sahajatlas-design.pages.dev |
Ardnived
force-pushed
the
feat/path-routing
branch
from
August 24, 2026 21:22
4cabcd4 to
3e84457
Compare
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]>
…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]>
Contributor
Author
|
Follow-ups raised from the design discussion on this branch:
|
`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]>
Ardnived
added a commit
that referenced
this pull request
Aug 25, 2026
The entry cited `[#167]` with no definition, so it rendered as literal text — the same dangling-reference bug this branch already fixed for #165 one commit earlier, which is a fair sign the check should not be by eye. Every `[#NNN]` reference in the file now resolves. Note the label is the ISSUE number and the target is the PR (168), matching how the ticket is cited in the entry itself. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
15 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
routing=pathworks. The widget's route becomes the pathname under a prefix (/map/gb/london) instead of?atlas=/gb/london. It has been accepted-but-inert since feat(widget)!: route through a query parameter and remove hash routing #155, which warned that "the prefix is not wired up yet" — SahajCloud #635 wired it up.canonical.embed, never a script parameter, because it is the same value SahajCloud composes canonical URLs from and two copies could disagree.The design decision
The prefix arrives over the network, after the router must exist. That is the sequencing problem #155 deferred on, and the answer is to wait:
AtlasBootreads the client record before constructing the router, and only in path mode. Query mode — every embed today — never reaches that code.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.
Five defects found and fixed during review
Two review passes plus a browser found more than the feature itself:
WIDGET_PARAMSomitted every filter name — filters silently dropped on each navigationfiltersparam that has never existedmountPrefixroot-mounted on any slashless value — which disables the only guard confining path mode, so the widget would adopt the host's whole URL space''andundefinedwere conflated; a''reached by accident makes the #92 basename-miss guard unable to firewebPathof/../../wp-adminescaped the mount subtreesafePathinspects the first two characters; the URL parser resolves dot segments afterwardswindow.location, and in path mode the route is the pathname?locale=was claimed but never written back — deleting a visitor's language on their first clickThe prefix read also no longer wraps the application: it used to put the router and all of
Appinside itsErrorBoundary, so an unrelated crash was reported as'path prefix'— and a failed background refetch would tear the widget down and rebuild it in query mode over a path-shaped URL.The shared canonical-URL contract is now asserted on this side
atlas-url-contract.jsonwas live in SahajCloud only — the fixture whose own$commenttells all three repos to assert against it byte-identically. It is copied here now, with a spec driving both directions over all 13 emitted cases: every canonical URL parses back to thewebPathit names, and path mode's composer reproduces the URL SahajCloud would have written. All 13 pass, which is the first evidence the two halves agree rather than an assumption.This is the gate for a failure that has already happened once: SahajCloud's first builder emitted
?atlas=events%2F12345, which oursafeLoaderPathrefuses outright — the widget would have discarded the route and opened its default view. It was caught by hand in the other repo's review.The 8 refusal cases are deliberately not exercised (they constrain SahajCloud's builder; there is no URL for a parser to be handed), but their count is pinned. Drift is
pnpm sync:atlas-contract, kept out of the unit lane because that lane must never touch the network.Verification
pnpm size✓ (299.9 / 302.2 against 310)canonical.embed: the readiness marker — which attests the shape the router actually used — reads"routing":"path", and the embed report files"pathname":"/pathmode"rather than/pathmode/gb/london.initialPathequal to the value it asserted, soread() ?? initialPathkept them green with the path shape returning nothing. Confirmed they now fail against a broken read.⚠ One fix broke another case, and only the browser showed it. Loosening the scheme strip to refuse
javascript:made//optional — which parseslocalhost:5173/pathmodeas schemelocalhost:, host5173. A mount key keeps its port (splitMountKeyrecordsurl.host). The//is required again, and the slashless rule refusesjavascript:anyway.Notes for reviewer
canonicalViable's path exemption stays off, permanently —detect.tscarried a note telling this commit to restore it. From the loader,routing=pathis a request rather than a finding, which is precisely what let a query-routed mount claim to be canonical.routeFromPageonly sees?atlas=and cannot know the prefix. Half-fixing it would reintroduce the mid-scroll modal that the&&exists to prevent.main.atlas-url-contract.jsonis no longer absent — see above. That closes the first of the four gaps recorded in the programme plan.🤖 Generated with Claude Code