Repository navigation
fix(map): atlas breadcrumb and event links keep the visitor's locale - #125
Conversation
A consumer holding a URL it did not build — an upstream canonical, most of all — has no way to locale-prefix it. `isSitePath` rejects an absolute URL outright, so such a link leaves the site's own link graph spelled in one fixed locale. `sitePathFromUrl` gives that consumer a path back, or nothing. How a URL is spelled lives here, so the origin comparison does too: a call site that compared origins itself would be a second place this rule lives. The scheme gate is deliberate rather than incidental. An opaque origin already compares unequal, but `isSafeHttpUrl` is this module's named gate on a URL the site did not author, and naming it is what keeps it true. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01DJm2UBFeN1JnKemdHbb2SE
`AtlasContent` rendered its breadcrumb rungs and event-card titles as raw anchors, so neither carried the locale. On `/fr/map/gb/london` the chrome was French while every link inside the page pointed at the English URL. One page shipped two spellings, because `LayoutMap`'s shared `Header` goes through `Link` and does carry `/fr`. Routing the two call sites through `Link` is not enough on its own. A rung's `url` is its canonical and is normally absolute, which `Link` leaves alone — that is the common case, not the edge one. So `atlasHref` now relativizes a canonical this origin serves, and `Link` prefixes the path that comes back. A canonical on another origin stays exactly as it is. Ownership is per-subtree, and that URL is another site's to spell. Off a request there is no origin to compare against, so the canonical stands as upstream wrote it. The committed suite renders without a `pageContext` and still asserts the absolute form for that reason; the two new suites supply an origin and cover the served behaviour, one locale each, because the `pageContext` mock is module-wide. Closes #122 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01DJm2UBFeN1JnKemdHbb2SE
`https://wemeditate.com//evil.com` is on this origin, so the origin check passes, and its path is `//evil.com` — a host again. `Link` routes a path it does not recognise as ours straight to `href`, so relativizing that URL would turn an upstream value into a protocol-relative link off-site. `isSitePath` already draws this exact line. The caller falls back to the absolute URL, which is same-origin and goes nowhere new. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01DJm2UBFeN1JnKemdHbb2SE
The review pass found the English case did not need a third copy of the region fixture: `vi.mock` is module-wide, but the value it returns need not be, and `layouts/LayoutChrome.test.tsx` already moves one through a mutable holder. One suite now covers both locales. `useOrigin` moves to `hooks/useT.ts` beside `useLocale`, where the next consumer will look for it. `lib/head.tsx` keeps its inline read: it holds `pageContext` already for `livePreview`, so the hook would only buy it a second context read. `atlasHref`'s `origin` is required now. Omitting it silently produced the English-only href this branch exists to fix, and no type error said so. `sitePathFromUrl` tests the scheme on the URL it already parsed rather than parsing a second time through `isSafeHttpUrl`. A breadcrumb rung's canonical is no longer parsed at all for the current page, which is always a span. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01DJm2UBFeN1JnKemdHbb2SE
The rule enumerates what `lib/urls.ts` owns, so a new member that is not named there reads as one a call site may re-derive instead. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01DJm2UBFeN1JnKemdHbb2SE
|
🤖 no session running recent dispatchesWritten by the sydevs dispatcher. Sessions never edit this comment. |
sydevs-bot
left a comment
There was a problem hiding this comment.
🧐 Adversarial review
The diff matches #122's size and takes the side its criteria asked for. The shape is right: the origin test lives in lib/urls.ts, both call sites go through Link, //evil.com is caught, off-origin is untouched. No scope creep.
The gap is evidence, not code. The canonical branch, which #122 called the normal case, cannot fire on any origin this app serves today — #124 says so in its own body. Only the url: null branch is demonstrable. The PR reads as if both were.
Findings
- should-fix — dormant in every deployed environment, so two verification steps cannot pass (
lib/urls.ts:161) - consider — an un-normalized path reaches
localePath, which does not re-normalize (lib/urls.ts:165) - consider —
useOrigin: one line, one consumer, in the translations file (hooks/useT.ts:54)
What was checked
Read whole: lib/urls.ts, Link.tsx, useT.ts, AtlasContent.tsx, both suites. Producer side in SahajCloud: canonicalUrl.ts (both URL shapes), atlas/seo/index.ts, regionOwners.ts:329. Read #122, #124.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
`sitePathFromUrl` returned `pathname` exactly as the URL spelled it, and every caller hands that straight to `localePath`, whose contract says it re-normalizes nothing. A canonical spelled `/map/gb/` therefore became `/fr/map/gb/` — the second URL for one page that `normalizeContentPath` exists to prevent, and the repo rule that a canonical goes through it. SahajCloud's `EMITTABLE_PATH` cannot emit a trailing slash today, so this is latent rather than live. It stops being latent the moment #124 wires this helper into `Link` for editor-pasted hrefs, which carry any shape a person typed. Only the pathname is normalized. The query and fragment name a different document, not a respelling, so they survive untouched. `//evil.com` still returns `null`: normalization does not touch a leading slash, so the host check behind it is unaffected. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MYUXRqT8ngfDScsftD8ihK
The file led with "`useT()` — the component-side translation accessor", which stopped being the whole truth when `useLocale` landed and is now plainly wrong with `useOrigin` beside it. An origin is not a translation. The reader that arrives next needs the shared fact — these are the `pageContext` readers, and each one falls back where there is no request — not a description of whichever function was written first. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MYUXRqT8ngfDScsftD8ihK
The URL-spelling rule said only "the path under such a URL", which left a reader to guess whether `localePath`'s "pass a path from `normalizeContentPath`" precondition was already met. It is, and the `/index` rule directly below names the same normalizer. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MYUXRqT8ngfDScsftD8ihK
Deploying wemeditate-design with
|
| Latest commit: |
fe4194c
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://fe01db7b.wm-design.pages.dev |
| Branch Preview URL: | https://claude-fix-122-atlas-link-lo.wm-design.pages.dev |
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
wemeditate-web | fe4194c | Commit Preview URL Branch Preview URL |
Sep 21 2026, 10:04 PM |
|
Addressed the adversarial review. Three threads, all resolved. Pushed Adopted
Adopted in part
Gate: lint 0 errors, 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
#121 landed `localeHref` on the same three files this branch extends with `sitePathFromUrl`. Both sides are kept: `sitePathFromUrl` relativizes a same-origin canonical, `Link` then spells it through `localeHref`, which re-normalizes an already-normalized path to no effect. - `lib/urls.test.ts` — both suites, both imports. - `AGENTS.md` — main's rewritten `localePath` paragraph, with this branch's `sitePathFromUrl` paragraph after it. - `lib/urls.ts` — auto-merged. `sitePathFromUrl`'s JSDoc named `localePath` as its only caller, which is no longer the path `Link` takes. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Bsg6d9XWRSKXFF2zAsnoWp
|
Merged #121 added
Gate after the merge: lint 0 errors, 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
`hooks/useT.ts` is the translation accessor. `useOptionalPageContext`, `useLocale` and `useOrigin` read `pageContext` and have nothing to do with translations, so eight modules imported a translations file for them. They move to `hooks/usePageContext.ts` unchanged. `useT` stays and imports the accessor from there. The two suites that stub the accessor stub the new path. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01UDfCzcBfYais3p597UA6tL
…t throw Four comments in this repo said `usePageContext()` throws with no Vike provider, and the accessor's `catch` was written for that. vike-react 0.6.26 returns `undefined` instead, while declaring the return type `PageContext` — verified by rendering a probe component bare. So `useOptionalPageContext` was returning `undefined` under a `PageContext | null` signature. It now coerces, and the comments say what the runtime does. The `catch` stays as cover if a future version throws. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01UDfCzcBfYais3p597UA6tL
|
Addressed the review. Pushed Adopted
Answered
Whether the two one-line readers earn their keep is still open. The guarded accessor does. Gate: lint 0 errors, 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
Summary
/fr/map/gb/londonthe chrome was French while every breadcrumb rung and event-card titlelinked to the English URL. Both now carry
/fr.urlis its canonical, whichLinkleavesalone. So
atlasHrefrelativizes a canonical this origin serves, andLinkprefixes it.Changes
lib/urls.ts— newsitePathFromUrl: the path under a same-origin absolute URL,nullotherwise. How a URL is spelled stays in one module. The path comes back in
normalizeContentPath's spelling, so it meetslocalePath's stated precondition and one pagecannot yield both
/fr/map/gband/fr/map/gb/.pages/map/_components/AtlasContent.tsx— the two raw anchors becomeLink;atlasHreftakesthe origin.
hooks/usePageContext.ts— new home for thepageContextreaders,useOptionalPageContextand
useLocale, joined by the newuseOrigin. They were inhooks/useT.ts, which is thetranslation accessor and keeps only
useT.useOptionalPageContextnow coerces tonull. vike-react 0.6.26 declaresusePageContext(): PageContextand returnsundefinedwith no provider, so the wrapper waspassing
undefinedthrough aPageContext | nullsignature. Four comments saying the built-inthrows are corrected.
Preview
wrangler.tomlbinds noroutesand no custom domain, and SahajCloud builds every rung's canonical from
WEMEDITATE_WEB_URL(
https://wemeditate.com,src/lib/atlas/regionOwners.ts:329). No origin this app servestoday is same-origin with that, so
sitePathFromUrlreturnsnullfor every rung and theabsolute canonical stands.
Test results
.claude/skills/pr-prep/check.sh— lint 0 errors,tsc --noEmitclean,736 tests passed
pnpm build(run because the diff adds a file underpages/, which is where the+-prefix routing trap is build-only)Manual verification
What the preview can show — the
routebranch, which is the one that fires there:/fr/map/<region>and confirm an event card whoseurlis empty links to/fr/map/…./map/<region>links bare —/map/…, never/en/map/….What it cannot show — the canonical branch. It needs the serving origin to equal
WEMEDITATE_WEB_URL, which happens once a custom domain is bound, or locally against aSahajCloud whose
WEMEDITATE_WEB_URLpoints at the dev origin.lib/urls.test.tsandAtlasContent.test.tsxare what covers it until then.Notes for reviewer
The ticket's leading open question is still open, and this PR takes one side of it. #122 asks
whether a locale-prefixed atlas URL belongs in this site's link graph at all: the atlas canonical
is locale-free by design and its hreflang cluster spells a locale as
?locale=, so/fr/map/gbis served but never advertised. The acceptance criteria answer "keep the visitor's locale", and
this implements exactly that. If the contract owner disagrees, this PR is the thing to revert.
The altitude call is worth checking. This fix sits in
atlasHref, one level below where itarguably belongs —
Linkasks the same question one line from the answer. I kept it at/mapscope deliberately and filed #124 for the wider decision, because moving it into
Linkwouldrewrite every editor-pasted href in
RichText(every content page) and would makeexternalmeantwo things —
MeditationPlayer.tsx:823is<Link external href="https://wemeditate.com/…">, whichwould become
/fr/meditationsin a new tab. That is a content-policy decision, not a code one.atlasHrefcarries aTODOpointing at #124 so the shape is not copied.Whether these hooks should exist at all is still yours to settle. The placement half of that
review is done — they are out of the translations file. The built-in cannot replace them, because
it lies about its own return type off-provider.
Dismissed findings, with reasons:
EventCardas a prop instead of re-reading context per card — measured atsingle-digit µs; prop-drilling costs more clarity than it buys.
Link's per-render style tables to module scope — real, but pre-existing and outsidethis diff.
lib/head.tsxshould call the newuseOrigin— it already holdspageContextforlivePreview, so the hook would only add a second context read.Breadcrumbsnow duplicates thecomponents/atoms/Breadcrumbsatom — true, andpre-existing; the atom does not emit
aria-current. Left alone, not filed.Detail
Why
Linkalone was not enough.isSitePathrejects an absolute URL, so routing the two callsites through
Linkwould have fixed only theurl: nullbranch — and that is the rare one. Thecommitted suite asserts the absolute canonical (
AtlasContent.test.tsx:127), which is the normalshape upstream returns.
Fixture pre-mortem. The suites assume
urlParsed.originis an origin with no trailing slash.Verified against
lib/head.tsx:161-166, which concatenates it with a path to build the canonicaland would emit
//mapotherwise.Hydration. The server now emits a relativized href, so the client must agree.
urlParsedis aclient-router built-in (
vike/dist/client/runtime-client-routing/getPageContext/removeBuiltInOverrides.js:4)and vike-react sets
clientRouting: true(vike-react/dist/config.js:22), so the origin ispresent on both sides and resolves to the same value. It is not in this repo's
passToClient, anddoes not need to be.
One defect found and fixed inside this branch.
https://wemeditate.com//evil.comissame-origin, so it passed the origin check, and its path is
//evil.com— a host again, whichLinkwould have emitted untouched as a protocol-relative link off-site.sitePathFromUrlnowreturns
nullthere and the caller falls back to the absolute URL. Commite21066d, covered bylib/urls.test.ts. Normalization does not touch a leading slash, so8807e3aleaves that guardintact.
The existing English assertion still asserts the absolute canonical, as #122's checklist asked.
It renders with no
pageContext, so there is no origin to recognise the canonical as ours, andthe fallback is to leave it alone. The new suite supplies an origin and covers the served
behaviour in both locales.
Test-file shape. #122 asked for a second file because the
pageContextmock is module-wide.That is half true — the mock registration is, but the value it returns need not be, and
layouts/LayoutChrome.test.tsx:14already moves one through a mutable holder. One suite coversFrench and English.
grep -nE "<a($|[ >/])" pages/map/_components/AtlasContent.tsxreturns one line: the event'sexternal "join online / visit website" link, which #122 excludes.
Closes #122
🤖 Written by the sydevs autonomous loop — see what this is
🤖 Generated with Claude Code
https://claude.ai/code/session_01UDfCzcBfYais3p597UA6tL