Skip to content

fix(map): atlas breadcrumb and event links keep the visitor's locale - #125

Merged
sydevs-bot merged 11 commits into
mainfrom
claude/fix-122-atlas-link-locale
Sep 21, 2026
Merged

sydevs-bot merged 11 commits into
mainfrom
claude/fix-122-atlas-link-locale

Conversation

@sydevs-bot

@sydevs-bot sydevs-bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • On /fr/map/gb/london the chrome was French while every breadcrumb rung and event-card title
    linked to the English URL. Both now carry /fr.
  • The common case was the absolute one: a rung's url is its canonical, which Link leaves
    alone. So atlasHref relativizes a canonical this origin serves, and Link prefixes it.
  • A canonical owned by another domain is still untouched. Ownership is per-subtree.

Changes

  • lib/urls.ts — new sitePathFromUrl: the path under a same-origin absolute URL, null
    otherwise. How a URL is spelled stays in one module. The path comes back in
    normalizeContentPath's spelling, so it meets localePath's stated precondition and one page
    cannot yield both /fr/map/gb and /fr/map/gb/.
  • pages/map/_components/AtlasContent.tsx — the two raw anchors become Link; atlasHref takes
    the origin.
  • hooks/usePageContext.ts — new home for the pageContext readers, useOptionalPageContext
    and useLocale, joined by the new useOrigin. They were in hooks/useT.ts, which is the
    translation accessor and keeps only useT.
  • useOptionalPageContext now coerces to null. vike-react 0.6.26 declares
    usePageContext(): PageContext and returns undefined with no provider, so the wrapper was
    passing undefined through a PageContext | null signature. Four comments saying the built-in
    throws are corrected.

Preview

  • ⚠ The preview cannot demonstrate the canonical branch. wrangler.toml binds no routes
    and 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 serves
    today is same-origin with that, so sitePathFromUrl returns null for every rung and the
    absolute canonical stands.

Test results

  • Lean gate: ✓ .claude/skills/pr-prep/check.sh — lint 0 errors, tsc --noEmit clean,
    736 tests passed
  • Build: ✓ pnpm build (run because the diff adds a file under pages/, which is where the
    +-prefix routing trap is build-only)

Manual verification

What the preview can show — the route branch, which is the one that fires there:

  1. Open /fr/map/<region> and confirm an event card whose url is empty links to /fr/map/….
  2. Confirm /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 a
SahajCloud whose WEMEDITATE_WEB_URL points at the dev origin. lib/urls.test.ts and
AtlasContent.test.tsx are 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/gb
is 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 it
arguably belongs — Link asks the same question one line from the answer. I kept it at /map
scope deliberately and filed #124 for the wider decision, because moving it into Link would
rewrite every editor-pasted href in RichText (every content page) and would make external mean
two things — MeditationPlayer.tsx:823 is <Link external href="https://wemeditate.com/…">, which
would become /fr/meditations in a new tab. That is a content-policy decision, not a code one.
atlasHref carries a TODO pointing 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:

  • Pass the origin to EventCard as a prop instead of re-reading context per card — measured at
    single-digit µs; prop-drilling costs more clarity than it buys.
  • Hoist Link's per-render style tables to module scope — real, but pre-existing and outside
    this diff.
  • lib/head.tsx should call the new useOrigin — it already holds pageContext for
    livePreview, so the hook would only add a second context read.
  • The local Breadcrumbs now duplicates the components/atoms/Breadcrumbs atom — true, and
    pre-existing; the atom does not emit aria-current. Left alone, not filed.
Detail

Why Link alone was not enough. isSitePath rejects an absolute URL, so routing the two call
sites through Link would have fixed only the url: null branch — and that is the rare one. The
committed suite asserts the absolute canonical (AtlasContent.test.tsx:127), which is the normal
shape upstream returns.

Fixture pre-mortem. The suites assume urlParsed.origin is an origin with no trailing slash.
Verified against lib/head.tsx:161-166, which concatenates it with a path to build the canonical
and would emit //map otherwise.

Hydration. The server now emits a relativized href, so the client must agree. urlParsed is a
client-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 is
present on both sides and resolves to the same value. It is not in this repo's passToClient, and
does not need to be.

