Skip to content

feat(map): server-rendered atlas routes under /map, plus sitemap and robots (C4) - #63

Merged
Ardnived merged 15 commits into
mainfrom
feat/map-atlas-ssr-routes
Aug 27, 2026
Merged

Ardnived merged 15 commits into
mainfrom
feat/map-atlas-ssr-routes

Conversation

@Ardnived

@Ardnived Ardnived commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Every city and every meditation class is now a real URL on this site, server-rendered under /map — indexable, unfurlable, and readable with JavaScript off. Content renders as children of <sahaj-atlas>; the widget adopts the element and replaces them when it mounts, so one document serves crawlers and browsers alike.
  • The server owns the <head> — canonical, hreflang, Open Graph and JSON-LD, all read from the C3 endpoint rather than recomposed here.
  • Adds robots.txt and sitemap.xml, which this app shipped neither of. Preview deployments refuse crawlers; the sitemap lists only URLs this origin is the canonical home of.

Verified end to end

SSR half — on the deployed preview, against live CMS data. GET /map/gb/london:

<title> London, United Kingdom — ancestry-qualified, as upstream composes it
canonical …/map/gb/south-east/london — read from webUrl, never recomputed
hreflang 11 rows (10 locales + x-default)
Open Graph og:title, og:type, og:locale, og:url, og:description
JSON-LD @graph with City + BreadcrumbList; event pages add Event / Place / PostalAddress / GeoCoordinates / Schedule
body <h1>London</h1>, breadcrumb trail, 18 class cards — all inside <sahaj-atlas>

The requested route was /gb/london and the canonical came back /gb/south-east/london — terminal-segment resolution working as designed: stale or shortened ancestry still resolves, and the answer names the URL to redirect to.

Routes that name no document (/map, /map/search, an unknown slug) return 200 and render the widget alone — never a 404, never a 500.

Widget half — measured in a real browser with a dedicated Atlas credential. The widget mounts, replaces the server-rendered children (confirmed: our breadcrumb is gone post-mount), and opens on London with its real class list.

The two bugs this caught

1. Every route with a document 500'd. Routes resolving nothing returned 200, which made it look like bad data rather than a systematic fault. Root cause:

TypeError: ((intermediate value) ?? []) is not iterable
    at getHeadHtml (vike-react/.../onRenderHtml.js:1101)

Head is a cumulative config that vike-react spreads (...pageContext._configViaHook?.Head ?? []), so a bare element takes down the render. Its own types don't say so — ConfigViaHook picks Head from Vike.Config, where it is singular — so the broken form type-checks. Neither tsc, pnpm build, nor the unit tests could catch it: the Page test mocks useConfig. Fixed in fed3a80, with a test asserting Head is an array.

2. The site nav painted over the map. Unsized, the widget's map is position: fixed; inset: 0 and escapes the element (measured box: 0×0), so our sticky; z-index: 50 nav sat on top of it. Fixed by opting into contained map mode (SahajAtlasWeb#170): display: block plus a definite height makes the widget's frame take contain: layout, becoming both the containing block for the map's fixed descendants and a stacking context.

Measured after: element 1152×735, widget frame and canvas both exactly 1152×735 rather than the 1200×919 viewport, nav sitting above at y=128.

⚠ height, never min-height — a min-height box engages containment but then resolves to zero, and the widget refuses and renders uncontained.

Design decisions worth a look

routing=path, not memory. The ticket left this open and expected memory. memory means in-widget navigation never changes the URL, defeating much of why these pages exist; query is worse — the widget would find no ?atlas= on /map/nl/amsterdam, open the atlas root, and replace the content we just rendered.

This is exactly why atlas= rides along on the loader URL. In the browser the readiness marker reports {"routing":"query",…} — path mode is refused because client 39 has canonical: {enabled: false, embed: null}, one of its two documented prerequisites. The widget said so and fell back, and the visitor still landed on London because of that fallback parameter. Enabling the canonical embed flips it to path routing with no code change.

The sitemap's atlas half is filtered to this origin. Ownership is per-subtree, so most regions canonicalize to the national site that owns them; listing those would ask a crawler to index URLs we ourselves declare non-canonical. The set is self-adjusting — legitimately empty on a preview and until the wemeditate.com cutover.

