Skip to content

fix(preview): a translations session should not inert the widget it is previewing - #215

Merged
sydevs-bot merged 7 commits into
mainfrom
claude/fix-211-preview-scope
Sep 18, 2026
Merged

sydevs-bot merged 7 commits into
mainfrom
claude/fix-211-preview-scope

Conversation

@sydevs-bot

@sydevs-bot sydevs-bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • A translator previewing sy-atlas-translations can now click through the widget to reach the screen their string appears on.
  • The session reads the scope parameter SahajCloud has been sending all along, and a scoped session takes neither the link guard nor the pinned query defaults.
  • A document session is unchanged, on any route. An unrecognised scope reads as a document session, never as an error.

Changes

  • src/config/live-preview/protocol.ts — scope joins LivePreviewSession; documentPreviewActive() is the predicate.
  • src/config/live-preview/boot.ts — narrows scope inline, on every route.
  • src/components/live-preview/LivePreviewController.tsx — turns a scoped session away; the hook-bearing body is now DocumentLivePreview.

Three review follow-ups:

  • 24afa08 — the file's header claimed it "holds no behaviour at all", which the new predicate made false. It now says nothing here acts, and names what the predicate reads.
  • 9aa19dd — a ⚠ line at LivePreviewScope naming readLivePreviewParams as the set's second home, so a member added to the union is not silently left unparsed.
  • 0122180 — Widget.standalone.test.ts closes the session's writer list to boot.ts, so a preview session cannot be opened from the widget graph. See the standalone-only note below.

Preview

Branch alias: https://claude-fix-211-preview-scope.sahajatlas.pages.dev — it follows this branch, so it lags a fresh push by a deploy. The tab to open is /admin → Sahaj Atlas → Translations.

Test results

  • Lean gate: ✓ lint, typecheck, test:run (121 files / 1537 tests) — re-run after 0122180.
  • Targeted specs: 13 new assertions across boot.test.ts, fetch.test.ts, LivePreviewController.guards.test.tsx, Widget.standalone.test.ts
  • Build: ✓ including pnpm size — standalone 296.0 / 308, loader 2.6 / 3.5, embed 297.9 / 308 KiB. Measured before the three review commits, none of which ships code. CI re-runs both.

Manual verification

  1. /admin → Sahaj Atlas → Translations → any tab: navigate inside the panel, and confirm the widget responds to clicks.
  2. The same panel on an event or region path: confirm links are still inert and navigation still snaps back.
  3. Save a translation without publishing it, then confirm the draft string still renders on a view path.

Notes for reviewer

Preview is standalone-only, and 0122180 is what now enforces it. It already held by construction: only activateLivePreview (boot.ts) may flip active, and boot.ts is unreachable from Widget.tsx — asserted since #208. The gap was the other side. protocol.ts holds the session as a mutable singleton both graphs import, and the request interceptor (also both graphs) attaches the credential and draft=true on active plus token alone, so one write from widget-graph code would have the embedded element sending a CMS credential out of a host page. Nothing could see it: the size budget reads bytes, the graph walk reads imports. 0122180 closes the writer list to boot.ts.

No code drops out of this, and the "simplify" half is a question back to you. The shared module is shared for the interceptor's sake, not the controller's — the controller is already behind a lazy seam with one asserted importer. The version that really would shrink the widget is splitting the preview branch out of config/api/client.ts so the embed graph carries no preview credential path at all. That is a bigger change than this PR, and it wants its own ticket. Say the word and I will file it.

draft=true stays session-wide. It is what fetches the unpublished translation the translator is previewing, so it is not one of the restraints this drops. The finer per-read split #211 quotes from WeMeditateWeb — drafts for the translations read, published for the document reads — is a separate decision and is left open. fetch.test.ts pins the current behaviour so the symmetry is not "tidied" by accident.

This does not deliver the resolved view target discussed on the ticket. That is the second, independent door, and no acceptance criterion here depends on it.