One defect found and fixed inside this branch. https://wemeditate.com//evil.com is
same-origin, so it passed the origin check, and its path is //evil.com — a host again, which
Link would have emitted untouched as a protocol-relative link off-site. sitePathFromUrl now
returns null there and the caller falls back to the absolute URL. Commit e21066d, covered by
lib/urls.test.ts. Normalization does not touch a leading slash, so 8807e3a leaves that guard
intact.

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, and
the 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 pageContext mock is module-wide.
That is half true — the mock registration is, but the value it returns need not be, and
layouts/LayoutChrome.test.tsx:14 already moves one through a mutable holder. One suite covers
French and English.

grep -nE "<a($|[ >/])" pages/map/_components/AtlasContent.tsx returns one line: the event's
external "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

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
@sydevs-bot

sydevs-bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 no session running

recent dispatches
  • 21:57Z address-review · attempt 1 · session · done
  • 21:57Z address-review · attempt 1 · session
  • 19:44Z resolve-conflicts · attempt 1 · session · done
  • 19:44Z resolve-conflicts · attempt 1 · session
  • 19:21Z address-review · attempt 1 · session · done

Written by the sydevs dispatcher. Sessions never edit this comment.

@sydevs-bot sydevs-bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Sep 21, 2026

@sydevs-bot sydevs-bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧐 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

Comment thread lib/urls.ts Resolved
Comment thread lib/urls.ts Resolved
Comment thread hooks/useT.ts Resolved
@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Sep 21, 2026
`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
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

Deploying wemeditate-design with  Cloudflare Pages  Cloudflare Pages

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

View logs

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

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

@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Addressed the adversarial review. Three threads, all resolved. Pushed 9299f04.

Adopted

  • Dormant canonical branch — confirmed. wrangler.toml binds no custom domain, and SahajCloud falls back to WEMEDITATE_WEB_URL, so no origin this app serves is same-origin with a rung's canonical. Verification steps 1 and 3 are gone.
  • Un-normalized path into localePath — 8807e3a. sitePathFromUrl normalizes the pathname, so /map/gb/ can no longer become a second /fr/map/gb/.

Adopted in part

  • useOrigin — 1a02814. The hook stays: two call sites, and inlining spreads pageContext shape into a component file. Its module header was stale, and now names all three readers.

Gate: lint 0 errors, tsc --noEmit clean, 725 passed.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

@sydevs-bot sydevs-bot removed the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Sep 21, 2026
@sydevs-bot
sydevs-bot marked this pull request as ready for review September 21, 2026 19:29
@sydevs-bot
sydevs-bot requested a review from Ardnived September 21, 2026 19:29
@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed awaiting labels Sep 21, 2026
#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
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Merged main in. Both sides kept.

#121 added localeHref, this branch added sitePathFromUrl, and they compose: atlasHref relativizes a same-origin canonical, Link spells it through localeHref, and re-normalizing an already-normalized path changes nothing.

AGENTS.md took main's rewritten localePath paragraph rather than this branch's, since main revised the same lines. This branch's sitePathFromUrl paragraph follows it.

sitePathFromUrl's JSDoc named localePath as its only caller. That is no longer the path Link takes, so it now names both.

Gate after the merge: lint 0 errors, tsc --noEmit clean, 736 tests passed.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

@sydevs-bot sydevs-bot added awaiting and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Sep 21, 2026
Comment thread hooks/useT.ts Resolved
@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed awaiting labels Sep 21, 2026
`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
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Addressed the review. Pushed fe4194c. One thread, left open for the half that is yours to settle.

Adopted

  • Where these readers live — 04de4c7. useOptionalPageContext, useLocale and useOrigin now live in hooks/usePageContext.ts. useT keeps the translations file to itself.

Answered

  • Could built-ins replace them? No. vike-react 0.6.26 declares usePageContext(): PageContext and returns undefined with no provider — verified with a bare probe. So the wrapper was passing undefined through a PageContext | null signature. fe4194c coerces it and corrects four comments that said the built-in throws.

Whether the two one-line readers earn their keep is still open. The guarded accessor does.

Gate: lint 0 errors, tsc --noEmit clean, 736 passed.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

@sydevs-bot sydevs-bot added awaiting and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Sep 21, 2026
@sydevs-bot
sydevs-bot added this pull request to the merge queue Sep 21, 2026
Merged via the queue into main with commit e4b89a5 Sep 21, 2026
23 checks passed
@sydevs-bot
sydevs-bot deleted the claude/fix-122-atlas-link-locale branch September 21, 2026 22:43
@sydevs-bot sydevs-bot moved this from Revising to Done in SYDevelopers Technical Roadmap Sep 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

fix(map): atlas breadcrumb and event links drop the visitor's locale

3 participants