Skip to content

feat(admin): add live preview for regions and events via sahaj atlas - #579

Merged
Ardnived merged 10 commits into
mainfrom
feat/atlas-live-preview
Jul 17, 2026
Merged

Ardnived merged 10 commits into
mainfrom
feat/atlas-live-preview

Conversation

@Ardnived

@Ardnived Ardnived commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Regions and Events edit views get a Live Preview tab loading the Sahaj Atlas widget (SAHAJATLAS_URL/preview), with a 390×844 mobile breakpoint. Config is inlined per collection, matching the Pages/Meditations pattern.
  • The preview URL carries the doc id, the shared preview secret, and the edited locale; unsaved docs (no id) return null, disabling the panel until first save.
  • CORS now allow-lists x-sahajcloud-preview-secret: Atlas fetches drafts client-side, so the draft-unlock header rides cross-origin requests and must clear preflight. origins: '*' is kept, so Access-Control-Allow-Credentials stays off (feat(usage): enforce CORS + Origin/Referer against Clients.allowedDomains via usagePlugin #509); the object form appends to Payload's default header list.

Changes

  • src/collections/{Events,Regions} — inline admin.livePreview (URL + breakpoint + unsaved-doc guard)
  • src/payload.config.ts — cors: '*' → cors: { origins: '*', headers: [PREVIEW_SECRET_HEADER] }
  • tests/e2e/cors-preflight.e2e.spec.ts — real OPTIONS preflight against the Railway preview (verifies the allow-list end-to-end in CI)
  • tests/unit/verification-stage-timeline.spec.ts — fixes a pre-existing failure on main: the spec formatted a midnight-UTC instant, which renders as the previous day on machines west of UTC; a zone-less input keeps the day stable everywhere
  • Docs: api-clients.md CORS section updated to the object form; environment.md + .env.example document the no-trailing-slash and restart-for-CSP gotchas; finalize-pr skill gains a baked-in docs-sync step (5) before push, with AGENTS.md/implement-issue summaries aligned

Test Results

  • Unit: 688 passed
  • Integration (targeted): atlas-collections (7, incl. exact preview-URL + unsaved-doc guard) + cors-config (runs Payload's own headersWithCors against the real app config) — all passed
  • Lint + typecheck: ✓ clean (Tier 2 gate)
  • Full suite + smoke: CI (Tier 3)

Manual verification

The CMS side is complete; full iframe behaviour needs the Atlas widget's /preview route (sydevs/SahajAtlasWeb#40, PR sydevs/SahajAtlasWeb#54):

  1. Open an Event (or Region) in the admin → Live Preview tab shows the Atlas widget (verified locally against the dev widget).
  2. Unpublished/draft events render in the preview (draft unlock via the secret header, client-side).
  3. Edit a field without saving → the preview updates live (postMessage).
  4. Toggle the Mobile breakpoint → widget renders at 390×844 (bottom-sheet drawer layout).

Notes for reviewer

  • Verified against Payload's compiled headersWithCors source: cors.headers appends to the default allow-list, and credentials are only enabled for a specific-origin list — never for origins: '*'. Also verified by live preflight against the deployed PR preview.
  • The admin CSP frame-src already includes SAHAJATLAS_URL (env-derived in next.config.mjs), so the iframe isn't CSP-blocked — but it's baked at server boot, hence the new restart gotcha in the env docs.
  • Regions have no drafts — region preview shows published data plus unsaved form edits streamed via postMessage (per the issue, drafts for Regions are out of scope).
  • Security review (CORS + secret-in-URL surface): no findings; the preview-secret header path is cache-exempt (private, no-store).

Closes #575

🤖 Generated with Claude Code

Ardnived and others added 5 commits July 16, 2026 16:10
Both collections load the Atlas widget's /preview route in the admin
Live Preview tab, via a shared atlasLivePreview factory (URL carries
collection, id, the preview secret, and the edited locale) with a
390x844 mobile breakpoint for the widget's bottom-sheet drawer layout.

Refs #575

Co-Authored-By: Claude Fable 5 <[email protected]>
The Atlas widget fetches drafts client-side, so the live-preview secret
header rides a cross-origin browser request and must be in the CORS
allow-list. Payload's object form appends to the default header set and
keeps origins '*', so Access-Control-Allow-Credentials stays off (#509).

Refs #575

Co-Authored-By: Claude Fable 5 <[email protected]>
Unit: atlasLivePreview URL (collection, id, secret, locale) + breakpoint.
Int: both collections wire the config; Payload's headersWithCors against
the real app config allows the secret header, keeps defaults, and keeps
credentials off. Smoke: a real OPTIONS preflight against the deployed
preview.

Refs #575

Co-Authored-By: Claude Fable 5 <[email protected]>
Pre-existing failure on main: the spec formatted a midnight-UTC instant,
which renders as the previous day on machines west of UTC (display is
intentionally viewer-local). A zone-less input keeps the rendered day
stable in every timezone.

Co-Authored-By: Claude Fable 5 <[email protected]>
Drop a needless async on the spec helper and a redundant default-header
assertion.

Co-Authored-By: Claude Fable 5 <[email protected]>
@railway-app
railway-app Bot temporarily deployed to sahajcloud / SahajCloud-pr-579 July 16, 2026 23:48 Destroyed
@railway-app

railway-app Bot commented Jul 16, 2026

Copy link
Copy Markdown

🚅 Deployed to the SahajCloud-pr-579 environment in sahajcloud

Service Status Web Updated (UTC)
SahajCloud ✅ Success (View Logs) Web Jul 16, 2026 at 11:48 pm

Ardnived and others added 5 commits July 17, 2026 10:31
The atlasLivePreview factory abstracted ~6 lines shared by two adjacent
collections while breaking the codebase's inline livePreview pattern
(Pages, Meditations, WeMeditateWebConfig) and needing a derived type
Payload doesn't export. Inline it like the others; URL-shape coverage
moves from the deleted unit spec into the atlas int spec.

Refs #575

Co-Authored-By: Claude Fable 5 <[email protected]>
api-clients.md still described cors: '*'; document the object form and
why the preview-secret header is allow-listed. Add the two gotchas hit
while testing locally: no trailing slash on preview URLs (URL prefix +
Origin comparison) and restart-required for the boot-baked CSP frame-src.

Co-Authored-By: Claude Fable 5 <[email protected]>
New step 5 before push: sweep the branch diff for stale statements in
.claude/rules, .claude/docs, AGENTS.md, DEPLOYMENT.md, .env.example and
skill docs, commit updates as their own commit. Pipeline summaries in
AGENTS.md and implement-issue updated to match.

Co-Authored-By: Claude Fable 5 <[email protected]>
The prose already requires checking skill docs; the copy-paste template
omitted the path.

Co-Authored-By: Claude Fable 5 <[email protected]>
An unsaved doc has no id, so the preview URL pointed the widget at
id=undefined; returning null disables the panel instead (Payload's
documented conditional-preview contract).

Refs #575

Co-Authored-By: Claude Fable 5 <[email protected]>
@railway-app
railway-app Bot temporarily deployed to sahajcloud / SahajCloud-pr-579 July 17, 2026 18:03 Destroyed
@Ardnived
Ardnived merged commit 80c812e into main Jul 17, 2026
2 checks passed
@Ardnived
Ardnived deleted the feat/atlas-live-preview branch July 17, 2026 18:13

This branch was successfully deployed

No deployments
sahajcloud / SahajCloud-pr-579 — 529ec3ab Deployed Jul 17, 2026 by railway-app[bot]
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(admin): add live preview for regions and events via sahaj atlas

1 participant