RegistrationForm deliberately still reads livePreview.active, not the new predicate: no preview session of any kind may register someone against a draft event.

Detail

Why no runtime standalone && term at the mount site. App.tsx:433 gates on livePreview.active, and adding standalone && beside it would read as enforcement while enforcing nothing: in widget mode active is already unreachable, which is exactly what 0122180 now asserts. A guard no spec can drive red is the #161 shape — a simulation that cannot fail checks nothing. config/mode.ts already carries the invariant in prose, and the closed writer list now carries it as a gate.

Why the gate is an early return rather than a flag. The first draft threaded an enabled boolean through both hooks and the target resolution — one bit at four sites, inside a component that never varies it. LivePreviewController now calls no hooks itself, so if (!documentPreviewActive()) return null is legal above them, and DocumentLivePreview holds the rest verbatim.

Why the gate is not in App.tsx instead. Moving it to the mount site would also skip the lazy chunk for a scoped session, which is a real saving. It would also leave the wiring untested: the predicate is pure and the mount is one expression in a component with no spec, which is the shape of the #132 defect — four green assertions over a helper nothing called. Keeping the gate in the component is what lets guards.test.tsx observe the outcome (a click not cancelled, no query defaults, no populate request). The cost is one dynamic import inside the CMS admin, and no eager bytes. The adversarial review's counter — that the swap renames an untested seam rather than adding one — is fair as far as it goes. What the swap changes is what that one expression carries: today a single bit, afterwards the whole of #211.

Why scope narrows inline rather than through a closed-set helper: collection narrows exactly that way three lines above it, and the repo has no shared closed-set codec. 9aa19dd records the resulting two-home coupling at the type rather than closing it, because collection carries the identical split and guarding one alone would read as a distinction that is not there.

Red first, every assertion. The four guard cases were driven red by removing the early return; the scope case by hard-coding scope: null; the closed-set case by a pass-through parse; the draft case by gating applyRequestContext on the scope. The writer-list case by adding a write to App.tsx, on both detector arms — a property assignment and an Object.assign. Each was restored after.

Reviews run. Four cleanup lenses (reuse, simplification, efficiency, altitude) — the restructure above came from two of them agreeing; /code-review at high — no findings, two wording claims tightened in ccbdd9d; /security-review — no findings. It confirmed one thing worth knowing: a failed token verify wipes scope too, because LIVE_PREVIEW_INACTIVE carries the new field. The adversarial review then raised three threads, all now resolved.

Fixture pre-mortem. guards.test.tsx assumes the CMS sends scope=sy-atlas-translations as a query parameter on an ordinary atlas path. Verified against SahajCloud/src/globals/SahajAtlasTranslations/SahajAtlasTranslations.ts, which composes exactly that.

Docs checked, nothing stale. docs/architecture.md and docs/rules/data-layer.md both say draft=true attaches during a verified session, which is still true. Nothing here is host-observable, so docs/embedding.md and CHANGELOG.md are untouched.

Not run: the contract step (pnpm types:cms) — no CMS schema is involved.

Closes #211

🤖 Written by the sydevs autonomous loop — see what this is

🤖 Generated with Claude Code

https://claude.ai/code/session_01PgvGMeV1B6HNtNDNKUwXq3

SahajCloud points the translations panel at the atlas root and names the global
it is previewing in `scope`, because a CMS global has no page of its own to be
previewed at. `readLivePreviewParams` never looked for it, so the parameter rode
in the URL unused and a translations session was indistinguishable from a
document one.

`scope` joins the session, parsed against a closed set.

⚠ **Closed, because an unrecognised value must read as a DOCUMENT session.** The
parameter arrives unauthenticated on a URL anyone can compose, and the scoped
session is the one that will hold fewer restraints. A typo, an older CMS, or a
stranger's link therefore falls back to the stricter reading, never to an error.