The Atlas credential

Uses a dedicated record rather than the app's own key, which matters beyond tidiness: anything published in page HTML grants everything that record can read.

record id 39, We Meditate Web (Atlas)
roles sahaj-atlas-client
can read regions, events, /api/atlas/seo
denied pages, meditations — site content is walled off

/api/atlas/seo itself is still called server-side only, with SAHAJCLOUD_API_KEY.

Test Results

  • Lint ✓ · Types ✓ · 550 tests passed · Build ✓
  • CI: ✓ all five checks green

Follow-ups (not blocking)

  1. Set PUBLIC__SAHAJ_ATLAS_KEY on the deployment. PUBLIC__ vars are embedded at build time, so it must exist during the Cloudflare build or /map stays static there. The key is public by design.
  2. Enable the canonical embed on client 39 to get routing=path instead of the query fallback.
  3. sahaj-atlas-client for the LOCAL client (id 3) — the atlas surface 403s in local dev with a valid key. Detail in #62 (comment).
  4. Sitemap locale alternates — ten locales done properly means xhtml:link per entry.
  5. withCache reads a stored null back as a miss, so a 404 atlas route re-queries each time. Documented in code rather than worked around.

Notes for reviewer

  • Review pass fixed a real bug: the class page's link guarded with || but built its href with ??, so an empty onlineUrl rendered href="" and hid the real website link.
  • Two review findings were refuted against the live CMS — the sitemap does not leak drafts, because the API client's access control already filters them (pages 66/66 and meditations 121/121 published; lectures carry no _status).
  • Security review: no findings. The one sink, dangerouslySetInnerHTML for JSON-LD, is upstream-escaped and guarded fail-closed by isSafeJsonLd(). React 19 blocking javascript: hrefs was verified empirically.
  • ⚠ pages/[slug]/+route.ts needed an explicit map exclusion. That matcher takes any single segment, so /map silently rendered the Pages "not found" state.

Closes #62

🤖 Generated with Claude Code

Ardnived and others added 11 commits August 25, 2026 15:58
The rule that decides whether a route names a region or an event is
mirrored from SahajCloud's `parseAtlasRoute`, which itself mirrors the
widget's `resolveStack`. All three have to agree about what a route is
*of*, or a page's canonical describes a different document than its body.

Parsed locally rather than deferred to the endpoint because the answer is
needed before the call: it picks the cache TTL, and it distinguishes a
route that names no document (the atlas root, a bare view route) from one
that 404s.

The test table is copied from the upstream spec so a drift in the port
fails a test rather than surfacing as a wrong canonical.

Refs #62

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`GET /api/atlas/seo` is a custom root endpoint belonging to no collection,
so the Payload SDK can't express it — a plain fetch, matching the pattern
the related-content readers already use. It lives in its own module rather
than growing cms-client.ts, which is ~950 lines of collection reads.

The response types are hand-mirrored from SahajCloud's responseTypes.ts:
`pnpm types:cms` generates collections only, so a custom endpoint's shape
is not in payload-types.ts.

Cached per the ticket — a region for an hour, a class for fifteen minutes,
since a stale class is the failure a seeker actually feels. Keyed on the
parsed target rather than the raw route, so the several URLs that name one
document share one entry.

A refusal degrades to widget-only instead of 500ing. That matters beyond
the usual robustness argument: the endpoint is gated on the
`sahaj-atlas-client` role, which production's client holds and the LOCAL
one does not, so these reads 403 in local dev by design.

Refs #62

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
A route function, not a filesystem route: an atlas route runs from zero
segments to a country/region/city/venue chain plus an event id, and the
filesystem router matches a fixed shape. Matching everything under the
prefix is also what the widget's routing=path asks of a host — an in-page
click never reaches the server, but a reload or a shared link does.

Also excludes `map` from the [slug] page matcher. That matcher takes any
single segment, so /map resolved to the Pages renderer and rendered "page
not found" for a route that exists — a failure with no error to notice.
The exclusion derives from MAP_PREFIX so the two can't drift, and a test
pins it along with the near-miss (/maps is still an ordinary page).

