Skip to content

fix(urls): spell every locale-prefixed URL through one function - #118

Merged
sydevs-bot merged 8 commits into
mainfrom
claude/fix-115-locale-path
Sep 18, 2026
Merged

sydevs-bot merged 8 commits into
mainfrom
claude/fix-115-locale-path

Conversation

@sydevs-bot

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

Copy link
Copy Markdown
Contributor

Summary

  • One function prefixes a path with a locale now. <Link href="/" locale="fr"> renders /fr, matching the canonical, where it used to render /fr/.
  • Link and EmbedButton call lib/urls.ts instead of each restating the rule with their own drifted copy.
  • Fixes a latent bug on the way: mailto:, tel:, a bare relative about and //another-origin used to come back locale-prefixed (/frmailto:[email protected]). Nothing links that way today.

Changes

  • lib/urls.ts — new localePath(locale, path) holds the rule; localeUrl is now just its absolute form. New isSitePath(href) says which hrefs are ours to prefix.
  • components/atoms/Link/Link.tsx — calls both, and calls useLocale() 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_LOCALE in place of the 'en' literals.
  • 9 locale?: string props tightened to Locale, plus LectureData, PageData and MeditationData.
  • lib/cms-blocks.ts — isExternalUrl deleted with its spec. It was a second, zero-caller predicate for the question isSitePath now 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

  • Lean gate: ✓ lint (0 errors), tsc --noEmit, test:run
  • Targeted specs: 668 passed (71 files), from 665 on main. It was 669 before this round — the isExternalUrl spec went with the function it covered.
  • Build: N/A — no build/server/Wrangler paths changed

Manual verification

  1. pnpm ladle — open the Link and EmbedButton stories. Neither should throw, and no href should contain undefined. Ladle has no pageContext, which is the path the || DEFAULT_LOCALE fallback exists for.
  2. pnpm dev, open a /fr page, and check the language dropdown's home entry points at /fr and 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 +onBeforeRoute over 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 makes Task the honest issue type rather than Bug. I have not changed the type; that is yours.

I took the recommended type option (tighten all the props to Locale, no isLocale() narrowing). tsc found sites the ticket did not list — LectureData, then PageData and MeditationData — each taking pageContext.locale and widening it back to string. Narrowing them needed no cast anywhere.

One thing in the ticket is now stale: it says localeFromPath does not exist. It does, at lib/urls.ts:36 — #113 added it after the ticket was revised. Nothing here depended on the claim.

isSitePath is 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 — Link denylisting http/#, EmbedButton allowlisting /. 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 isSitePath branch in buildEmbedSnippet. #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): Link hands localePath an un-normalized href, but localePath documents a normalized precondition. So href="/about/" renders /fr/about/ while lib/head.tsx emits /fr/about as that page's canonical — the same two-spellings defect as #115, in a second form. Every lib/urls.ts caller except Link normalizes first. Reachable only if an href carries a trailing slash; today's hrefs are '/' + page.slug from the CMS, so it depends on slug hygiene this repo does not control. Fixing it means Link normalizing, which is a behaviour change beyond these acceptance criteria.

Dismissed — the three "duplicate" Link tests. Two review lenses flagged that "spells the home page /fr", "prefixes a content path" and "region-cased locale" in Link.test.tsx re-assert what lib/urls.test.ts already covers directly. Kept: the ticket's verification checklist explicitly requires Link.test.tsx to assert all five acceptance rows, and they pin Link's own rendered contract rather than localePath's return value.

Adopted after review — isExternalUrl is 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 /fr vs /fr/ case by running normalizeContentPath over the prefixed path. It would work, but it couples localePath to normalizeContentPath's /index special case and adds a regex per Link render to replace an explicit ternary that reads fine.

Checked and cleared — bundle weight. Link now imports hooks/useT, which reaches lib/translations.en.json (7 KB). Not a regression: pages/+config.ts makes LayoutRoot global, LayoutRoot imports ErrorFallback, and that already imports useT, so the JSON is in every route's graph on main. pages/+onBeforeRender.ts imports EN_TRANSLATIONS directly for the Worker bundle regardless.

Verified rather than assumed: the new Link tests render with no Vike app, so usePageContext() throws and useOptionalPageContext() returns null. That is the real Ladle/unit shape, not a supposition — EmbedButton.test.tsx already renders a useT consumer bare on main and passes.

Closes #115

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


Generated by Claude Code

`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
@cloudflare-workers-and-pages

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

Copy link
Copy Markdown

Deploying wemeditate-design with  Cloudflare Pages  Cloudflare Pages

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

View logs

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Sep 18, 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 495371b Commit Preview URL

Branch Preview URL
Sep 18 2026, 07:24 PM

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

sydevs-bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 no session running

recent dispatches
  • 19:19Z resolve-conflicts · attempt 1 · session · done
  • 19:19Z resolve-conflicts · attempt 1 · session
  • 19:04Z address-review · attempt 1 · session · done
  • 19:04Z address-review · attempt 1 · session
  • 18:56Z adversarial-review · attempt 1 · session · done

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

@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 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 widen pageContext.locale to string. → pages/lectures/[id]/_lecture.ts:10
  • consider — isExternalUrl is a second, zero-caller predicate for the same question. → lib/urls.ts:82
  • consider — buildEmbedSnippet's isSitePath branch 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

Comment thread pages/lectures/[id]/_lecture.ts Resolved
Comment thread lib/urls.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 18, 2026
`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
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Review addressed — 2 adopted, 1 pushed back. Pushed eea5f09.

Lean gate green: lint, tsc --noEmit, 668 tests across 71 files. PR body refreshed.

🤖 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 18, 2026
@sydevs-bot
sydevs-bot marked this pull request as ready for review September 18, 2026 19:12
@sydevs-bot
sydevs-bot requested a review from Ardnived September 18, 2026 19:12
@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 18, 2026
`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
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Merged main. Two conflicts, both an append to the same place, both sides kept whole.

lib/urls.ts auto-merged with all four functions. AGENTS.md and lib/urls.test.ts needed a hand only to hold both additions.

isSitePath and isSafeNavigationUrl disagree on //host by design. One asks whether a path is ours to locale-prefix, the other whether a scheme is safe to navigate to. An off-site URL is a yes to the second and a no to the first.

Lean gate green on the merge: 695 tests, 73 files.

🤖 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 18, 2026
@sydevs-bot sydevs-bot moved this from Revising to Approved in SYDevelopers Technical Roadmap Sep 18, 2026
@sydevs-bot
sydevs-bot added this pull request to the merge queue Sep 18, 2026
Merged via the queue into main with commit a07f902 Sep 18, 2026
17 checks passed
@sydevs-bot
sydevs-bot deleted the claude/fix-115-locale-path branch September 18, 2026 23:07
@sydevs-bot sydevs-bot moved this from Approved to Done in SYDevelopers Technical Roadmap Sep 18, 2026
sydevs-bot pushed a commit that referenced this pull request Sep 18, 2026
#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
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(links): Link and EmbedButton each restate the locale-prefix rule

3 participants