The scope is read on every route, unlike the collection and id, which only
`/preview` carries: a global is previewed at whatever path its tab targets, and
that path is an ordinary atlas path.

Names mirror WeMeditateWeb's `lib/live-preview/`, which reads the same parameter
from the same CMS.

Nothing consumes the field yet, so behaviour is unchanged.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012WEMZsUZE6A2dsLWSAMc84
A translator previewing `sy-atlas-translations` got a widget where nothing was
clickable, so they could not reach the screen the string they were editing
appears on. Five of the panel's tabs are reachable only by clicking: `event`,
`registration` and `share` are keyed by an event id, `online` by a region that
has online events, and `compact` by the measured box. No static preview target
can name any of them.

`LivePreviewController` ran both session-wide hooks before it resolved what was
being previewed, so both applied to every verified session.

Both are right for a DOCUMENT session and neither is right for a scoped one. The
link guard keeps the panel from navigating away from the document being edited.
The pinned `['event']` / `['region']` defaults keep a live-overlaid document from
being refetched out from under an unsaved edit. A translations session has no
document to leave and no overlay to protect, so the guards only took away the
navigation the translator needed.

`documentPreviewActive()` — `active && scope === null`, WeMeditateWeb's predicate
over the same parameter — now gates both hooks and the target resolution. A
scoped session installs no listener, pins no defaults, and mounts no document
arm. A document session is untouched, whatever the route.

**`draft=true` stays session-wide, deliberately.** The guards are UI restraints;
this is how a saved-but-unpublished translation is fetched at all. Scoping it the
way the guards are scoped would leave a translator previewing copy that is
already live. A spec in `fetch.test.ts` now pins that, since the symmetry is
inviting and wrong.

Each new assertion was watched failing first, at the site of the defect: the
guard cases against unconditional hooks, the arm cases against an ungated target,
the closed-set case against a pass-through parse, and the draft case against
`applyRequestContext` gated on the scope.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012WEMZsUZE6A2dsLWSAMc84
Three findings from the cleanup pass, each reported independently.

**The gate is one early return, not a boolean threaded through two hooks.**
`LivePreviewController` now turns a scoped session away and delegates the rest
to `DocumentLivePreview`. It calls no hooks itself, so the conditional return is
legal, and the six edit sites the `enabled` parameter needed collapse to one.
Two private hooks stop advertising a condition they do not own.

**The scope narrows inline**, the way `collection` narrows three lines above it,
so `LIVE_PREVIEW_SCOPES`, `readLivePreviewScope` and one exported symbol go. The
repo has no shared closed-set codec — every param codec open-codes this — and
the nearest precedent is in the same function.

**Both preview specs reset through `LIVE_PREVIEW_INACTIVE`** instead of listing
fields. `transport.test.ts` already leaked `scope` between cases in this branch,
which is the failure mode: a missed field is silent, not a red test.

The four guard assertions were re-driven red against the new gate site, and the
closed-set assertion against a pass-through parse.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012WEMZsUZE6A2dsLWSAMc84
Review read the `documentPreviewActive` docblock as arguing that `draft=true`
must stay session-wide because the alternative is dropping it — which is only
the coarse alternative. The finer per-READ split WeMeditateWeb makes (drafts for
the translations fetch, published for the document ones) is untouched by that
argument, and #211 leaves it open. The docblock now names it as the separate
decision it is.

The closed-set ⚠ also justified itself as guarding an unauthenticated
parameter, which is weak: scope is only read inside an already-verified session.
What the fallback really buys is that a renamed global or a newer CMS cannot
silently drop the document guards.

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

cloudflare-workers-and-pages Bot commented Sep 18, 2026 •

Copy link
Copy Markdown

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Sep 18, 2026 •

Copy link
Copy Markdown

Deploying sahajatlas with  Cloudflare Pages  Cloudflare Pages

Latest commit: 0122180
Status: ✅  Deploy successful!
Preview URL: https://309e819c.sahajatlas.pages.dev
Branch Preview URL: https://claude-fix-211-preview-scope.sahajatlas.pages.dev

