Repository navigation
fix(preview): a translations session should not inert the widget it is previewing - #215
Conversation
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
Deploying sahajatlas-design with
|
| Latest commit: |
0122180
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://0824114d.sahajatlas-design.pages.dev |
| Branch Preview URL: | https://claude-fix-211-preview-scope.sahajatlas-design.pages.dev |
Deploying sahajatlas with
|
| 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 |
|
🤖 no session running recent dispatchesWritten by the sydevs dispatcher. Sessions never edit this comment. |
sydevs-bot
left a comment
There was a problem hiding this comment.
🧐 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
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
|
Addressed the adversarial review — two adopted, one rebutted. Pushed
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 |
Ardnived
left a comment
There was a problem hiding this comment.
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.
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
|
Preview is standalone-only — enforced in It already held one way: only 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 Lean gate green: lint, typecheck, 1537 tests. 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
@sydevs-bot Go ahead and file the follow-up ticket |
|
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 |
#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
Summary
sy-atlas-translationscan now click through the widget to reach the screen their string appears on.scopeparameter SahajCloud has been sending all along, and a scoped session takes neither the link guard nor the pinned query defaults.scopereads as a document session, never as an error.Changes
src/config/live-preview/protocol.ts—scopejoinsLivePreviewSession;documentPreviewActive()is the predicate.src/config/live-preview/boot.ts— narrowsscopeinline, on every route.src/components/live-preview/LivePreviewController.tsx— turns a scoped session away; the hook-bearing body is nowDocumentLivePreview.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 atLivePreviewScopenamingreadLivePreviewParamsas the set's second home, so a member added to the union is not silently left unparsed.0122180—Widget.standalone.test.tscloses the session's writer list toboot.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
test:run(121 files / 1537 tests) — re-run after0122180.boot.test.ts,fetch.test.ts,LivePreviewController.guards.test.tsx,Widget.standalone.test.tspnpm 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
/admin→ Sahaj Atlas → Translations → any tab: navigate inside the panel, and confirm the widget responds to clicks.Notes for reviewer
Preview is standalone-only, and
0122180is what now enforces it. It already held by construction: onlyactivateLivePreview(boot.ts) may flipactive, andboot.tsis unreachable fromWidget.tsx— asserted since #208. The gap was the other side.protocol.tsholds the session as a mutable singleton both graphs import, and the request interceptor (also both graphs) attaches the credential anddraft=trueonactiveplustokenalone, 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.0122180closes the writer list toboot.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.tsso 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=truestays 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.tspins the current behaviour so the symmetry is not "tidied" by accident.This does not deliver the resolved
viewtarget discussed on the ticket. That is the second, independent door, and no acceptance criterion here depends on it.RegistrationFormdeliberately still readslivePreview.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:433gates onlivePreview.active, and addingstandalone &&beside it would read as enforcement while enforcing nothing: in widget modeactiveis already unreachable, which is exactly what0122180now asserts. A guard no spec can drive red is the #161 shape — a simulation that cannot fail checks nothing.config/mode.tsalready 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
enabledboolean through both hooks and the target resolution — one bit at four sites, inside a component that never varies it.LivePreviewControllernow calls no hooks itself, soif (!documentPreviewActive()) return nullis legal above them, andDocumentLivePreviewholds the rest verbatim.Why the gate is not in
App.tsxinstead. 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 letsguards.test.tsxobserve 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
scopenarrows inline rather than through a closed-set helper:collectionnarrows exactly that way three lines above it, and the repo has no shared closed-set codec.9aa19ddrecords the resulting two-home coupling at the type rather than closing it, becausecollectioncarries 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 gatingapplyRequestContexton the scope. The writer-list case by adding a write toApp.tsx, on both detector arms — a property assignment and anObject.assign. Each was restored after.Reviews run. Four cleanup lenses (reuse, simplification, efficiency, altitude) — the restructure above came from two of them agreeing;
/code-reviewat high — no findings, two wording claims tightened inccbdd9d;/security-review— no findings. It confirmed one thing worth knowing: a failed token verify wipesscopetoo, becauseLIVE_PREVIEW_INACTIVEcarries the new field. The adversarial review then raised three threads, all now resolved.Fixture pre-mortem.
guards.test.tsxassumes the CMS sendsscope=sy-atlas-translationsas a query parameter on an ordinary atlas path. Verified againstSahajCloud/src/globals/SahajAtlasTranslations/SahajAtlasTranslations.ts, which composes exactly that.Docs checked, nothing stale.
docs/architecture.mdanddocs/rules/data-layer.mdboth saydraft=trueattaches during a verified session, which is still true. Nothing here is host-observable, sodocs/embedding.mdandCHANGELOG.mdare 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