Skip to content

feat(studio): hosts can seal the preview frames NLEPreview draws - #7817

Merged
miguel-heygen merged 2 commits into
mainfrom
feat/studio-preview-sandbox-origin
Nov 15, 2026
Merged

miguel-heygen merged 2 commits into
mainfrom
feat/studio-preview-sandbox-origin

Conversation

@miguel-heygen

@miguel-heygen miguel-heygen commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

What

NLEPreview takes sandboxOrigin?: "opaque" and passes it to each player it draws: the component backdrop, the live preview and the hidden shadow reload. Studio's Player takes the same prop. An opaque player:

  • sets the player's sandbox-origin attribute, so its frame runs on an opaque origin;
  • loads its preview under the project's frame-token path (/api/projects/<id>/preview/~<token>/...), where the server answers the frame's own font and script loads. The token comes from GET /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; and previewUnderFrameToken, 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.
  • The prop is read once, when the player mounts, like the player's other attributes.

Before

main: the preview frame runs on Studio's origin (sandbox="allow-scripts allow-same-origin", /api/projects/capture-demo/preview).

before

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.

after

Test plan

  • Unit tests added/updated
  • Manual testing performed
  • Documentation updated (if applicable)
  • Comments follow CONTRIBUTING.md "Comments"

On Linux, Node 24, in packages/studio:

  • New tests against 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.
  • With the prop dropped from the shadow player only, the every-player test fails.
  • 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, oxlint and 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.

@github-actions

github-actions Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 267 (base branch 267), smooth 87 of those

The gate passes.
Smoothness is reported in the artifact, not gated. A case fails only if it fails 2 of 3 runs.

Quarantined, measured but not gated (8)

Unstable (1)

  • seqplainkeys-none-px-r0-root-z100: tracking 0.06, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo false, teleport true / tracking 0.06, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo true, teleport true / tracking 0.06, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo true, teleport true

@jrusso1020 jrusso1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 15, 2026
Merged via the queue into main with commit a73ecff Nov 15, 2026
78 checks passed
@miguel-heygen
miguel-heygen deleted the feat/studio-preview-sandbox-origin branch November 15, 2026 17:32
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.

2 participants