Repository navigation
fix(urls): spell every locale-prefixed URL through one function - #118
Conversation
`localeUrl` stated the prefix rule inline, and two components restated it with their own copies. A rule with three statements had already drifted: for `/`, `localeUrl` gave `/fr` while `Link` gave `/fr/`. `localePath` is that rule, origin-free. `localeUrl` is now its absolute form, so the two cannot disagree about a path again. The new test asserts the two agree across the locale and path matrix rather than restating each expectation twice. `localePath` deliberately does not judge whether its argument is a site path. An external URL and an `#anchor` are the caller's to filter, because only the caller knows it holds arbitrary input. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_016PqiuAUdrRWw1SVNucuhQp
The language dropdown hands `Link` the normalized `/` on the home page,
and `Link`'s own copy of the prefix rule concatenated it into `/fr/`. The
canonical for that same page renders `/fr`, so one document spelled one
URL two ways. Both 200 with no redirect, so this cost duplicate spellings
rather than a hop.
Both components now call `localePath` and keep only the guard that is
genuinely theirs: `http`/`#` in `Link`, `startsWith('/')` in
`EmbedButton`. Those guards are why a bare swap would have been wrong —
`localePath` would happily render `/frhttps://example.com`.
`Link` also inlined a fourth copy of the no-`pageContext` guard that
`useOptionalPageContext` already owns, and the `'en'` literals throughout
are now `DEFAULT_LOCALE`.
The `|| DEFAULT_LOCALE` fallback stays. Inside Vike it is dead, because
`pageContext.locale` is non-optional — but Ladle and a bare unit render
have no `pageContext` at all, and without it an href becomes
`/undefined/about`.
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016PqiuAUdrRWw1SVNucuhQp
`localePath` takes a `Locale`, but nine props that feed it were typed `string`, so the components widened a value that already arrived narrow. Every one of them is handed `pageContext.locale` or a `LanguageOption.code`, both of which are `Locale` at their source. `tsc` found the only two call sites that did not type-check, and both traced to `LectureData.locale`, which took `pageContext.locale` and forgot what it was. Narrowing the interface fixed both pages without a cast. `LectureSubtitleTrack.locale` stays `string`. It is a code from the Nirmala Vidya API, not a locale this site serves. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_016PqiuAUdrRWw1SVNucuhQp
…ePath
The review pass found the branch had reduced the prefix rule to one copy
but left its precondition written twice, in two non-equivalent spellings:
`Link` used a denylist (`http`, `#`) and `EmbedButton` an allowlist
(`startsWith('/')`). That is the same drift shape the ticket is about,
reduced from three copies to two rather than to one.
`isSitePath` is that predicate, next to the rule it guards. Unifying on it
also fixes what the denylist let through: `mailto:`, `tel:`, a bare
relative `about` and a protocol-relative `//cdn.example.com` each used to
come back with a locale glued on — `/frmailto:[email protected]`. Nothing
in the tree links that way today, so this was latent.
`Link` also still hand-rolled the locale fallback that `useLocale` owns,
which was the fourth copy of the no-`pageContext` guard the ticket counted.
It calls `useLocale` now, the same way `EmbedButton` already did.
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016PqiuAUdrRWw1SVNucuhQp
The repo-wide rule named `localeUrl` as the one that serves English bare. That rule now belongs to `localePath`, with `localeUrl` as its absolute form, and the "which hrefs are ours to prefix" half has a name too. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_016PqiuAUdrRWw1SVNucuhQp
Deploying wemeditate-design with
|
| Latest commit: |
495371b
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://4ade0f8d.wm-design.pages.dev |
| Branch Preview URL: | https://claude-fix-115-locale-path.wm-design.pages.dev |
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
wemeditate-web | 495371b | Commit Preview URL Branch Preview URL |
Sep 18 2026, 07:24 PM |
|
🤖 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 is the size of the ticket. Reducing localeUrl to origin + localePath is the right shape: the relative and absolute forms can no longer drift, and the dropdown's home entry now agrees with the canonical. isSitePath is unasked-for scope that earns it — the precondition was the second copied rule, written two non-equivalent ways. Nothing blocks.
Findings
consider— two sibling data shapes still widenpageContext.localetostring. →pages/lectures/[id]/_lecture.ts:10consider—isExternalUrlis a second, zero-caller predicate for the same question. →lib/urls.ts:82consider—buildEmbedSnippet'sisSitePathbranch is unreachable. →EmbedButton.tsx:21
What was checked
#115 against 5 commits, 15 files, read whole. grep -rn "'/' + locale|/${locale}" over components layouts lib hooks pages server now returns only lib/urls.ts:104 — one prefixer, as asked. Dropdown → Link traced: normalizeContentPath(urlPathname) plus each option's code, so /fr matches ContentHead.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
`PageData` and `MeditationData` each took `pageContext.locale`, already `Locale` through `types/vike.d.ts`, and widened it back to `string` — exactly what `LectureData` did before this branch narrowed it. `tsc` stayed quiet because no tightened prop consumes either one yet, so the widening would have surfaced only when some later prop did. `lib/lecture-shape.ts` and `VideoPlayer`'s `subtitleTracks` stay `string` on purpose: a subtitle track carries a BCP-47 tag, not a site locale. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01J69o6e4its6bqFCXPmmS3U
`isSitePath` gave the "which hrefs are ours to prefix" question one name. `lib/cms-blocks.ts` still exported `isExternalUrl` as a second answer to it, with a spec and no production caller since it was written. The two are not complements — `#section` is neither external nor ours — so keeping both leaves one question spelled two non-equivalent ways, which is the drift this branch exists to remove. Importing it into an atom was rejected on bundle weight, so deleting it is the other move. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01J69o6e4its6bqFCXPmmS3U
|
Review addressed — 2 adopted, 1 pushed back. Pushed
Lean gate green: lint, 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
`main` added `isSafeHttpUrl` and `isSafeNavigationUrl` to `lib/urls.ts` while this branch added `localePath` and `isSitePath`. Both sides took both, everywhere: the module auto-merged with all four, and the two conflicts were each an append to the same spot. `isSitePath` and `isSafeNavigationUrl` disagree on `//host` by design and not by accident. They answer different questions — "is this ours to locale-prefix" versus "is this scheme safe to navigate to" — and an off-site URL is a yes to the second and a no to the first. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VabF25b6EYxEQxER9osGPh
|
Merged
Lean gate green on the merge: 695 tests, 73 files. 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
#118 split `localeUrl` into `localePath` + `localeUrl` and added `isSitePath`. This branch had made the same split, for its own redirect targets. Three files conflicted; both behaviours are kept. - `lib/urls.ts` — the two splits are identical code, so main's version of that tail stands and `isSitePath` survives. This branch's `INDEX_PATH` and `requestedIndex` sit above it, untouched by either side. - `lib/urls.test.ts` — the import list only. - `AGENTS.md` — main's rewritten URL-spelling bullet, plus this branch's `requestedIndex` clause and its `/index is routing-internal` bullet. Lean gate green after the merge: lint 0 errors, tsc clean, 74 files / 710 tests. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01UEYDbxwjGimsypgzrvzJnQ
Summary
<Link href="/" locale="fr">renders/fr, matching the canonical, where it used to render/fr/.LinkandEmbedButtoncalllib/urls.tsinstead of each restating the rule with their own drifted copy.mailto:,tel:, a bare relativeaboutand//another-originused to come back locale-prefixed (/frmailto:[email protected]). Nothing links that way today.Changes
lib/urls.ts— newlocalePath(locale, path)holds the rule;localeUrlis now just its absolute form. NewisSitePath(href)says which hrefs are ours to prefix.components/atoms/Link/Link.tsx— calls both, and callsuseLocale()instead of hand-rolling the fallback it owns. Body went from 16 lines to 2.components/molecules/EmbedButton/EmbedButton.tsx— same two calls.hooks/useT.ts—DEFAULT_LOCALEin place of the'en'literals.locale?: stringprops tightened toLocale, plusLectureData,PageDataandMeditationData.lib/cms-blocks.ts—isExternalUrldeleted with its spec. It was a second, zero-caller predicate for the questionisSitePathnow answers.components/atoms/Link/Link.test.tsx— new; the directory had a story but no spec.Preview
Both last built
eb8c840. The two review commits are newer, so a rebuild is pending.Test results
tsc --noEmit,test:runmain. It was 669 before this round — theisExternalUrlspec went with the function it covered.Manual verification
pnpm ladle— open the Link and EmbedButton stories. Neither should throw, and nohrefshould containundefined. Ladle has nopageContext, which is the path the|| DEFAULT_LOCALEfallback exists for.pnpm dev, open a/frpage, and check the language dropdown's home entry points at/frand 200s.Notes for reviewer
The open question is settled:
/fr/costs no redirect.curl -sI https://wemeditate.com/fr/returns 200, not a 301, matching the revised ticket's reading of+onBeforeRouteover the smoke-test comment that claimed the hop. So this is a duplicate-URL-spelling defect, not a broken link — which by the ticket's own note makesTaskthe honest issue type rather thanBug. I have not changed the type; that is yours.I took the recommended type option (tighten all the props to
Locale, noisLocale()narrowing).tscfound sites the ticket did not list —LectureData, thenPageDataandMeditationData— each takingpageContext.localeand widening it back tostring. Narrowing them needed no cast anywhere.One thing in the ticket is now stale: it says
localeFromPathdoes not exist. It does, atlib/urls.ts:36— #113 added it after the ticket was revised. Nothing here depended on the claim.isSitePathis scope the ticket did not ask for. The review pass caught that the branch had reduced the prefix rule to one copy but left its precondition written twice in two non-equivalent spellings —Linkdenylistinghttp/#,EmbedButtonallowlisting/. That is the same drift shape the ticket is about, so I unified it rather than leave the job half done. It is its own commit.The one review finding I pushed back on is the unreachable
isSitePathbranch inbuildEmbedSnippet. #115 asks for that guard twice — Approach step 3, and an acceptance row. Its thread is left open for you.Detail — review findings I did not act on, and a follow-up
Follow-up worth its own ticket (not filed as part of this PR's scope):
LinkhandslocalePathan un-normalized href, butlocalePathdocuments a normalized precondition. Sohref="/about/"renders/fr/about/whilelib/head.tsxemits/fr/aboutas that page's canonical — the same two-spellings defect as #115, in a second form. Everylib/urls.tscaller exceptLinknormalizes first. Reachable only if an href carries a trailing slash; today's hrefs are'/' + page.slugfrom the CMS, so it depends on slug hygiene this repo does not control. Fixing it meansLinknormalizing, which is a behaviour change beyond these acceptance criteria.Dismissed — the three "duplicate"
Linktests. Two review lenses flagged that "spells the home page/fr", "prefixes a content path" and "region-cased locale" inLink.test.tsxre-assert whatlib/urls.test.tsalready covers directly. Kept: the ticket's verification checklist explicitly requiresLink.test.tsxto assert all five acceptance rows, and they pinLink's own rendered contract rather thanlocalePath's return value.Adopted after review —
isExternalUrlis gone. The earlier note here rejected importing it into an atom, on bundle weight. That left the repo with two non-equivalent spellings of one question, which is the drift this PR exists to remove, so the review round deleted it and its spec instead. It had no production caller.Dismissed — derive the
/frvs/fr/case by runningnormalizeContentPathover the prefixed path. It would work, but it coupleslocalePathtonormalizeContentPath's/indexspecial case and adds a regex perLinkrender to replace an explicit ternary that reads fine.Checked and cleared — bundle weight.
Linknow importshooks/useT, which reacheslib/translations.en.json(7 KB). Not a regression:pages/+config.tsmakesLayoutRootglobal,LayoutRootimportsErrorFallback, and that already importsuseT, so the JSON is in every route's graph onmain.pages/+onBeforeRender.tsimportsEN_TRANSLATIONSdirectly for the Worker bundle regardless.Verified rather than assumed: the new
Linktests render with no Vike app, sousePageContext()throws anduseOptionalPageContext()returns null. That is the real Ladle/unit shape, not a supposition —EmbedButton.test.tsxalready renders auseTconsumer bare onmainand passes.Closes #115
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code