View logs

@sydevs-bot sydevs-bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Sep 18, 2026
@sydevs-bot

sydevs-bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 no session running

recent dispatches
  • 23:08Z address-review · attempt 1 · session · done
  • 23:08Z address-review · attempt 1 · session
  • 18:22Z address-review · attempt 1 · session · done
  • 18:22Z address-review · attempt 1 · session
  • 17:46Z address-review · attempt 1 · session · done

Written by the sydevs dispatcher. Sessions never edit this comment.

@sydevs-bot sydevs-bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧐 Adversarial review

The diff is the size #211 asked for — 65 source lines, both deferred doors still deferred. guards.test.tsx pairs every scoped case against a document case on the same path, so nothing passes vacuously. SahajCloud agrees: SahajAtlasTranslations.ts composes scope=sy-atlas-translations as the fixture assumes.

One shape question. App.tsx:433 already gates the controller on livePreview.active. Swapping that word for documentPreviewActive() deletes the whole LivePreviewController.tsx hunk.

Findings

  • should-fix — move the gate to the existing mount condition. LivePreviewController.tsx:298
  • consider — one caller, in a file that claims no behaviour. protocol.ts:142
  • consider — the closed set has two homes. boot.ts:104

What was checked

Read whole: protocol.ts, boot.ts, LivePreviewController.tsx, all four specs, plus the mount site. Boot order makes the pre-hook read safe. WeMeditateWeb's mirror is unverified — outside this run.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

Comment thread src/config/live-preview/protocol.ts Resolved
Comment thread src/config/live-preview/boot.ts Resolved
@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Sep 18, 2026
The header said the module "holds no behaviour at all", and cited the pure
URL reader living in boot.ts as the precedent. An exported predicate now
sits below it, so the claim read false to anyone opening the file.

The predicate stays. The rule the header carries is about weight in a
shared chunk, and reading two fields off the session object next to it
costs nothing a consumer of that object was not already carrying. Both
graphs reach it, unlike boot.ts, which is what sent the URL reader away.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012xKJe8kdfXWAw9d3whp1gj
The union and the narrowing in `readLivePreviewParams` spell the same
closed set. Adding a member to the union leaves that narrowing compiling
clean and silently never parsing it, because a subset is still valid.

No codec: `collection` two lines above carries the identical split, so a
type-level guard on one and not the other would read as a distinction
that is not there. Closing both homes is its own change. This records
where the second one is, which is what the next editor needs.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012xKJe8kdfXWAw9d3whp1gj
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Addressed the adversarial review — two adopted, one rebutted. Pushed 9aa19dd.

  • Adopted protocol.ts claims no behaviour — 24afa08. The header now says nothing here acts. Kept the function: the widget graph reaches its caller, unlike boot.ts.
  • Adopted the closed set has two homes — 9aa19dd. A ⚠ line at LivePreviewScope names the second. No codec: collection carries the identical split.
  • Rebutted, open move the gate to App.tsx:433. The four scoped cases in guards.test.tsx mount the controller directly, and the mount site has no spec to hold them. Weighed against one lazy chunk fetch in the CMS admin. Your call settles it.

Both commits are comment-only. Lean gate green: lint, typecheck, 1536 tests.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

@sydevs-bot sydevs-bot removed the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Sep 18, 2026
@sydevs-bot
sydevs-bot marked this pull request as ready for review September 18, 2026 17:55
@sydevs-bot
sydevs-bot requested a review from Ardnived September 18, 2026 17:55

@Ardnived Ardnived left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The preview mode should only be supported in the standalone mode, never in the widget mode. Can we use that to simplify the code? And also enforce that to avoid confusion and security issues in the future.

SahajCloud's live previews will always target the standalone atlas (at sahajatlas.com), the widget mode is to support other client sites to embed on their own pages instead of framing.

