Skip to content

fix(studio): a sealed preview shows its loading overlay while media still loads - #8184

Merged
miguel-heygen merged 9 commits into
mainfrom
secpub/sealed-u11c
Nov 18, 2026
Merged

miguel-heygen merged 9 commits into
mainfrom
secpub/sealed-u11c

Conversation

@miguel-heygen

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

Copy link
Copy Markdown
Collaborator

What

With the preview sealed (VITE_STUDIO_OPAQUE_PREVIEW_ENABLED=true), the preview's loading overlay shows while its video, audio or Lottie still loads, as it does with the preview open. Before, a sealed preview never showed it, so pressing play on a cold video could start on a blank or stalled first frame with nothing saying why.

Why

Studio decides whether to show the overlay by reading the preview's document for media that cannot play through yet. A sealed frame refuses that read, so the check fell back to "nothing loading" every time.

How

  • previewAssetsUnloaded (core/src/lottieReadiness.ts) holds the check: a <video> or <audio> without an error, with a source, that cannot play through yet, or a Lottie still loading. Studio's open-frame check (hasUnloadedAssets) now calls it, so both frames answer the same question the same way.
  • The editing port gets one request kind, assets-unloaded, added at the end of the list. The frame's agent answers it with that same check over its own document.
  • previewStillLoading (player/components/Player.tsx) asks the open frame directly and a sealed frame over the port. The overlay poll uses it after the first check: an open frame's first check is still synchronous, and a sealed frame's first answer holds readiness back without showing the overlay. Every 100 ms tick still counts toward the 10 s cap, even while an answer is pending, and an answer that arrives after a newer load is ignored.

Test plan

  • fails without the fix: "keeps a sealed preview loading while its media still buffers" in packages/studio/src/player/components/Player.sealed.test.ts, the first commit. It runs the real editing agent behind a frame Studio cannot read. On a Linux box, with the sealed branch of previewStillLoading sent back to the direct document read main uses, both sealed tests fail: a buffering sealed preview reads as loaded (expected false to be true), and a ready one reads as still loading (expected true to be false).
  • With the fix on a Linux box: Player.sealed.test.ts and Player.test.ts pass 3 of 3 runs (38 tests). The Studio player suite (src/player) passes 211 files, 2,592 tests, and core's editing port, agent and readiness tests pass 169. Studio and core typechecks exit 0.
  • An open preview's check stays synchronous, as on main, so Studio never reports it ready while media buffers ("marks the preview booted at its first frame while media is still buffering" in Player.test.ts). A sealed preview holds readiness back until its first answer arrives, without showing the overlay for a frame that has no media.
  • Unit tests added/updated
  • Manual testing performed: CLIs built with the preview sealed (window.origin in the frame is null) at main and at this branch, opening a fixture whose audio request is held back for 20 s. Inside the frame the audio stays unloaded (readyState 0, networkState 2) on both. Both screenshots show the same loader over the first frame, and no pixel differs by more than 24 of 255: in this setup the preview's own loader already covers the media wait, so Studio's asset overlay never gets its turn. No console errors either way.
  • Comments follow CONTRIBUTING.md "Comments"

Before

No visible difference in a real sealed preview: the preview's own loader covers the media wait there (details under Manual testing). The unit tests above carry the proof.

Before: sealed preview on main, audio held back

After

The same screen on this branch.

After: the same screen on this branch

What I did not exercise

  • A unit test of the sealed readiness hold-back in the Player component, and a real setup where Studio's asset overlay shows: the unit tests cover the check itself.
  • Lottie readiness in a sealed preview: the check is shared with the open frame, but no sealed test covers a Lottie.

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 271 (base branch 271), smooth 70 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 (0)

Unstable (1)

  • seqrotatenudge-none-pct-r0-root-z100: tracking 0.03, pressJump 0, drop 0, reload 3.03, render 0.04, renderKey -, undo false, teleport true / tracking 0.03, pressJump 0, drop 0, reload 0, render 0.08, renderKey -, undo true, teleport true / tracking 0.03, pressJump 0, drop 0, reload 0, render 0.08, renderKey -, undo true, teleport true

@terencecho terencecho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

  • [P1] The first asset check can report ready during buffering. At packages/studio/src/player/components/Player.tsx:266, an editing-port client opened before iframe load can be disposed by the same load event that starts the asset check. The first request then falls back to “ready.” In Chromium, using Studio’s Player and the editing agent with a stub player element, the preconnected case reported ready with the overlay hidden while a fresh port reported buffering. Without a preconnection, the overlay appeared and readiness stayed false. Run the first check after the frame’s load-time port cleanup and cover that ordering at the Player level.
  • [P2] Include the first sealed reply in the asset wait cap. At packages/studio/src/player/components/previewAssetWait.ts:83, the ten-second timer starts after the first reply. With the first reply delayed and the next check pending, a fake-timer probe still showed the preview loading after the ten-second mark.
  • [P2] Invalidate the pending first reply on teardown. The liveness check in packages/studio/src/player/components/Player.tsx:269 only compares the load count. A Player test unmounted during the first request and observed two more polls afterward.

The workspace build, Studio and Core typechecks, 2,594 Studio player tests and 205 focused Core tests passed. Restoring the old direct read caused both sealed query regressions to fail. The CI support shard timed out in an AWS Lambda test, which also made the aggregate check fail. I did not repeat the full CLI screenshot run.

