Skip to content

fix(pages): a prefix that is not a language 404s instead of serving a second address - #315

Merged
sydevs-bot merged 3 commits into
mainfrom
claude/fix-unknown-locale-prefix-404
Nov 20, 2026
Merged

sydevs-bot merged 3 commits into
mainfrom
claude/fix-unknown-locale-prefix-404

Conversation

@sydevs-bot

@sydevs-bot sydevs-bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Before this change, a made-up language prefix still opened the page: /zz/meditations/105, /zz/lectures/162, their /embed players, /zz/map and /zz/map/nl all returned 200. That gave every meditation, lecture and the map an unlimited number of duplicate addresses. These paths now return 404 and render the existing "Content Not Found" page. Real language prefixes behave as before: /fr/meditations/105/embed, /ru/lectures/162/embed and /de/map still work, and so do the unprefixed English addresses.

What changed and why

  • F7a, meditation/lecture matcher. lib/document-routes.ts matchDocumentRoute now matches ^/${collection}/([^/]+)${suffix}/?$. The optional (?:/[a-z]{2}(?:-[A-Z]{2})?)? group is gone. pages/+onBeforeRoute.ts already strips a real locale and sets urlLogical, and Vike builds the route functions' urlPathname from that value on both server and client (vike/dist/shared-server-client/getPageContextUrlComputed.js; onBeforeRoute runs with env {server, client}). So the only prefixes that ever reached that group were codes SahajCloud does not define. A ⚠ comment on the matcher records this constraint. Measured on local vike dev, before → after: /zz/meditations/105 200→404, its embed 200→404, /zz/lectures/162 200→404, its embed 200→404. Deployed main Worker today: /zz/meditations/105 and its embed return 200. Pinned by lib/document-routes.test.ts ("does not match a path under an unknown code / a locale-shaped code / a compound code", "does not match an embed path under a prefix").
  • F7a, map matcher. lib/atlas-route.ts matchMapRoute now uses /^\/map(\/.*)?$/. /zz/map and /zz/map/nl go from 200 to 404. /map and /map/nl stay 200. Pinned by lib/atlas-route.test.ts, which moves /zz/map, /zz/map/nl/amsterdam and /fr/map (as the router would see it, unstripped) to the does-not-match table.
  • End-to-end composition spec. pages/onBeforeRoute.test.ts "onBeforeRoute with the route functions" runs the real hook, then every pages/**/+route.ts found through import.meta.glob. A real locale must reach exactly one route: /fr/meditations/105, /fr/meditations/105/embed, /pt-BR/lectures/162, /ru/lectures/162/embed, /de/map, /de/map/nl/amsterdam. No route may claim /zz/meditations, /zz/meditations/105, its embed, /zz/lectures, /zz/lectures/162, its embed, /zz/map, /zz/map/nl/amsterdam or /zz/about. Because the glob picks up new routes, a future index route that keeps the old tolerant prefix fails this spec. I checked that by adding a temporary pages/meditations/(index)/+route.ts with the tolerant /meditations index pattern from feat(components): a MeditationLibrary for the meditations index block #293: "routes nothing for /zz/meditations" failed. With the source fix reverted, the 13 new unit assertions fail.
  • Smoke specs against the deployed preview. tests/smoke/web/meditations.smoke.test.ts adds "serves neither page under a prefix that is not a locale" (/zz/meditations/<id> and its embed must return 404). The new tests/smoke/web/map.smoke.test.ts first checks that /map returns 200 as a control, so its 404s cannot pass on a preview that has no map, then asserts /zz/map and /zz/map/nl return 404. Run against today's main Worker, both specs fail (2 of 3 tests).
  • Route doc lines. The four pages/{meditations,lectures}/[id]/{(full),embed}/+route.ts comments no longer say "an optional /:locale prefix". They now say +onBeforeRoute strips a real locale before the route runs, which matches the matcher's own comment.
  • pages/[slug]/+route.ts:33 is left as it is. That regex does not tolerate a prefix. It is a guard that refuses a path whose first segment looks like a locale, so it creates no duplicate address. /zz/about already returns 404 on the deployed main Worker and locally, and feat(server): switch wemeditate.com over to the new site #288 pins this guard (match('/zz/') is false). The composition spec still asserts that /zz/about reaches no route.
  • F7c(3), embeds keep their language prefix. No change, as decided. /fr/meditations/105/embed and /fr/lectures/162/embed still return 200, and the composition spec pins them.

