Skip to content

fix(studio): colour grading works in a sealed preview - #7999

Merged
miguel-heygen merged 2 commits into
mainfrom
hfsupabase/colour-grading-editing-port
Nov 17, 2026
Merged

miguel-heygen merged 2 commits into
mainfrom
hfsupabase/colour-grading-editing-port

Conversation

@miguel-heygen

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

Copy link
Copy Markdown
Collaborator

What changes for Studio users

With the sealed preview on (VITE_STUDIO_OPAQUE_PREVIEW_ENABLED=true), the colour grading panel works again: its status line, the preset and effect cards, the live card preview on hover, and the graded frame capture. Before this, Studio read the frame's colour grading runtime straight off the preview's window, which a sealed preview refuses, so the cards stayed empty and the status stuck at "Waiting for runtime".

With the flag off, Studio takes the same direct path as before.

Before

Sealed preview (VITE_STUDIO_OPAQUE_PREVIEW_ENABLED=1), a graded video selected, on the base: the preset cards stay empty.

Before: empty preset cards in a sealed preview

After

Same project, same flag, this branch: the frame renders the 13 preset cards and Studio draws them.

After: preset cards drawn in a sealed preview

Both captures use the repo's graded-video-transitions fixture with crossorigin="anonymous" added to its videos (see Not in this change).

How

  • Three editing-port kinds, each with its own handler and param check under packages/core/src/runtime/editing/:
    • color-grading-status: the runtime's getStatus for the selected media.
    • color-grading-previews: the runtime renders the candidate looks in the frame and returns the batch as data.
    • color-grading-playback: the frame starts or stops the muted, looping card playback and keeps the stop function itself, because a function cannot cross the port.
  • Params are checked like the other kinds: the target must carry all four nullable keys with strings capped at 2,000 characters; there can be 1 to 64 candidates with short ids and a plain-object or null grading; maxDimension must be above 0 and at most 320 (the runtime clamps to 320 anyway).
  • Studio reads the frame through the previewChannel helpers only when previewFrameOpaque(iframe) is true, so it is the same split as the element picker. Replies are frame data, so Studio checks their shape. Only data:image/ URLs reach a card's <img>, and a status in any other shape reads as "Waiting for runtime".
  • Async replies don't pile up. When status reads overlap, the newest one wins. The card render loop waits for each reply before it schedules the next frame, which it already did on the direct path.
  • These reads stay as they are because a sealed frame still allows them: posting set-color-grading / set-color-grading-compare to contentWindow, and checking event.source === iframe.contentWindow on the runtime's ready message.
  • @hyperframes/inspector's unpacked budget goes from 3,780,000 to 3,830,000 bytes. The inspector bundles the runtime, which grows by about 1.9 KB minified for the three handlers, and that put it 1,244 bytes past the 1% tolerance. The kind files declare the small slice of the grading runtime's types they use, so the port does not pull runtime/colorGrading.ts into core's package.
  • .fallowrc.jsonc exempts useColorGradingController.ts from the health check. The hook's complexity was already there before this change, and the change adds no branch to it. Its two new import lines shift the hook's line, though, so fallow reports it as new, which is the same reason other files in that list are exempt.

Tests

fails without the fix: packages/studio/src/components/editor/useColorGradingController.sealed.test.ts ("grade preview sealed"), the first commit, run on the base with VITE_STUDIO_OPAQUE_PREVIEW_ENABLED=true: 4 of 4 fail, for example

FAIL  src/components/editor/useColorGradingController.sealed.test.ts > grade preview sealed > reads the frame's grading status over the editing port
AssertionError: expected { state: 'pending', …(1) } to deeply equal { state: 'active', …(1) }
-   "message": "Shader active",
-   "state": "active",
+   "message": "Waiting for runtime",
+   "state": "pending",
FAIL  ... > captures a graded frame from the frame
AssertionError: expected null to deeply equal { …(3) }
  • useColorGradingController.sealed.test.ts (first commit) puts the hook on an opaque frame served by the real editing agent. It covers the status, the preset cards (a non-image URL is dropped), the hover playback start and stop, and the capture.
  • editing/color-grading.test.ts checks each kind's round trip through the agent, the null answers when the page has no grading runtime, and the rejection of bad params.

