Repository navigation
fix(urls): Link does not normalize its href, so a trailing slash spells a page twice - #121
Conversation
`localePath` documents a precondition — pass it a path from
`normalizeContentPath` — that its two component callers could not meet.
`Link` takes any href a component writes, and `RichText` hands it the URL
an editor types into the rich-text link dialog. `buildEmbedSnippet` takes
whatever `embedPath` it is given. Neither normalized first, so
`<Link href="/about/">` rendered `/fr/about/` while `ContentHead` emitted
`/fr/about` as that same page's canonical: one document spelling one URL
two ways.
English is affected too. `localePath` returns the path untouched for the
default locale, so `/about/` contradicted a canonical of `/about` with no
locale prefix involved at all.
`sitePath` composes the guard, the normalization and the prefix, so the
rule stays in `lib/urls.ts` rather than being restated at each call site.
It normalizes inside the `isSitePath` branch, never before it:
`normalizeContentPath('')` returns `/`, which would turn an empty href
into a link to the home page.
A trailing slash before a `?` or a `#` survives, because
`normalizeContentPath` strips only a final slash. That limit is recorded
in the JSDoc and in a spec rather than fixed with a URL parser.
`lib/urls.test.ts` carried two overlapping `localePath` describe blocks,
one from #118 and one from #120. They are folded into one.
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01S2Dv9N87tE1CJaufz5U41v
The `lib/urls.ts` convention told a caller holding arbitrary hrefs to filter them through `isSitePath` itself. That is now `sitePath`'s job, and filtering alone was never enough: it let a trailing slash through. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01S2Dv9N87tE1CJaufz5U41v
Four review lenses over the branch diff. Production code came back clean
on reuse, efficiency and altitude; these are the test and comment fixes.
- `sitePath`'s JSDoc stated the `''` case as the reason for the guard
order. The invariant is more general — the predicate classifies the
href as written — so it now says that, in a third of the lines.
- One non-site-path fixture list, not two spellings of it.
- Drop assertions that only re-prove `localePath`: `localePath('en', '/')`
was already asserted a test above, and `sitePath`'s locale rows are
`localePath`'s rows.
- Move the no-locale trailing-slash assertion into the trailing-slash
test, out of the one about the `pageContext` fallback.
- `LayoutChrome`'s comment said adding the prefix back is `Link`'s job.
`Link` now normalizes as well, and the call here survives because
`urlPathname` may be nullish, which `sitePath` does not accept.
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01S2Dv9N87tE1CJaufz5U41v
`normalizeContentPath` strips a final slash off the whole string, and it was being handed a whole href. An editor-typed rich-text link then lost a slash that belonged to a value rather than to a path: `/share?url=https://example.com/` rendered `/fr/share?url=https://example.com`, and `/about#heading/` lost its anchor's trailing slash. `sitePath` now normalizes only an href with no `?` and no `#`. The trailing-slash fix is unchanged for every path that carries neither, and the limit the JSDoc already recorded — `/about/#section` keeps its slash — is now the mechanism rather than a side effect. Found by the review pass over this branch, not in the ticket. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01S2Dv9N87tE1CJaufz5U41v
Skipping an href that carried a `?` or a `#` kept the query's value safe but left three wrong spellings: `/about/#section` rendered `/fr/about/#section` against a canonical of `/fr/about`, `/?utm=1` rendered a 200 duplicate of `/fr`, and `/index?x=1` leaked the routing-internal `/index` into an href, against this repo's own rule that `/index` is never a URL. Splitting at the first `?` or `#` normalizes the path and puts the rest back exactly as written, which is correct in all three cases and still never edits a slash that belongs to a value. This answers the ticket's open question — it recommended accepting the limit, on the grounds that fixing it meant a parser. It costs three lines, and leaving it violated a stated invariant. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01S2Dv9N87tE1CJaufz5U41v
Both templates build `embedPath` without a trailing slash, so the comment claiming a caller produces one was wrong about its own fixture. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01S2Dv9N87tE1CJaufz5U41v
Deploying wemeditate-design with
|
| Latest commit: |
40decff
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://86e5434b.wm-design.pages.dev |
| Branch Preview URL: | https://claude-fix-119-sitepath.wm-design.pages.dev |
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
wemeditate-web | 40decff | Commit Preview URL Branch Preview URL |
Sep 21 2026, 07:18 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: one composed function, two one-line call sites, no refactor smuggled in beside them. The query/fragment split overrides the ticket's open question and is right — normalizeContentPath strips the last slash of whatever it is handed, so the un-split version corrupts ?url=…/. On note 1: leave localePath alone. Folding normalization into it would not shrink sitePath, which still needs its own guard and split.
Three findings, all consider, none blocking:
lib/urls.ts:177— the namesitePathoverclaims.layouts/LayoutChrome.tsx:115— thatnormalizeContentPathis now dead.AGENTS.md:194— the rule doubled to restate the JSDoc.
What was checked. #119 against the diff. lib/urls.ts, Link.tsx, EmbedButton.tsx, LayoutChrome.tsx read whole. Traced languages[].href → LanguageDropdown.tsx:75 → Link to prove the dead call. git grep on the head leaves localePath( in lib/urls.ts and two '/' literals under pages/. No contract file is in the diff.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
`sitePath` overclaimed. The function returns `mailto:`, `//cdn…` and an empty href untouched, and since the query/fragment split it returns a whole href rather than a path. It also read as the constructor half of `isSitePath` two functions above it. `localeHref` is the third member of the module's existing vocabulary: `localePath` returns a path, `localeUrl` an absolute URL, `localeHref` the href to render for any href. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01UmTczzh2NV5SddDiDCkeMM
`pathWithoutLocale` fed only `language.href`, which `LanguageDropdown` hands to `Link`, which calls `localeHref` — `normalizeContentPath` on the same string, `/index` branch included. The layout now passes `urlPathname` on as written, and a new spec pins that wiring. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01UmTczzh2NV5SddDiDCkeMM
The paragraph had doubled to restate `localeHref`'s JSDoc. AGENTS.md is read every session; the JSDoc is read when someone opens the function. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01UmTczzh2NV5SddDiDCkeMM
|
All three findings adopted, nothing rebutted, nothing asked. Pushed as
Lean gate green: lint, 🤖 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
Summary
<Link href="/about/">rendered/fr/about/whileContentHeademitted/fr/aboutas that page's canonical. English was affected too, with no prefix involved.localeHref(locale, href)inlib/urls.tscomposes theisSitePathguard,normalizeContentPathandlocalePath, so the rule stays in one place.LinkandbuildEmbedSnippetboth call it.?url=https://example.com/keeps the slash that belongs to its value.Changes
lib/urls.ts— addslocaleHref;localePath's JSDoc now points arbitrary-href callers at it instead of atisSitePath.components/atoms/Link/Link.tsx,components/molecules/EmbedButton/EmbedButton.tsx— one call each, replacing the duplicatedisSitePath(…) ? localePath(…) : hrefternary.layouts/LayoutChrome.tsx— the language dropdown handsurlPathnameon as written. Its ownnormalizeContentPathcall did whatLinknow does to the same string.AGENTS.md— the URL-spelling rule points atlocaleHref, and stays a pointer rather than a second copy of the JSDoc.Preview
Test results
.claude/skills/pr-prep/check.sh— lint (0 errors),tsc --noEmit,vitest run721/721lib/urls.test.ts,Link.test.tsx,EmbedButton.test.tsx,LayoutChrome.test.tsxBefore implementing, every row of the ticket's evidence table was re-measured against current
main(cf7e088, past both #118 and #120) by running the reallib/urls.ts. All reproduced. The new specs were then confirmed to fail against the unfixed function: 6 failures across all three files.Manual verification
/frpage and click a rich-text link whose URL an editor typed with a trailing slash — the href should be/fr/<slug>, matching the canonical in<head>./fron the home page.Notes for reviewer
Three judgement calls worth your eye:
The function is named
localeHref, not the ticket'ssitePath. The critic arguedsitePathoverclaims — it returnsmailto:,//cdn…and''untouched, and since the query/fragment split it returns a whole href, not a path.localeHrefis the third member of the module's existing vocabulary besidelocalePathandlocaleUrl. Adopted in59bbe0c. Revert that commit if you want the ticket's name back.I answered the ticket's open question the other way. It recommended accepting that a trailing slash before
?or#survives. Skipping those hrefs turned out to leave three wrong spellings, including/index?x=1leaking the routing-internal/indexinto an href against this repo's own stated invariant. Splitting at the first?or#costs three lines, so I fixed it. Revert82ab0edif you disagree.localePathstays the raw primitive, per the ticket's Approach step 4. The altitude review wanted normalization folded into it; the critic came down the other way, and I left it. Reasoning in Detail below — it is a one-line follow-up either way.Filed separately, found on the way: #122 — the atlas breadcrumb and event links drop the visitor's locale.
Detail
Adversarial review, three findings, all adopted.
lib/urls.ts— the name overclaims. Renamed tolocaleHrefin59bbe0c, across both call sites, the specs andAGENTS.md.layouts/LayoutChrome.tsx— thenormalizeContentPathcall is dead. Confirmed by reading the chain:pathWithoutLocalefed onlylanguage.href→LanguageDropdown.tsx:75→Link→localeHref, which normalizes the same string,/indexbranch included. Dropped in48c3833, with a newLayoutChromespec pinning the wiring, so the equivalence that justifies the deletion is now enforced rather than argued.AGENTS.md— the rule doubled to restate the JSDoc. Cut in40decff, one line shorter than before this PR. One deviation from the suggested wording://another-originstays in the not-ours-to-spell list, because a protocol-relative URL is the member of that list that looks like a path.On
localePath(note 3). All four existing callers (lib/head.tsx:190,lib/hreflang.ts:96,100,pages/+onBeforeRoute.ts:19,pages/[slug]/+data.ts:86) pass an already-normalized path or the literal'/', andnormalizeContentPathis idempotent, so folding it in would alter no existing output. The critic's argument against:localeHrefstill needs its own guard and its own query/fragment split, so the fold shrinks nothing and costs a primitive's documented contract that #118 and #120 just set.Earlier findings, both mine, both caught after the first green gate:
normalizeContentPathstrips a final slash off whatever string it gets, and it was being handed a whole href./share?url=https://example.com/rendered/fr/share?url=https://example.com— a corrupted query value on an editor-typed rich-text link. Fixed in686b688, then properly in82ab0ed.LayoutChromecomment claimedurlPathnamemay be nullish. It is typedstring; a throwaway assignment compiled clean. That comment is gone with the call it explained.Dismissed, with reasons:
isSitePath, now that onlylocaleHrefcalls it. Kept.AGENTS.mdnames it as the site-path predicate and it has its own specs; removing a documented export is a separate decision, not this ticket's.describe('isSitePath')block into the new one. Kept. It predates this PR and tests the predicate rather than the branch.normalizeContentPath's/\/+$/to module scope. Skipped. Pre-existing, and measured as immaterial — one small short-lived allocation next to three object literalsLinkalready builds per render.siteUrl(origin, locale, href)to absorbEmbedButton's${origin}${src}. Skipped as over-engineering for one caller.Not a regression, deliberate behaviour change:
href="/index"now renders/frrather than/fr/index./indexwas already a link to a 301, and the language dropdown — the one place that now passes it — gets the same/frit got before.Efficiency: no Worker bundle delta — both call sites swapped named imports within
lib/urls, andnormalizeContentPathwas already reachable from both bundles.LayoutChromedrops one import.Test hygiene:
lib/urls.test.tscarried two overlappingdescribe('localePath')blocks, one left by #118 and one by #120. Folded into one; both of the deleted block's assertions survive.Closes #119
🤖 Written by the sydevs autonomous loop — see what this is
🤖 Generated with Claude Code
https://claude.ai/code/session_01UmTczzh2NV5SddDiDCkeMM