Not in this PR

  • F7b(1), canonical under a real language prefix (follow-up after feat(seo): share metadata and JSON-LD at parity with the old site #282). On main, ContentHead (lib/head.tsx, localeUrl(origin, locale, path)) emits a prefixed self-canonical. I tested this locally with the locale gate bypassed temporarily (the change was reverted and never committed): /fr/meditations/105 gave a canonical of …/fr/meditations/105, and /fr/lectures/162 gave …/fr/lectures/162. The decision wants the English (unprefixed) address. feat(seo): share metadata and JSON-LD at parity with the old site #282 rewrites this code, and its lib/content-seo.ts canonicalUrl(route) is still localeUrl(route.origin, route.locale, route.path). That value also feeds og:url, the JSON-LD url fields and the oEmbed discovery url=. Follow-up once feat(seo): share metadata and JSON-LD at parity with the old site #282 merges: build those four values from localeUrl(origin, DEFAULT_LOCALE, path) in meditationSeo and lectureSeo, and keep the visitor's locale for og:locale and inLanguage. Production offers only English today (availableLocales is []), so /fr/meditations/105 returns 404 for now.
  • F7b(2), lecture subtitle language (report only). With feat(player): move VideoPlayer from Vidstack to Video.js 10 #285 merged, VideoPlayer wraps itself in I18nProvider and SubtitlePreference selects the page-language track, so lectures follow the URL language. Before feat(player): move VideoPlayer from Vidstack to Video.js 10 #285, Chromium against the deployed Worker showed the IT track on /it/lectures/162/embed and the RU track on /ru/lectures/162/embed. One gap remains: PageTemplate's featured video never passes subtitleLang, so its inline track is always labelled EN. Passing the page locale would mislabel the cases where English is served as the fallback. A correct fix needs the cues' source locale (for example, a read with fallbackLocale off). Affected today: 5 live pages have a featured video, and 1 of the 6 videos has subtitles.
  • No translation keys are needed.
  • pnpm build was not run. This bundle changes no dependencies, CSS, bundling or CI config.

Reconciled with open PRs

Test results

.claude/skills/pr-prep/check.sh exit 0 after the rebase onto main:

  • Lint: 0 errors, 1087 warnings, all already on main. eslint on the 11 changed files reports nothing.
  • tsc --noEmit: passed.
  • vitest: 131 files, 1293/1293 tests passed.
  • pnpm build: not run (not required for this bundle).

🤖 Generated with Claude Code

https://claude.ai/code/session_01Mg9rjZcE8bs5uRJ6dsg6kw

…ddress

`/zz/meditations/105`, its `/embed`, the lecture pair and `/zz/map` all
answered 200 with the page at the bare path, and the full pages declared
that prefixed URL their own canonical. The meditation, lecture and map
matchers each accepted an optional `/xx` or `/xx-YY` segment ahead of
their path.

That segment never carries a real locale by the time a route runs:
`+onBeforeRoute` strips one SahajCloud defines into `urlLogical`, and Vike
hands every route function that path, on the server and in the client
router. So only a code SahajCloud does not define (`zz`, `st`) ever
reached the optional group, and the tolerance did nothing but mint
duplicates. The matchers now take the bare path, and an unknown prefix
404s through the error page like `/zz/about` already did.

`pages/[slug]/+route.ts:33` is left as it is: its locale-shaped regex
refuses a path rather than tolerating one, so it creates no duplicate,
and #288 pins `/zz/` against it.

The routing spec in `pages/onBeforeRoute.test.ts` runs the hook and then
every `+route.ts` under `pages/` (an `import.meta.glob`, so a new route
joins it), and pins both sides: a real locale still reaches the
meditation, lecture and map routes, and nothing claims the `/zz/` paths.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjZcE8bs5uRJ6dsg6kw
The unit specs prove the matchers; these prove the deployed Worker, where
the duplicates were first seen. A meditation and its embed under `/zz/`
must 404, and so must `/zz/map` and a route under it, beside a `/map`
control that keeps a preview serving no map at all from passing them.

Both specs fail against the current main Worker (200 for each `/zz/` path)
and pass once this branch's preview serves the fixed matchers.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjZcE8bs5uRJ6dsg6kw
The composition spec listed only document paths, so an index route that
kept the old optional prefix (as the open /meditations index does) would
answer /zz/meditations and stay green. The route doc lines now say a real
locale is stripped before the matcher runs, which is what the matcher's
own comment states.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjZcE8bs5uRJ6dsg6kw
@cloudflare-workers-and-pages

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-design 3a25d61 Commit Preview URL

Branch Preview URL
Nov 19 2026, 11:07 PM

@sydevs-bot
sydevs-bot added this pull request to the merge queue Nov 20, 2026
Merged via the queue into main with commit dbf71dc Nov 20, 2026
12 checks passed
@sydevs-bot
sydevs-bot deleted the claude/fix-unknown-locale-prefix-404 branch November 20, 2026 00:06
@sydevs-bot sydevs-bot moved this from Awaiting to Done in SYDevelopers Technical Roadmap Nov 20, 2026
sydevs-bot pushed a commit that referenced this pull request Nov 20, 2026
#315 landed on `main` and removed the optional locale prefix from every
document-route matcher: `+onBeforeRoute` strips a real locale into
`urlLogical` before any route runs, so a prefix still reaching a matcher is
not a locale, and tolerating it served `/zz/meditations/105` as a second
address of the page.

This branch's new `/meditations` matcher was built on the prefix that fix
deletes, so `main`'s rule is applied to it too rather than only to the hunk
git flagged:

- `documentRoutePattern` takes `main`'s bare-path regex.
- `MEDITATIONS_INDEX_ROUTE` loses the prefix, and `LOCALE_PREFIX` goes with
  it — nothing else referenced it.
- `pages/meditations/(index)/route.test.ts` pinned `/fr/meditations` and
  `/pt-BR/meditations` as matches. They are now refused, beside `/zz/`.
- `pages/onBeforeRoute.test.ts` gains the positive counterpart of the
  `/zz/meditations` row it already carried: `/fr/meditations` reaches the new
  index route through the hook.

The list route itself is unchanged — `/fr/meditations` still answers 200,
because the hook hands the router `/meditations`.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjVZyqL7JbDkVBd4Szb
sydevs-bot pushed a commit that referenced this pull request Nov 20, 2026
Smoke (web) failed on `/zz/map` and `/zz/meditations/142` answering 200
where 404 is asserted. Neither assertion exists on this branch: both arrived
with #315 on main. CI checks out the pull request's merge ref, so it ran
main's new smoke specs, while the Cloudflare preview it fetched was built
from this branch's tip, which predates that routing fix. Production answers
404 for `/zz/map`; all three of this branch's previews answer 200.

So the merge is the fix. Pushing it rebuilds the preview with #315's routes
in it, and the specs then run against a Worker that has them.

Nothing conflicted. #315 touched `lib/atlas-route.ts`,
`lib/document-routes.ts` and the four `+route.ts` matchers; this branch
touches the meditations region of `server/sahajcloud-client.ts` and the
`_meditation.ts` loader, which runs only after a matcher has claimed the
path.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjXbkobB5uhfhfthYE5
sydevs-bot pushed a commit that referenced this pull request Nov 20, 2026
#315 made the document route matchers take a bare path: Vike hands a
route function the path `+onBeforeRoute` already stripped, so a prefix
that still reaches one is not a language, and tolerating it served
`/zz/lectures/163` as a second address.

`/oembed` is a Hono route, where nothing stripped anything, so it was
relying on that tolerance to resolve `/fr/lectures/163`. It now strips
the locale itself through `localeFromPath` — the same derivation the
rest of the site uses, which leaves an undefined code in place, so a
media path under one is refused here too.

The locale rides on the resolved target instead of being parsed a
second time in the handler, so the path the matcher saw and the
language the player answers in cannot disagree.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjY1HQUVjZbWcpFW73g
sydevs-bot pushed a commit that referenced this pull request Nov 20, 2026
The lane reached `/oembed` only through the discovery link on a bare
`/lectures/:id`, so no spec sent it a prefixed URL at all — which is
why the merge with #315 broke the locale case with the smoke lane
green. The refusal is the half with no data dependency: a lecture need
not be published in any particular language for `/zz/` to 404.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjY1HQUVjZbWcpFW73g
sydevs-bot pushed a commit that referenced this pull request Nov 20, 2026
Fixes the red `Smoke (web)`: `/zz/map should 404: expected 200 to be 404`,
and the same for `/zz/meditations/<id>`.

The smoke job runs the spec from the merge ref but fetches the preview
Cloudflare built from this branch's head (#295). `main` carries both halves
of #315 — the matchers that stop an unknown prefix minting a second address,
and the smoke spec that pins it — while this head carried only the spec's
absence. Bringing the base in puts the matchers on the head the preview is
built from, so there is nothing else to fix here.

Base merged clean. Lean gate green: lint, `tsc --noEmit`, 1482 tests in 150
files, `pages/onBeforeRoute.test.ts` among them.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjXMjw8p5ZyKppLjncT
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.

3 participants