Repository navigation
feat(pages): canonical and hreflang from per-locale publish state - #95
Conversation
The contract step for this branch (`pnpm types:cms`). It picks up the atlas translations' new `seo` group, unrelated to this change but part of the same regenerated file. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TZi28MqR2xkFgZvxbx8JR1
Content pages emitted no `<link rel="canonical">` at all — only `/map` had one, from the atlas SEO endpoint. So `/`, `/:slug`, `/meditations/:id` and `/lectures/:id` had neither a canonical nor the hreflang cluster that belongs with it, and Google discards a cluster whose members are not self-canonical. Both ship together here. A URL advertises the locales its own document is published in, read from the per-locale `_status` map that SahajCloud#718 made readable, and filtered by the site's `availableLocales`. Using the site set alone would declare translations that do not exist: Payload's fallback renders English for an untranslated page, and a locale the site does not offer 404s. `lib/hreflang.ts` owns that derivation and the alternate URL shape, so the page head and the sitemap cannot disagree. `getPageAdvertisedLocales` is a second, locale-agnostic read beside the content read — `?locale=all` turns every localized field into a map, which every consumer of `Page` would otherwise have to unpick. Its cache key carries no locale, so all locales of a page share one entry, and it degrades to no cluster rather than failing the render. `useContentHead` is called from each route's `+Page.tsx`, not from the templates: `PageTemplate`, `MeditationTemplate` and `LectureTemplate` are shared with the embed routes and the live preview, and neither is a URL to point a crawler at. `meditations` and `lectures` get the canonical alone — neither opts into per-locale publish state upstream, so neither has a per-document translation claim to make. `lib/head.ts` becomes `.tsx` because it now renders an element. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TZi28MqR2xkFgZvxbx8JR1
`sitemap-routes.ts` deferred locale variants on purpose, and `SitemapUrl` had nowhere to put them. Each page entry now carries one `xhtml:link` per locale it is published in, built by the same `lib/hreflang.ts` function the page head uses. One row per document, not one row per locale variant — that is what the alternates annotation is for, and the `<head>` of every variant already carries the full reciprocal cluster. ⚠ `xmlns:xhtml` is declared on `<urlset>` unconditionally. An `xhtml:link` under an undeclared prefix invalidates the whole document, and Search Console then rejects every URL in it — the silent, total failure `xmlEscape` already exists to prevent. Declaring it always removes the ordering hazard for one attribute. The pages read moves to `locale: 'all'` and adds `_status`, which costs no extra query: `slug` and `updatedAt` are not localized, so they come back as plain values in the same response. The annotation's one added read is `getWebConfig`, for `availableLocales` and the home page's slug — KV-cached for 24 h and shared with every page render. Both halves degrade: a failed config read falls back to English-only clusters, and `/` stays listed even when the content reads fail. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TZi28MqR2xkFgZvxbx8JR1
The unit specs pin the builders. These pin the deployed Worker: a content page declares its own canonical, names the bare English URL and `x-default`, and advertises no locale outside `availableLocales`. Both skip when no CMS key is set, like the existing content-page spec. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TZi28MqR2xkFgZvxbx8JR1
…casts
Review pass over the branch. Each change has its own reason:
**`Head: ContentHead` in `+config.ts`, beside `Layout: LayoutChrome`.**
"This route is an indexable content URL" is route identity, exactly like
"this route wears the site chrome", and it now reads the same way. Two of
the three call sites were a bare `useContentHead()` whose only content was
a comment, so a new content route shipped with no canonical and nothing
failed. One component replaces three hook calls, reads `alternateLocales`
off the route's data, and takes the cumulative-`Head`-array footgun with
it.
**`locale: 'all'` needs no cast.** `@payloadcms/sdk` already declares
`locale?: 'all' | TypedLocale<T>`. The `as unknown as Locale` in both
reads asserted the value was a single locale when it is not, so the field
stopped being checked at all — `'All'` would have passed.
**One `HreflangLinks`.** `ContentHeadTags` had copied `AtlasHeadTags`'
alternate loop, the lowercase-`hreflang` workaround, and the comment
explaining it. The two clusters are built differently — path prefixes here,
`?locale=` query variants for `/map` — but they are spelled once now.
**`getPageLocaleStatus` returns the map, not a locale list.** The read and
the derivation were fused, which forced the read to wait on the config for
`offered`. It now runs in the same `Promise.all` as the page read, and
`advertisedLocales` runs at the call site — the same shape the sitemap
already used. It also returns `{}` rather than `null` (`withCache` reads a
stored `null` as a miss, so every render re-queried) and retries once
rather than stalling TTFB for seconds to decorate a `<head>`.
**The sitemap caches documents, not built URLs.** `offered` and `homeSlug`
were in the cache key, so a CMS config edit orphaned a 500-document read
and every locale set kept its own copy. Annotating after the cache puts the
key back to `{ origin }`, restores the parallel fan-out, and lets the
degraded path list `/` from its own `catch` instead of relying on
first-wins dedup and argument order in another module.
Also: `SitemapUrl.alternates` reuses `Alternate` instead of re-declaring
the shape a third time; `LayoutChrome` takes its `/index` collapse from
`normalizeContentPath`, so the language dropdown and the cluster cannot
disagree; and `normalizeContentPath` runs once per cluster rather than once
per locale.
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TZi28MqR2xkFgZvxbx8JR1
… read Two surfaces the branch makes stale: - The root `AGENTS.md` conventions list had nothing about canonicals. A content route now opts in declaratively, and the rule that a URL advertises only its own published locales belongs beside the other repo-wide rules. - `server/AGENTS.md` covers every CMS read. `locale: 'all'` reshapes every localized field into a map, so it needs the same "when, and only when" treatment the `select` / `populate` / `locale` rules already get — including that only `pages` carries the map, and that the API returns zero docs for a locale a page is not published in. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TZi28MqR2xkFgZvxbx8JR1
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
wemeditate-web | df1e506 | Commit Preview URL Branch Preview URL |
Sep 13 2026, 09:39 PM |
|
🤖 no session running recent dispatchesWritten by the sydevs dispatcher. Sessions never edit this comment. |
`Smoke (web)` failed on "a content page advertises only locales it is published in": the page advertised `en`, and the spec read that as a locale outside `availableLocales`. `wm-web-config.availableLocales` is `[]` in production today, confirmed against the API. `getWebConfig` normalises that to `['en']`, because `loadSiteContext` 404s every locale outside the set and an empty set would 404 the whole site. `discoverFromCms` returned the raw `[]`, so the spec compared the rendered page against a set the Worker never serves — and its two assertions contradicted each other, one requiring `en` in the cluster and the other forbidding it. Mirror the normalisation in the helper. The assertion itself is unchanged: an advertised locale outside the served set still fails. Verified against the PR's preview Worker — the spec fails before this commit and passes after, and the lean gate is green (588 unit tests). Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_012yGdF3ZfEJkKpDxRqT3me3
Deploying wemeditate-design with
|
| Latest commit: |
df1e506
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://ae981d56.wm-design.pages.dev |
| Branch Preview URL: | https://claude-feat-81-hreflang-site.wm-design.pages.dev |
sydevs-bot
left a comment
There was a problem hiding this comment.
🧐 Adversarial review
Holistic. The diff matches #81's shape: one derivation in lib/hreflang.ts, read by both the head and the sitemap, so the two cannot drift. Each new layer pays rent — HreflangLinks is shared with /map, ContentHeadTags is the testable seam, ContentHead is the route entry point. Leaving /fr/meditations/1 self-canonical is right for this ticket. Two problems the diff introduces want an answer first.
Findings
- should-fix — the sitemap's cached value changed shape under an unchanged key (
sitemap-routes.ts:126). - should-fix — the home document is self-canonicalised at two URLs (
sitemap-routes.ts:145). - consider —
getPageLocaleStatusreturnsunknownwherePageStatusexists (cms-client.ts:379).
Checked. Read whole: lib/hreflang.ts, lib/head.tsx, pages/[slug]/+data.ts, server/{cms-client,sitemap,sitemap-routes,kv-cache}.ts. SahajCloud 25c0977 sets localizeStatus: true on Pages, so the locale=all map is live. Unverified: that a nested Head appends to pages/+Head.tsx.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
`content-sitemap:origin=…` held a `SitemapUrl[]` before this branch. It
now holds `{ pages, meditations, lectures }`, and `getCachedResponse`
returns stored JSON without a shape check, so on deploy a warm entry
comes back as an array, `docs.pages` is `undefined`, and the catch
serves `/` alone. Every content URL would drop out of `/sitemap.xml`
for up to `CacheTTL.LIST` (30 min), per origin.
A new prefix lets the old entries expire unread.
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01B3tNA2PUwvjs3UpD9wzcvW
`pages/[slug]/+route.ts` serves the home document at `/${homeSlug}` too,
so the sitemap listed it twice: once as `/` and again at its own slug,
each row self-canonical and each carrying its own cluster. That is the
duplicate-content shape the cluster work exists to avoid.
The `/` row is the one that keeps the cluster, and it now carries the
document's `lastmod`, which the read already held.
Its `<head>` at `/${homeSlug}` still names itself canonical. Pointing
that URL at `/` deindexes a URL the site serves, which is a larger call
than this ticket authorises — noted in the PR body as a follow-up.
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01B3tNA2PUwvjs3UpD9wzcvW
`getPageLocaleStatus` returned `Promise<unknown>` for a value it already knows the shape of, pushing the check downstream. `PageStatus` exists in `server/cms-types.ts`, so the signature is now `Partial<Record<Locale, PageStatus>>`, with the one cast where `locale: 'all'` is applied. `advertisedLocales` keeps its runtime guard: the sitemap hands it a `_status` straight off a generated document type, and meditations and lectures really do return a string or nothing there. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01B3tNA2PUwvjs3UpD9wzcvW
A cached value that changes shape needs a new key prefix, because `getCachedResponse` returns stored JSON unchecked. `getPageLocaleStatus` joins the cached-functions list. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01B3tNA2PUwvjs3UpD9wzcvW
|
All three review findings adopted, pushed as
Nothing rebutted, nothing to ask. Both new specs were watched fail first. One follow-up, now in the body: Gate: lint, 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
`normalizeContentPath` and `localeUrl` restate what `+onBeforeRoute` does — the `/index` spelling of `/`, and the 301 from `/en/x` to `/x`. Neither is an hreflang rule, and neither was only used as one: `layouts/LayoutChrome.tsx` normalizes the path for the language dropdown, and `lib/head.tsx` spells the canonical with both. A reader looking for how this site builds a URL should not have to open a file about search-engine annotations. Both move to `lib/urls.ts`, with their tests. They move as a pair because `localeUrl`'s contract is "pass a path from `normalizeContentPath`", and splitting them would leave the second half of one rule behind. `lib/hreflang.ts` keeps only the cluster derivation: which locales a document may advertise, and the rows it emits. Pure move. No call site changes behaviour, and the 7 relocated assertions pass unchanged. Raised by Ardnived in review: #95 (comment) Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01NkEMjG4Tkumxr5aWxxhSf5
The convention list pointed at `lib/hreflang.ts` for the locale set and at nothing for how a URL is written. The next contributor adding a URL builder would have put it back where it just came from. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01NkEMjG4Tkumxr5aWxxhSf5
|
One adopted, one answered, pushed as
Body updated: Gate: lint (0 errors), 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
Summary
/,/:slug,/meditations/:idand/lectures/:idnow emit a self-referential<link rel="canonical">. Only/maphad one before.hreflangrow per locale its own document is published in, plusx-default— never the site's whole locale set./sitemap.xmlcarries the same cluster asxhtml:linkchildren, and declaresxmlns:xhtml.Changes
lib/urls.ts— new. How this site spells a URL:normalizeContentPathundoes+onBeforeRoute's/indexspelling of/, andlocaleUrlserves English bare because/en/x301s to/x. The canonical, thehreflangcluster and the language dropdown read the same rule from one place.lib/hreflang.ts— new. The one derivation of a cluster: which locales a document may advertise, and the rows it emits. Used by the page head and the sitemap, so the two cannot disagree.lib/head.ts→lib/head.tsx—ContentHead, declared asHead: ContentHeadin a route's+config.tsbeside itsLayout: LayoutChrome.useConfigcannot emit a<link>, so this goes through vike-react'sHead, asuseAtlasHeaddoes.server/cms-client.ts—getPageLocaleStatus, the only single-document read that sendslocale: 'all'. It returnsPartial<Record<Locale, PageStatus>>, with the one cast at the boundary whereallis applied.server/sitemap.ts/sitemap-routes.ts—SitemapUrl.alternates, thexhtmlnamespace, and the annotated page rows. The documents cache undercontent-sitemap-docs, a prefix of their own, and the home document is listed once, as/.server/CACHING.md— the rule behind that prefix: a cached value that changes shape needs a new key, becausegetCachedResponsereturns stored JSON unchecked.Preview
https://claude-feat-81-hreflang-sitemap-alternates-wemeditate-web.contact-c66.workers.dev
A preview origin serves an empty
/sitemap.xmlby design, so check the sitemap on production.Contract impact
Consumes SahajCloud#718:
pagesopts intoversions.drafts.localizeStatusupstream, so?locale=all&select[_status]=truereturns a per-locale map. Nothing this repo exposes changes.server/payload-types.tsis resynced in its own commit.Test results
tsc --noEmit,vitest runlib/urls.test.ts,lib/hreflang.test.ts,lib/head.test.tsx,server/sitemap.test.ts,server/sitemap-routes.test.ts,server/cms-client.test.ts, plus 2 smoke specspnpm buildEach new assertion was watched fail against a reintroduced defect: the
xmlns:xhtmldeclaration removed (1 spec red), thex-defaultrow dropped (4 red),advertisedLocalesreturning the site's locale set instead of the document's published one (4 red), the cache prefix restored tocontent-sitemap(1 red), and the home document left in the pages loop (1 red).Manual verification
<link rel="canonical">names the URL you are on, on both/xand/<locale>/x./sitemap.xmlon production — a preview origin serves an empty one by design — and confirm each page entry carries itsxhtml:linkrows, and that the home document appears once, as/.wm-web-config.availableLocalesis empty in production today, sogetWebConfignormalises it to['en']and every cluster is English-only. Set it to more thanenand re-check a page published in several locales; that is the state the feature is written for.Notes for reviewer
Three judgement calls worth a look:
versions.drafts.localizeStatusupstream, so neither carries a per-document claim that a translation exists. AdvertisingavailableLocalesfor them is the exact failure this ticket's investigation ruled out./fr/meditations/1stays self-canonical rather than pointing at/meditations/1. Its main content is identical English and only the chrome is translated, so collapsing the two is arguable — but deindexing a URL the site serves is a bigger decision than this ticket authorises. Happy to make it a follow-up.<head>carries the full reciprocal cluster. This is also what the code comment this PR replaces asked for: "anxhtml:linkalternate per entry, not ten times the rows".Two observations, one of them now a follow-up:
pages/[slug]/+route.tsserves it at/${homeSlug}as well as at/. The sitemap lists/alone, but/homestill renders a<head>naming itself canonical. Pointing it at/is the textbook use of a canonical and is probably right — it is out of this PR for the same reason as/fr/meditations/1above, and wants its own ticket.locale=enandlocale=allboth return 66 pages and every one isen: published— but the invariant is not enforced. Worth a follow-up if pages ever ship non-English-first.Detail
What the investigation had to settle, and how. Measured against production (
cloud.sydevelopers.com) rather than reasoned from source:?locale=all&select[_status]=trueonpagesreturns{"en":"published"}-shaped maps, andslug/updatedAtcome back as plain values because neither is localized. So the sitemap's pages read gets the map for free — no extra query.meditationsreturns_statusas a plain string;lecturesomits it entirely and every lecture title exists only inen. Neither has a per-locale claim to make.pageContext.urlParsed.originis absolute server-side, so the canonical is built from the origin that served the request rather than a build-time guess.Read counts. The page render adds one read (
getPageLocaleStatus), which runs in the samePromise.allas the page and config reads and whose cache key carries no locale, so every locale of a page shares one entry. The sitemap adds one read (getWebConfig, KV-cached 24 h and shared with every page render) and keeps its three content reads. A spec asserts both counts.Why the
availableLocalesfilter stays at the point of use. It is applied in+data.tsand in the sitemap's row builder, not insidegetPageLocaleStatus. The unfiltered map never crosses to the client —+data.tsreduces it toalternateLocalesbefore returning, and the sitemap's copy never leaves the Worker. Filtering inside the read would land before the KV write, andpage-status:slug=…would then cache a value derived fromavailableLocales, a config its key does not carry. Switching a locale off would leave the stale entry advertising a 404 for a full TTL.Degradation. A failed status read emits no cluster and logs a Sentry warning; a failed config read falls back to English-only clusters; a failed content read still lists
/. None of them fails the page or the document.The cache prefix.
getCachedResponsereturns stored JSON with no shape check, so a key whose value changes shape hands the new code an old value for a whole TTL. Here that would have emptied/sitemap.xmlof every content URL for up to 30 minutes per origin after the deploy. The prefix moves with the shape, and the stale entries expire unread.Rejected while reviewing: adopting
lib/urls.ts'slocaleUrlinsideLink.tsxandEmbedButton.tsx, which hardcode the same "English bare, others prefixed" rule against a'en'literal. Correct, but it changes link building across the site and belongs in its own PR.Closes #81
🤖 Written by the sydevs autonomous loop — see what this is
🤖 Generated with Claude Code
https://claude.ai/code/session_01NkEMjG4Tkumxr5aWxxhSf5