Refs #62

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Canonical, the hreflang cluster, Open Graph and JSON-LD, all read from the
endpoint rather than composed here — the canonical especially, since the
ownership walk that produces it lives upstream and a second implementation
would be free to disagree with the first.

Open Graph skips the three properties vike-react already generates from
title/description/image, so no tag is emitted twice.

The JSON-LD is emitted verbatim: upstream escapes `</script>` and `<!--`
with JSON escapes that round-trip, so re-escaping would corrupt it and
re-serializing would strip the escaping that makes it safe. A fail-closed
guard drops the block if a raw sequence ever reaches us — this is a script
sink carrying CMS-authored text on our own page, so an upstream regression
would land here as an XSS.

hreflang is spread in lowercase: React emits the `hrefLang` prop as
authored, and these tags are read by crawlers that pattern-match.

Refs #62

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The split the ticket is built on: the server owns the head, the children
own the body. Content renders inside <sahaj-atlas>, which the loader adopts
rather than replacing — React's createRoot then swaps the children when the
widget mounts. One URL serves a crawler real HTML and a browser the full
interactive atlas.

The loader asks for routing=path, the only mode consistent with these URLs:
under the default query mode the widget finds no ?atlas= on /map/nl/amsterdam,
opens the atlas root, and replaces the content we just rendered — leaving the
head describing Amsterdam and the body showing the world. `atlas=` rides along
as the documented fallback, because path mode also needs a canonical embed on
the client record, which this repo doesn't control.

A missing route is not a 404. The atlas root and the widget's own view routes
name no document by design, and even a stale region link should land on a
working atlas the visitor can navigate out of.

Links prefer the canonical over our own path: ownership is per-subtree, so a
region's canonical may be another client's domain, and linking elsewhere would
build a graph pointing at URLs we declare non-canonical.