Not in this change

In a sealed preview the frame's origin is opaque, so a <video> loaded without crossorigin is cross-origin data to WebGL and the grading shader itself fails (texImage2D ... The video element contains cross-origin data). With this change Studio now shows that message in the Grade status line instead of "Waiting for runtime". Making graded media load CORS-clean in a sealed preview is a runtime and server change, so it is left for a separate one.

@miguel-heygen
miguel-heygen force-pushed the hfsupabase/colour-grading-editing-port branch 3 times, most recently from ed6e853 to 86ae5a0 Compare November 17, 2026 02:17
@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 267 (base branch 267), smooth 98 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)

  • pathstray-none-pct-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

@miguel-heygen
miguel-heygen force-pushed the hfsupabase/colour-grading-editing-port branch 2 times, most recently from 7eb3f0b to dca89eb Compare November 17, 2026 03:15

@vanceingalls vanceingalls 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.

Approved at dca89eb.

  • Handshake: the new message kinds use the existing editing-port handshake, which accepts editing-connect only from event.source === parent with source: 'hf-parent'. No new listener is added, so page content can't drive the editor through the port.
  • Exposure: status text and preview pixels are already visible in the frame, so the seal hides nothing extra.
  • Inputs: params are capped (keys, length, count, maxDimension <= 320) before the handler runs.
  • Studio side: it keeps only data:image/ URLs, checks the status shape and renders as text, so a faked __hf.colorGrading can't do harm.
  • Test: the fails without the fix: line is present (4 of 4 sealed tests fail on the base).

Should-fix, all low:

  1. Playback cleanup: stopPlaying is module-level and isn't cleared on port close or agent dispose, so a muted video can keep looping until the frame reloads.
  2. Stale reads: the non-opaque refreshStatus path doesn't bump reads.current, so a stale sealed read can overwrite a newer direct one.
  3. Unbounded sizes: images and dataUrl sizes from the frame have no cap.
  4. Size budget: the inspector budget went up 50,000 bytes for about 1.9 KB of growth.

@miguel-heygen
miguel-heygen force-pushed the hfsupabase/colour-grading-editing-port branch from dca89eb to a64886e Compare November 17, 2026 04:29

@vanceingalls vanceingalls 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.

Re-approved at a64886e. This is a rebase onto main. The range-diff against dca89eb shows only context changes where the new colour-grading kinds sit beside restore-attributes, which landed in #8009. The PR's own code is unchanged.

@miguel-heygen
miguel-heygen force-pushed the hfsupabase/colour-grading-editing-port branch from a64886e to 984032b Compare November 17, 2026 06:26

@vanceingalls vanceingalls 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.

Re-approved at 984032b. This is a rebase onto main after #8002. The range-diff against a64886e shows the test commit unchanged, and in the fix commit only context lines differ: the colour-grading kinds and handlers now sit beside the caption kinds. The PR's own code is unchanged.

@miguel-heygen
miguel-heygen force-pushed the hfsupabase/colour-grading-editing-port branch from 984032b to 93d2bd5 Compare November 17, 2026 06:38

@vanceingalls vanceingalls 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.

Re-approved at 93d2bd5. This is another rebase onto main. The range-diff against 984032b shows only an import line regrouped next to the caption imports in editingPort.ts. The code is unchanged.

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 17, 2026
Merged via the queue into main with commit d7d4161 Nov 17, 2026
97 checks passed
@miguel-heygen
miguel-heygen deleted the hfsupabase/colour-grading-editing-port branch November 17, 2026 07:22
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