Skip to content

fix(studio): a sealed preview that can't swap scenes reloads without asking first - #8544

Merged
miguel-heygen merged 2 commits into
mainfrom
fix/sealed-refresh-skips-impossible-swap
Nov 23, 2026
Merged

miguel-heygen merged 2 commits into
mainfrom
fix/sealed-refresh-skips-impossible-swap

Conversation

@miguel-heygen

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

Copy link
Copy Markdown
Collaborator

What

On a sealed preview whose film has no scene manifest, an edit that needs a full refresh now reloads at once. Before, Studio first fetched the whole preview document and asked the frame to swap scenes. The frame always refused ("the preview cannot swap scenes"), and only then did the reload start, 0.1-0.5 s late.

Why

refreshPlayer asks sceneSwapFor(iframe) whether the preview can swap, and reloads directly when it can't.

  • Unsealed, reachableSwap reads the frame's __hfSwapScenes. The runtime sets that only when the preview has a scene manifest, so a film without one gets null and reloads at once.
  • Sealed, Studio can't read the frame's window, so sealedSwap always returned a swap. Every refresh of such a film fetched the preview HTML, sent swap-scenes, and waited for the refusal.

On the edit-accuracy bench, 12 sequences at 3 parallel jobs, 3 runs per mode:

  • sealed refreshes asked for a swap 28 times and were refused every time, the refusal arriving 206 ms after the refresh at the median and 465 ms at most;
  • unsealed paid this once.

Related work

Refs #7846 (Studio's preview sealed by default). Found while measuring how long a sealed undo takes to show; #8542 makes the bench record that time.

How

  • Runtime (init.ts): one timelineMessage builder makes every timeline message the runtime posts, the first post and each later announce. It adds sceneSwap, true only when the preview has a scene manifest. That's the same value that decides whether __hfSwapScenes is installed, now read once into scenesSwappable. It's sent per load on the timeline message, not in RUNTIME_PROTOCOL_CAPABILITIES, which is the same for every document a runtime build serves.
  • Studio (sceneSwap.ts): notePreviewSceneSwap keeps each frame's latest answer, and the message router calls it on every timeline message. sealedSwap returns null only when the frame said false. An older runtime that sends no sceneSwap is still asked, so no swap a frame could do is lost.
  • The answer is kept per frame element, not per load. In the short window before a new load's first timeline message, the previous load's answer applies. A wrong "no" means one whole reload instead of a swap. A wrong "yes" means one refused swap, as before. Both show the right film.

No visible change

On a sealed preview without scenes, the film reloads a little sooner after an edit that needs it. The interface itself doesn't change.

Test plan

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

fails without the fix:

  • packages/core/src/runtime/init.swapScenes.test.ts: "says in each timeline message whether this load can swap scenes";
  • packages/studio/src/player/sceneSwap.sealed.test.ts: "asks no swap of a sealed load that said it cannot swap, so the film reloads at once";
  • packages/studio/src/player/hooks/previewMessageRouter.clipFields.test.ts: "takes each load's word on whether it can swap scenes".

"still asks a load that said it can swap, and an older runtime that said nothing" fails on main only because notePreviewSceneSwap doesn't exist there; it pins that an older runtime is still asked.

Against main's init.ts, types.ts, sceneSwap.ts and previewMessageRouter.ts, all four rows fail. With the fix, init.swapScenes.test.ts (171 tests) and sceneSwap.sealed.test.ts, sceneSwap.test.ts and previewMessageRouter.clipFields.test.ts (20 tests) pass three runs in a row on Linux.

@github-actions

github-actions Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

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

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

Verdict: APPROVE at 5976e4e7.

Need ✅ · Size ✅ (+77/−5, about half of it tests) · Reuse ✅ (one timelineMessage builder for both timeline posts; scenesSwappable is the same check that installs __hfSwapScenes) · Simpler ✅ · Structure ✅
Risk: low. A missing or stale answer only costs one reload or one refused swap, and the right film shows either way.

  • One source of truth. scenesSwappable is read once, in the same synchronous init body that later decides whether to install __hfSwapScenes. Both posts of a timeline payload (the first post and onAnnounceTimeline) now go through timelineMessage, so no timeline message leaves without sceneSwap.
  • Studio only trusts an explicit "no". notePreviewSceneSwap stores only booleans, and sealedSwap returns null only for a stored false. An older runtime that sends nothing is still asked, as before. The note happens after acceptedPreviewMessage, so only the current frame's accepted messages count.
  • Red-first holds. With main's init.ts, types.ts, sceneSwap.ts and previewMessageRouter.ts, all four named tests fail (1 in core, 3 in studio). At this head, init.swapScenes.test.ts passes 171/171 and packages/studio/src/player passes 2683/2683, both run locally.

Nit: the answer is keyed by the frame element, so it outlives a load until that load's first timeline message, which the body says. A comment at sceneSwapAnswers saying so would keep the next reader from "fixing" it per load.

— Rames (hf-review)

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 23, 2026
Merged via the queue into main with commit 35a0d81 Nov 23, 2026
101 checks passed
@miguel-heygen
miguel-heygen deleted the fix/sealed-refresh-skips-impossible-swap branch November 23, 2026 00:35
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