Refs #62

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`pnpm types:cms`. Picks up the `webPath` / `webUrl` virtuals on regions
(SahajCloud #640/#646), which the sitemap reads select — they were absent
from the local `RegionsSelect`, so selecting them would not have compiled.

Refs #62

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The app shipped neither, so nothing on it was discoverable except by
link-following — and the /map routes exist precisely to be indexed.

Hono routes beside registerApiRoutes, inside contextStorage() and ahead of
Vike's catch-all. One sitemap file: the whole surface is a few thousand
URLs, well inside the 50,000 a single sitemap allows.

Preview deployments refuse crawlers and serve an empty sitemap. Every PR
builds a preview Worker on workers.dev, and a preview that invites
crawlers competes with production for the same content.

The atlas half lists only URLs this origin is the canonical home of.
Ownership is per-subtree, so most regions canonicalize to the national site
that owns them; listing those would ask a crawler to index URLs we
ourselves declare non-canonical. It follows that the set is legitimately
empty on a preview and until the wemeditate.com cutover.

Each half degrades independently — a sitemap missing its atlas is useful,
and a 500 on robots.txt reads to some crawlers as "crawl nothing".

Locale variants are not listed yet: ten locales done properly means
xhtml:link alternates per entry, which is worth doing separately.

Refs #62

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`pnpm build` fails on `+route.test.ts`: Vike loads every `+`-prefixed file
under `pages/` as a config file and rejects one exporting no `route` /
`default`. Renamed to drop the `+`, which keeps them co-located with their
subjects — the existing tests under `pages/` avoid this by living in an
underscore directory, which these two can't.

Caught by the full build gate; the unit run and typecheck were both green.

Refs #62

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Three findings, all in the atlas sitemap read:

- Reuse: the return shape duplicated `SitemapUrl`; import it instead.
- Rule: the `select` was untyped, which `.claude/rules/cms-api-reads.md`
  forbids — typed against `RegionsSelect`/`EventsSelect` so a CMS schema
  change breaks the build rather than 400ing at runtime.
- Simplification: typed selects remove the `unknown` plumbing and the
  `as string` cast, replaced by a narrowing predicate in the filter.

Refs #62

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
From the /code-review pass. Four findings actioned, two refuted.

- The join/website link guarded with `||` but built its href with `??`, so
  an empty `onlineUrl` passed the guard and rendered `href=""` while hiding
  the real website link. Upstream uses the empty string for "absent"
  elsewhere in this contract, so this was reachable.
- `EventContent` dereferenced images/languages/paragraphs/schedule
  unguarded on a response type that is hand-mirrored from upstream. A field
  that stops being sent should degrade, not 500 the page.
- The 404 branch's comment claimed the answer is cached. It isn't:
  `withCache` reads a stored `null` back as a miss, so a dead route
  re-queries every time. Comment corrected rather than the behaviour — the
  cost is one cheap upstream read on a rare path.
- The script-tag comment named the wrong mechanism: `type="module"` already
  nulls `document.currentScript`, and the loader finds its own tag by
  filename regardless.

Refuted against the live CMS rather than assumed: the sitemap does not leak
drafts. The API client's access control already filters them — pages 66/66
and meditations 121/121 come back `published`, and lectures carry no
`_status` at all.

Refs #62

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
- CLAUDE.md: the new /map atlas routes; the [slug] matcher's greediness and
  why a top-level path owned elsewhere must be excluded there;
  PUBLIC__SAHAJ_ATLAS_KEY; and the Vike plus-file trap that makes a
  `+foo.test.ts` under pages/ fail the build while tests and tsc stay green.
- .claude/docs/local-environment.md: corrects a rule that is now incomplete.
  It said a CMS 403 means a stale key. That holds for content, but the atlas
  surface 403s locally with a perfectly valid key, because .env.local's
  client (id 3) lacks the `sahaj-atlas-client` role that production's
  (id 1) has. Includes how to tell the two apart via /api/clients/me.
- .claude/rules/cms-api-reads.md: custom root endpoints are not collection
  reads — no select/populate, but still cache-and-degrade; plus the
  withCache null-is-a-miss caveat and hand-mirrored response types.

Refs #62

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 26, 2026 •

Copy link
Copy Markdown

Deploying wemeditate-design with  Cloudflare Pages  Cloudflare Pages

Latest commit: 2b9d3ac
Status: ✅  Deploy successful!
Preview URL: https://daad2a06.wm-design.pages.dev
Branch Preview URL: https://feat-map-atlas-ssr-routes.wm-design.pages.dev

View logs

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 26, 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 2b9d3ac Commit Preview URL

Branch Preview URL
Aug 27 2026, 12:42 AM

Ardnived and others added 4 commits August 25, 2026 17:10
Every /map route that resolved a real SEO document returned 500 on the
deployed preview. Routes that resolved nothing — /map, /map/search, an
unknown slug — returned 200, which is what made it look like a data problem
rather than a systematic one.

Root cause, reproduced locally against a fixture and read off the dev
server:

    TypeError: ((intermediate value) ?? []) is not iterable
        at getHeadHtml (vike-react/.../onRenderHtml.js:1101)

`Head` is a *cumulative* config and vike-react spreads it —
`...pageContext._configViaHook?.Head ?? []` — so a bare element is not
iterable and takes the whole render down. Its own types don't say so:
`ConfigViaHook` picks `Head` from `Vike.Config`, where it is singular, so
the broken form type-checks. The ticket's note that this was "verified
against [email protected]" didn't cover the array requirement.

Neither the unit tests nor `tsc` nor `pnpm build` could catch this — the
Page test mocks `useConfig`, so nothing exercised the real one. Only
rendering through vike-react does. The test now asserts `Head` is an array,
which is the cheapest available proxy.

Verified after the fix by rendering a fixture document in dev: 200, with
the canonical, both hreflang alternates, og:type/og:locale, the JSON-LD
block, and the h1/subtitle/breadcrumb/class-list inside <sahaj-atlas>.

Refs #62

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Verified in a browser against the production loader: unsized, the map is
`position: fixed; inset: 0` and escapes the element (whose box measured
0x0), so our LayoutChrome nav — `sticky; z-index: 50` — painted on top of
it. Not a widget bug; the element simply had no box to be contained by.

`display: block` plus a definite height is the documented opt-in for
contained map mode (SahajAtlasWeb#170, merged): the widget's frame takes
`contain: layout`, becoming both the containing block for the map's fixed
descendants and a stacking context, so the host's header floats above the
map like any other content.

⚠ `height`, never `min-height`. A min-height box has a non-zero rect so
containment engages, but the widget's `height: 100%` then resolves against
an `auto` parent to zero; it verifies its own box and refuses, rendering
uncontained.

`overflow-y-auto` keeps the server-rendered content reachable for a no-JS
visitor when a region lists more classes than the box fits — London lists
18 — while crawlers read the DOM regardless of overflow.

Measured after the change: element 1152x735, the widget's frame and canvas
both exactly 1152x735 rather than the 1200x919 viewport, with the nav
sitting above at y=128.

Refs #62

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The atlas owns the viewport, so /map now uses LayoutMap rather than
LayoutChrome. Three differences, all consequences of that:

- Condensed header only. The tall banner is chrome the page has no room to
  give away, and the condensed nav already carries the logo and the
  "classes near me" link, so rendering both duplicated them.
- No footer. The page doesn't scroll, so a footer below the fold would be
  unreachable rather than merely unused.
- No content padding. LayoutChrome's `max-w-7xl mx-auto px-6 py-8` framed
  the map in whitespace; it now meets the nav edge to edge.

`condensed` is a new Header prop rather than a second copy of the nav: it
pins the same state the scroll observer already produces, and skips the
observer entirely since there is nothing left to observe.

The nav construction moves to `useSiteNav`, shared by both layouts — two
copies of it would drift, and it is the one piece of chrome every layout
has in common. LayoutChrome is otherwise unchanged.

`h-dvh` + `flex-1 min-h-0` gives <main> a definite height, which is what
lets the atlas element resolve `h-full` and still opt into contained map
mode — verified in a browser rather than assumed, since that mode fails
silently: element, frame and canvas all 1200x862 (viewport 900 less the
38px nav), page scrollHeight equal to the viewport, no footer, atlas at
left 0.

Refs #62

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The preview build for 863bc16 rendered no loader tag, so
PUBLIC__SAHAJ_ATLAS_KEY did not reach Vite's inliner. Workers Builds
variables are not branch-scoped (production and non-production builds share
one set), and the local build inlines the value correctly when the variable
is present — so this separates "the build predated the variable" from "the
variable is in the runtime section, not the build section".

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@Ardnived

Copy link
Copy Markdown
Contributor Author

Follow-up filed: the atlas root view has no metadata contract

Raised as sydevs/SahajAtlasWeb#173.

This PR already implements the rule that a page's metadata describes the route the widget mounted
with — /map/gb/london mounts with atlas=/gb/london and is described by exactly that route. /map
mounts with atlas=/, the atlas root, and there is nothing to describe it with:

GET /api/atlas/seo?route=/&locale=en  → 404 "That route does not name a region or an event."

That 404 is deliberate on SahajCloud's side (#646: "the atlas root and bare view routes included…
The host owns its own landing page's metadata"
), but the host was never told it owns that, and
docs/embedding.md says nothing about the host's <head> at all.

Consequence in this PR: /map inherits the global site title and description and emits no
canonical, so the atlas entry point reads to a crawler as a duplicate of the homepage. Every region
and class page beneath it is described correctly — only the front door is not.

Not fixed here because the honest fix needs the title and description in ten locales, which is
the same constraint that made #646 return description: null for regions rather than ship English
into a Dutch page's head. #173 asks who owns that.

@Ardnived

Copy link
Copy Markdown
Contributor Author

Tracking issue for the /map metadata gap described above: #64 (labelled wait for upstream, blocked on sydevs/SahajAtlasWeb#173). Nothing further to do in this PR.

@Ardnived
Ardnived merged commit 73b4765 into main Aug 27, 2026
5 checks passed
sydevs-bot pushed a commit that referenced this pull request Oct 5, 2026
Its three siblings moved to ^3.90.2 while this exact pin stayed at
3.88.0, so the lockfile carried `@payloadcms/live-preview` twice where
main carried it once. `pnpm why` now reports one version again.

Both tarballs are byte-identical across 3.88.0 -> 3.90.2 bar their own
version strings, and #63 recorded no reason for the exact pin.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012mJHFSsgnE2qC52UjswTR4
@Ardnived
Ardnived deleted the feat/map-atlas-ssr-routes branch November 13, 2026 03:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(map): server-rendered atlas routes under /map, plus sitemap and robots (C4)

1 participant