— tai (automated review)

@miguel-heygen

Copy link
Copy Markdown
Collaborator Author

Fixed in c9da5a6. All three findings came from one cause, fixed in one place, waitForPreviewAssets (previewAssetWait.ts).

  • [P1] A missing answer is asked again, never taken as ready. A sealed frame's asset check that gets no answer (its port not up yet, or replaced by the load event) leaves the preview "checking" and asks again on the next poll. Only an answer that the media can play through releases the wait. So it no longer matters whether the port connected before or after the frame's load.
  • [P2] The first answer is inside the 10 s cap. The poll starts at once and the first question is its first tick, so a slow first answer is cut off at 10 s like any other.
  • [P2] Teardown ends a pending first answer. The loop checks that its own interval is still the Player's (pollRef). Unmounting clears it, so a late reply changes nothing and no further polls run.

fails without the fix, in previewAssetWait.test.ts:

  • asks a sealed frame again when its first answer is missing, and is not ready meanwhile
  • counts a sealed frame's first answer inside the 10 s cap
  • asks nothing more once the wait is torn down during the first request

The tests drive the wait with a stand-in for the frame's answers rather than at the Player level. With the fix, the outcome no longer depends on when the port connects, so the wait itself is the place to pin it. The two sealed tests that ask the real editing agent stay in Player.sealed.test.ts.

@terencecho terencecho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The three prior findings are resolved. A missing sealed reply keeps the preview unready and retries. The first request counts against the shared window, and a late reply after teardown cannot update loading state.

  • [P2] Dispose the editing-port client with its iframe. At packages/studio/src/player/components/Player.tsx:317, cleanup clears the interval and removes the frame. The client only disposes on a future iframe load (previewChannel.ts:27). When the editing agent never connects, the client's window message listener retains the detached iframe. A Chromium fixture with a nonresponsive preview still had one listener registered 10.3 seconds after unmount. The same fixture with the base Player had none. Dispose the existing client during cleanup so each retired Player releases its listener and pending work.

All 2,597 Studio player tests, 205 focused Core tests, Studio typecheck, and eight extra timing checks passed. The three new wait tests failed with the previous implementation and passed at this head. The Chromium preconnected-port fixture now kept readiness false while the media buffered. Full screenshot comparison and sealed Lottie browser validation were outside this pass.

— tai (automated review)

@miguel-heygen

Copy link
Copy Markdown
Collaborator Author

Fixed in 53fa69d.

[P2] A closed preview frees its editing-port client. Each frame's client now has one retire step, retire, inside previewEditingClient (previewChannel.ts). That step drops its load listener, disposes the client and forgets it. Both the frame's next load and the new retirePreviewEditingClient(iframe) use it. The Player's cleanup calls it next to clearing the asset poll (Player.tsx). Every preview frame, live or shadow, is a Player (NLEPreview.tsx), so a shadow that is thrown away is freed the same way.

fails without the fix: disposes the frame's editing-port client when it unmounts (Player.test.ts). It mounts a Player, opens a client for its frame as the sealed path does, and unmounts. On the previous code the client's request is still pending after unmount; with the fix it is refused as disposed.

@terencecho terencecho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The teardown finding is resolved. Player cleanup now retires the iframe's editing-port client and removes its load listener. The Chromium fixture with an unresponsive preview dropped from one window message listener to zero after unmount. A separate reload check showed the retired client's pending request was rejected and the replacement client stayed usable. The preconnected preview still showed the loading overlay while media buffered.

The Player teardown regression failed without the retirement call and passed at this head. All 59 focused Studio tests, Studio typecheck, and lint and formatting checks for the changed files passed. Preview parity passed in CI. The full CLI screenshot comparison was outside this pass.

— tai (automated review)

@miguel-heygen

Copy link
Copy Markdown
Collaborator Author

Rebased on main at 5ef4be8: what changed since e0a2f45

git range-diff e0a2f458~9..e0a2f458 origin/main..5ef4be81: 8 of the 9 commits are identical (=). The only changed commit is "a sealed preview's loading overlay waits for its media through the editing port". #8158 added the soft-reload request to the same four lists this PR adds assets-unloaded to, so both entries are kept, soft-reload first:

  • packages/core/src/runtime/editingPort.ts: EDITING_REQUEST_KINDS, EditingRequests and the param parsers
  • packages/core/src/runtime/editingAgent.ts: the import and the handler
  • packages/core/src/runtime/editingPort.test.ts and editingAgent.test.ts: the expected kind lists

No other line differs from the approved head. CI at 5ef4be8: 89 pass, 11 skipped.

@terencecho terencecho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The rebase preserves the approved patch. Eight commits match exactly, and the remaining commit adds the same asset-readiness request alongside the soft-reload request now on main. Each request keeps its own type, validator, and handler. Both returned the expected reply when sent concurrently on one editing port.

The workspace rebuild, 224 focused Core tests, 130 focused Studio tests, lint, and formatting checks passed. CI reported 89 successful checks and 11 skipped. The full CLI screenshot comparison was outside this pass.

— tai (automated review)

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 18, 2026
Merged via the queue into main with commit 81f89b8 Nov 18, 2026
100 checks passed
@miguel-heygen
miguel-heygen deleted the secpub/sealed-u11c branch November 18, 2026 23:29
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