Repository navigation
Description
Summary
The embedded <sahaj-atlas> element ships the code that spends SahajCloud's live-preview credential, though no host page can ever open a session. applyRequestContext (src/config/api/client.ts:48-51) sets the token header and draft=true, and it sits in both entry graphs. #215 closed the session's writer list to boot.ts (src/Widget.standalone.test.ts:198-208), so the widget graph cannot open a session. This closes the other half: the widget graph should not carry the code that would use one.
Approach
Move the preview branch — and the header name — out of the shared graph, behind a one-slot seam.
client.tsholds the slot, not the behaviour. Addtype RequestDecorator = (url: URL, headers: Headers) => void, a module-scope slot holding one or none, andsetPreviewRequestDecorator.applyRequestContext(client.ts:33) calls it last, after auth and locale, and loses itslivePreviewandLIVE_PREVIEW_HEADERimports (client.ts:8).- A new standalone-only module holds the decorator —
src/config/live-preview/request.ts. It carries the body ofclient.ts:48-51verbatim, gate included:livePreview.active && livePreview.tokenstays inside the decorator, so the seam fails closed on its own rather than trusting where it was registered. LIVE_PREVIEW_HEADERmoves there too, out ofprotocol.ts:44. This is the part that makes the change real:protocol.tsis in both graphs on purpose, so a constant left there keeps the wire name in the embed bundle. Move the ⚠ block atprotocol.ts:38-42with it, and correct the module docblock atprotocol.ts:6-7, which still promises "header names".boot.tsregisters it, after verification — insideactivateLivePreview, on the line that flipsactive(boot.ts:150).boot.tsreaches onlymain.tsx(Widget.standalone.test.ts:145-158), andmain.tsx:119holds the render until activation settles, so no request can precede registration.
protocol.ts stays in both graphs, deliberately. App.tsx:433 and RegistrationForm.tsx:153 read the session to select restraints, and a restraint is not the credential. What leaves the embed graph is LIVE_PREVIEW_HEADER and every writer of it.
Two specs assert the credential, not one. fetch.test.ts:83-119 covers applyRequestContext directly. LivePreviewController.transport.test.tsx:158-161 covers the populate request, which reaches the same header through interceptFetch (LivePreviewController.tsx:72). Both must register the real decorator in setup. A spec that does not is asserting an absence, and stays green against a seam that never fires.
Out of scope: the per-read draft split #211 left open, and the controller gate's position, settled on #215.
Acceptance criteria
- With no decorator registered,
applyRequestContextproduces the same URL and header set it does today. -
config/live-preview/request.tsjoinsSTANDALONE_ONLY(Widget.standalone.test.ts:97), and the graph walk provesWidget.tsxcannot reach it. - No module in the widget entry's import graph contains the literal
x-sahajcloud-preview-secret, scanning comment-stripped source via that spec's ownstripComments. -
boot.tsis the only importer of the new module, asserted as a closed list likeWidget.standalone.test.ts:145-158. - A verified standalone session still sends the header and
draft=trueon every read.fetch.test.ts:83-119holds, retargeted at the seam. - The populate request still carries both.
LivePreviewController.transport.test.tsx:158-161holds, retargeted the same way. - A scoped
sy-atlas-translationssession is unchanged — it still sends both, per fix(preview): a translations session should not inert the widget it is previewing #215. -
docs/rules/data-layer.md:37-42anddocs/architecture.md:89-90describe the seam, not a branch insideapplyRequestContext.
Verification checklist
-
pnpm lint && pnpm typecheck && pnpm test:run -
pnpm build && pnpm size— record standalone / loader / embed against the budgets atscripts/check-bundle-size.mjs:115-118. Expect no meaningful byte change. Watch the under-budget arm as well as the over one. This buys a structural guarantee, not size. - Each new assertion driven red first, at the site that causes it (
docs/testing.md). For the literal scan, that site isprotocol.tsbefore the constant moves. -
grep -rn "x-sahajcloud-preview-secret" src/names only the new module and the specs. -
/admin→ Sahaj Atlas → Translations: an unpublished string still renders, proving the credential still rides the standalone read. -
/admin→ an Event → live preview: a title edit still lands on screen, proving the populate request still carries the header.
Open questions
- Should an active session with no decorator registered say so? An unregistered decorator is a silent no-op — the reviewer previews published content and sees no error. A dev-only warning in
applyRequestContextwould catch it. A throw would not, since the widget must never break a host page.
Notes
Follow-up from #215, requested at #215 (comment).
A list of decorators was the first shape, and one named slot replaces it. Only one decorator will ever exist, a list makes iteration order an implicit contract, and applyRequestContext is meant to stay the one place cross-cutting context attaches (docs/rules/data-layer.md:37-42). A named setter also keeps "who can spend this credential" a one-hit grep.
The change trades an impossible failure for a silent one. Today the branch cannot fire in a host page, because nothing there writes the session. After it, the branch is not in that graph at all — but a standalone session whose registration is dropped previews published content and says nothing. The retargeted specs and the two /admin checks stand in for the compiler here. The open question above is the same point.
Effort reads as Moderate: the code change is small, but it moves a seam two entry graphs share, needs a new graph assertion driven red, and retargets two specs and two docs.
🤖 Written by the sydevs autonomous loop — see what this is
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Hold Until
Projects
- StatusShow more project fieldsDone
Activity
sydevs-bot commentedon Sep 18, 2026
🤖 no session running
recent dispatches
Written by the sydevs dispatcher. Sessions never edit this comment.
sydevs-bot commentedon Sep 18, 2026
Revised against the code. The shape holds. Four corrections.
LIVE_PREVIEW_HEADERhas to leaveprotocol.ts:44. The body did not name it as moving, andprotocol.tsis in both graphs on purpose — so the wire name would stay in the embed bundle and the graph criterion could never pass.A second spec asserts the credential.
LivePreviewController.transport.test.tsx:158-161reaches the same header throughinterceptFetch. Onlyfetch.test.tswas named. Both must register the real decorator, or they assert an absence and stay green.One named slot, not a list of decorators. Only one will ever exist, and
applyRequestContextis meant to stay one place. Rejected alternative is in Notes.Two docs describe today's branch —
docs/rules/data-layer.md:37-42anddocs/architecture.md:89-90.Added one open question: an unregistered decorator is a silent no-op, and nothing catches it.
Effort stays Moderate. Priority is the reviewer's.
@sydevs-bot implementstarts the work.🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
Ardnived commentedon Sep 21, 2026
@sydevs-bot implement
test(preview): pin the decorator registration at boot
test(preview): close the setter's caller list in the widget graph
docs(size): name the gap the artifact scan actually covers
refactor(preview): hang the decorator off the session, not a slot in …
ci(size): drop the artifact-level scan for the preview header