@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed awaiting labels Sep 18, 2026
The graph walk above keeps `boot.ts` out of the widget entry, but the
session itself lives in `protocol.ts`, which both graphs reach on purpose
— a mutable singleton any importer can assign to. The request interceptor
is in both graphs too, and attaches the preview credential and
`draft=true` on `active` plus `token` alone.

So one write from widget-graph code would have the embedded element
sending a CMS credential out of a host page we do not own, with every
existing gate still green. Nothing in the repo could see it: the size
budget reads bytes, the graph walk reads imports, and this is neither.

`boot.ts` verifies a signature before it flips `active`, and reaches only
`main.tsx`. Closing the writer list to it is what makes "a preview
session is standalone-only" structural rather than incidental. Reading
stays open — four modules do it.

Driven red at the site that would cause it, on both arms: a property
assignment and an `Object.assign`, each added to `App.tsx`.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01PgvGMeV1B6HNtNDNKUwXq3
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Preview is standalone-only — enforced in 0122180. Pushed.

It already held one way: only boot.ts flips active, and the widget entry cannot reach boot.ts. The open side was the session itself. protocol.ts is a mutable singleton both graphs import, and the request interceptor attaches the credential and draft=true on active plus token. One write from widget-graph code would send a CMS credential out of a host page, with every existing gate green. Widget.standalone.test.ts now closes the writer list to boot.ts. Driven red on both arms.

On simplifying — no code drops out, and the version that would needs your call. The shared module is shared for the interceptor, not the controller. Splitting the preview branch out of config/api/client.ts would leave the embed graph carrying no preview credential path at all. That is bigger than this PR. Say the word and I will file the ticket.

Lean gate green: lint, typecheck, 1537 tests.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

@sydevs-bot sydevs-bot added awaiting and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Sep 18, 2026
@Ardnived

Copy link
Copy Markdown
Contributor

On simplifying — no code drops out, and the version that would needs your call. The shared module is shared for the interceptor, not the controller. Splitting the preview branch out of config/api/client.ts would leave the embed graph carrying no preview credential path at all. That is bigger than this PR. Say the word and I will file the ticket.

@sydevs-bot Go ahead and file the follow-up ticket

@sydevs-bot
sydevs-bot added this pull request to the merge queue Sep 18, 2026
@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed awaiting labels Sep 18, 2026
Merged via the queue into main with commit b9a2f1e Sep 18, 2026
17 checks passed
@sydevs-bot
sydevs-bot deleted the claude/fix-211-preview-scope branch September 18, 2026 23:11
@sydevs-bot sydevs-bot moved this from Revising to Done in SYDevelopers Technical Roadmap Sep 18, 2026
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Filed the follow-up — #217. Nothing else on this PR was open.

No code changed here. The three review threads were already resolved, and #215 merged at 23:11 UTC while this run was reading it.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

@sydevs-bot sydevs-bot removed the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Sep 18, 2026
sydevs-bot pushed a commit that referenced this pull request Sep 18, 2026
#215 landed the `scope` parameter and the `documentPreviewActive()` gate on
the same four files this branch rewrites. Both sides are kept.

`boot.ts` — the session keeps no `collection` (this branch) and gains `scope`,
read on every route (#215). `protocol.ts` merged clean and already carries that
shape.

`LivePreviewController.tsx` — both imports. The gate turns a scoped session
away, and the document arm below it still picks the submission arm on a boot
id.

`boot.test.ts` — #215's two scope cases join this branch's "reads no collection
off the boot URL", which subsumes #215's collection-nulling case: the field is
gone from the session, not narrowed.

`transport.test.tsx` — reset through `LIVE_PREVIEW_INACTIVE`, which is #215's
own fix for the `scope` leak this branch's spec would otherwise carry.

Lean gate green: lint, typecheck, 1559 tests across 122 files.

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

fix(preview): a translations session should not inert the widget it is previewing

3 participants