fix(cms): normalize trailing slashes in page paths#92
Closed
JonasJesus42 wants to merge 1 commit intomainfrom
Closed
fix(cms): normalize trailing slashes in page paths#92JonasJesus42 wants to merge 1 commit intomainfrom
JonasJesus42 wants to merge 1 commit intomainfrom
Conversation
Admin editors sometimes save page blocks with a path ending in "/" (e.g. /ofertas/datas-promocionais/). TanStack Router strips the trailing slash at the edge (307 to the no-slash form) before matching, so the page was only reachable via the exact form in the block, which the router never delivered. The existing matchPath happened to work for both URL forms because of a filter(Boolean) side-effect, but page.path was still stored with the trailing slash, which leaked into sitemap.ts:87 (URLs in the sitemap would 307 on crawl, wasting budget) and resolveDecoPage result path (pagePath on the resolved page). Normalize once at load time so every downstream consumer sees the canonical no-trailing-slash form, and make matchPath explicit about the normalization as defense-in-depth. Root path "/" is preserved as-is. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
CMS pages created in the admin with a path like
/ofertas/datas-promocionais/were effectively unreachable:/foo/→/fooat the edge (307).findPageByPath("/foo")had to match a block whosepage.pathwas/foo/.The existing
matchPathinloader.tshappened to work for both forms due to afilter(Boolean)side-effect onsplit("/"), so the page DID render. Butpage.pathwas still stored with the trailing slash, which leaked into:src/sdk/sitemap.ts:87— emitted sitemap URLs ending in/, which crawlers would then see 307 → wasted crawl budget and duplicate-URL noise.src/cms/resolve.ts:1438— thepathfield onDecoPageResultcarried the un-normalized value to callers (pagePathon the resolved page).Real-world case that triggered this audit:
pages-Datas Promocionais-670910was created in admin withpath: /ofertas/datas-promocionais/. TanStack site rendered it (lucky), but the original Fresh/Deno site 404d (nofilter(Boolean)side-effect there).Changes
normalizePagePath(path)— strips a single trailing slash, preserves/.getAllPages()— every consumer now sees the canonical form.matchPath()— make the normalization explicit instead of relying on the implicitfilter(Boolean)behavior.:paramroutes, andgetAllPagesexposure.Test plan
npx vitest run src/cms/loader.test.ts— 8/8 pass (new file)npx vitest run— 75/75 pass, no regressionsnpx biome check src/cms/loader.ts src/cms/loader.test.ts— clean (1 pre-existing info on an unrelated line)npm run typecheck— same 47/48 pre-existing errors inscripts/migrate/, no new errors🤖 Generated with Claude Code
Summary by cubic
Normalize CMS page paths by stripping a trailing slash (except
/) so routes match the router’s redirect and all consumers see a canonical URL. Fixes unreachable pages saved with a trailing slash and removes 307s from the sitemap andDecoPageResult.path.normalizePagePath(path)to strip a single trailing slash, preserving/.getAllPages()so exposed pages use the canonical path.matchPath()for explicit, consistent matching.getAllPages()output.Written for commit 4f53ee9. Summary will update on new commits.