Repository navigation
feat(studio-server): an opaque preview loads its images, media and fetched files - #7806
Conversation
Edit accuracy: accurate 267 (base branch 267), smooth 110 of thoseThe gate passes. Quarantined, measured but not gated (8)
Unstable (1)
|
jrusso1020
left a comment
There was a problem hiding this comment.
Reviewed at 569ff35
The server-side increment is sound: grants remain limited to the validated project's token preview path and an opaque origin. The shared MIME table checks both requested file and response type, including revalidation. Token issuance/validation, private-file refusal and ordinary preview routes are unchanged. Tokens remain project-wide, server-instance capabilities with no time-based expiry; this change does not introduce a new token model or activate the main preview's opaque mode.
Nit — finish response-header support before the main preview flips (packages/studio-server/src/helpers/opaqueFrameLoads.ts:56–59, packages/core/src/runtime/preloadMedia.ts:137–141). Native Chrome can now read a range response's body, but Content-Range remains hidden. The runtime's size probe consequently cannot determine the total and falls back from long-source handling. Expose the required range header. Also cover the media-proxy reader's custom priority-header preflight and readable retry/progress headers before enabling that reader in an opaque frame. These are remaining rollout integrations, rather than regressions in today's same-origin preview.
Validation: frozen install/full bun run build passed. bun run --cwd packages/studio-server test src/routes/ src/helpers/safePath.test.ts --maxWorkers=1 through the shared gate passed 860 committed tests plus the native fixture, with 3 skipped; reverting this helper to its parent makes exactly 7 new grant cases fail, with 46 passing. A temporary native Chrome fixture uses the actual token/preview server, an opaque sandbox="allow-scripts" frame and real media/font files: image plus canvas readback, video/audio metadata, JSON fetch/XHR, stylesheet, font, module script and a 206 range body all succeed. It confirms Content-Range is hidden. The fixture exercises asset delivery, not the complete Studio playback/flag flow; no Safari, packaged Desktop or signed-in dev walkthrough was performed.
Need: yes · Size: ok, server preparation only · Reuse: existing MIME table, token middleware and preview routes · Simpler: already minimal · Structure: fine (checked token issuer, validator, private-file gate and response wrapper; no split)
Risk: medium — expands readable project-file responses for holders of a preview capability.
Verdict: APPROVE
Reasoning: The bounded CORS expansion preserves the existing token boundary and current preview behavior; complete the noted runtime-header integrations before the later opaque-preview rollout.
— Rames
jrusso1020
left a comment
There was a problem hiding this comment.
Reviewed at 3c8704c80dd49b80cb3ace76dfe95614f160f61c.
Re-review since 569ff353: the fetch-grant expression is named without changing its behavior, and the added test pins the main preview's tokenized base path. Token validation, response filtering and the ordinary unsealed route are unchanged by this delta. Frozen install/full build and vitest run src/routes/preview.opaqueFrameLoads.test.ts pass: 54 tests.
The earlier rollout follow-ups remain: range-response headers and media-proxy preflight/header support need integration before enabling every opaque-frame reader. I did not rerun the earlier native-browser fixture for this naming/test-only delta.
Need: yes · Size: ok · Reuse: existing token and MIME helpers · Simpler: no new mechanism · Structure: fine (delta checked against the previously reviewed helper; no split)
Risk: medium — token-scoped project response grants.
Verdict: APPROVE
Reasoning: The reviewed delta preserves the server boundary and adds coverage for the main preview path. This is preparation, not a complete switch-on validation.
— Rames
What
A preview frame on an opaque origin can now load what a composition uses from its own project, under its frame-token path (
/api/projects/<id>/preview/~<token>/...). Besides fonts and module scripts, the server now answers these withAccess-Control-Allow-Origin: null:Sec-Fetch-Dest: image, when the file and the response areimage/*;video/*andaudio/*, matched the same way;Sec-Fetch-Dest: empty, for every file the preview route serves.The main preview is served under the token path too (
/api/projects/<id>/preview/~<token>), its document re-based under the token; a test now pins it.Nothing changes for a same-origin preview, which is every preview today. Nothing in Studio loads the main preview under the token path or flips
sandbox-originyet.Why
The main preview frame can go opaque only once a composition's own loads still work there. The runtime shares the frame with the composition and fetches files itself:
captionOverrides.ts);compositionLoader.ts);colorGrading.ts);preloadMedia.ts);webAudioTransport.ts).Colour grading and WebGL also read images through
crossOrigin, and that needs the grant to keep the canvas untainted.Related work
Refs #7556, #7522 and #7561 (the opaque hover frame, the editing port, and the playback readers). This is the server half of serving the main preview under the token path.
How
getMimeType, the table the route serves with. This replaces the hand-written extension list per load type. A load is granted only when both the file's type and the response's type match. On a 304, the file's type alone decides.Origin: nullgets a grant, only under the token path, only for the project the token was minted for;Sec-Fetch-Destgets none;emptynow covers every file the preview route serves. The runtime and the composition share one frame, so the server cannot tell the runtime's own fetch from the composition's. Files the preview route already refuses (isPrivateProjectFile) stay refused.Test plan
Results (
packages/studio-server, Linux, Node 24):src/routes/preview.opaqueFrameLoads.test.ts, the new rows againstmain's helper: the 7 new grants fail; every refusal passes. With this change, all pass.<base>under the token. With the re-base removed, it fails. The file passes 54/54, 3 runs in a row.vitest run src/routes/: 38 files, 3 runs in a row. The full suite: 107 files.tsc --noEmit,oxfmt --checkandoxlintare clean on both files.Not exercised: no real browser loaded an opaque preview through these paths. Studio's main preview does not use the token path yet.