Repository navigation
feat(studio): hosts can seal the preview frames NLEPreview draws - #7817
Conversation
Edit accuracy: accurate 267 (base branch 267), smooth 87 of thoseThe gate passes. Quarantined, measured but not gated (8)
Unstable (1)
|
…s complexity at main's
jrusso1020
left a comment
There was a problem hiding this comment.
Reviewed at 53892338af7804a7e82293092b84fe100a952b7b.
The optional seal reaches the backdrop, live and shadow players. The default remains unsealed with no token request; a failed token request still retains the opaque sandbox. The token is requested for the project parsed from the preview source, and canceled mounts discard late responses.
Nit — make tokenization idempotent (packages/studio/src/player/lib/frameToken.ts:19): a full reload starts from the current iframe URL, already tokenized, and adds a second token segment. My temporary Player test confirms the duplicate. The server currently handles nested token segments, so this is not an immediate load failure or seal bypass, but repeated reloads grow the URL and repeat server processing. In a follow-up, replace an existing token segment rather than prepend, with root/composition reload tests.
Validation: frozen install/full build; Player and NLEPreview tests 62 passed, plus the temporary reload probe failed as described. No live browser walkthrough. The documented mount-time-only setting and old-token-after-server-restart limitation remain; validation here covers the player wiring, not every preview reader.
Need: yes · Size: ok · Reuse: player sandbox attribute and frame-token endpoint · Simpler: shared token helper is appropriate · Structure: fine (checked all three player branches and reload flow; no split)
Risk: medium — optional preview isolation and source routing.
Verdict: APPROVE
Reasoning: The opt-in wiring preserves the default path and stays sealed on token failure. The reload normalization nit is a nonblocking follow-up.
— Rames
What
NLEPreviewtakessandboxOrigin?: "opaque"and passes it to each player it draws: the component backdrop, the live preview and the hidden shadow reload. Studio'sPlayertakes the same prop. An opaque player:sandbox-originattribute, so its frame runs on an opaque origin;/api/projects/<id>/preview/~<token>/...), where the server answers the frame's own font and script loads. The token comes fromGET /api/projects/<id>/frame-token, read from the preview path itself, so the shadow reload, which has no project id, gets it too.Studio feeds the same prop from
VITE_STUDIO_OPAQUE_PREVIEW_ENABLED(also read at runtime from__HF_STUDIO_ENV__). It is off by default. With the flag off and no prop, nothing changes: same path, same sandbox, and no token request.Why
A host that embeds Studio's editor needs to turn the sealed preview on for its own players, not only through Studio's build flag. The flag stays off until every Studio reader of the preview frame has its editing-port path, so people see no change before then.
Related work
Refs #7556, #7561 and #7806 (the opaque hover frame, the playback readers, and the server's grants under the token path) and #7811 (the shared editing-port client).
How
player/lib/frameToken.ts:fetchFrameToken, moved out of the compositions tab, which now uses it; andpreviewUnderFrameToken, which puts~<token>after the preview segment and keeps the rest of the path and the query.Player: the source URL is built before the player module resolves, and an opaque player waits for its token alongside the module. Without a token it still seals the frame and loads the plain path, as the hover card does.Before
main: the preview frame runs on Studio's origin (sandbox="allow-scripts allow-same-origin",/api/projects/capture-demo/preview).After
This branch with
VITE_STUDIO_OPAQUE_PREVIEW_ENABLED=1: the same preview in a sealed frame (sandbox="allow-scripts",/api/projects/capture-demo/preview/~<token>). The timeline clip's filmstrip is empty: it is one of the Studio readers that still needs its editing-port path, which is why the flag is off by default.Test plan
On Linux, Node 24, in
packages/studio:main: the 3 sealed-path cases, the no-token case and the opaque player case fail; the same-origin cases pass. With this change, all pass.vitest run src/player/components/Player.test.ts src/components/nle/ src/components/sidebar/: 25 files, 276 tests, 3 runs in a row.tsc --noEmit,oxfmt --check,oxlintand the comment ratchet are clean.Not done here: a retry after the server restarts reuses the old token and gets a 404 until the preview is reopened. Studio's own readers of the preview frame still need the frame on Studio's origin, which is why the flag is off.