Repository navigation
feat(studio): playback and timeline reads go over the preview's message channel - #7561
Merged
Merged
Conversation
Contributor
jrusso1020
force-pushed
the
feat/studio-playback-over-bridge
branch
from
November 11, 2026 23:33
cc4741d to
3a44017
Compare
Contributor
There was a problem hiding this comment.
Verdict: REQUEST CHANGES · 1 blocker · 1 important · 0 nits · head 3a440172
- important: the UX-parity run only covers frames Studio can script. The dev server's preview is same-origin, so it never reaches the bridge adapter or the port reads. The opaque path is tested only in jsdom, with a harness that never closes ports, which is how the blocker below got past it. Please add a parity run with an opaque preview, e.g.
sandboxwithoutallow-same-origin.
Scope
- Read all 12 files. Required CI is green on this head.
- The CodeQL origin alert at
bridgePlayback.ts:40is a false positive: the mirror is keyed byevent.source, so a window can only write its own entry. - Not posted (medium confidence): a retry reload reuses the same iframe (
Player.tsx:238). The mirror is keyed by window and survives that reload, soinitializeAdaptercan take the fast path with the old document's duration before the new runtime is listening.
— Genesis
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Nov 12, 2026
…ng port A parent that disposes its editing client and creates a new one for the same frame (a remount that keeps the iframe) used to wait forever: the runtime handed its port over once per page load. Each valid connect from the parent now closes the previous port and hands over a new one. Connects from any other sender are still ignored. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ge channel Prepares Studio's preview to run on an opaque origin, where the parent cannot read the frame's window. - previewChannel: one editing-port client per frame load, plus the loop start, seek-painted and clip-manifest reads over it. - bridgePlayback: a playback adapter that sends play, pause and seek as control-bridge messages and mirrors the runtime's state and timeline posts. It is used only for a frame Studio cannot script; a same-origin frame keeps the direct adapter. - The loop start and the state-tick manifest recovery now always use the editing port. The shadow reload's seek-painted wait uses it for a frame Studio cannot script. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…hare Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… Studio can script A host can pair this Studio with a runtime older than the editing port. The loop start and the state-tick manifest recovery now read a same-origin frame directly, exactly as before; only a frame Studio cannot script uses the port. previewFrameOpaque replaces previewFrameScriptable and treats a frame with no window as not opaque, so a detached frame keeps its old no-op path too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… on an opaque preview The runtime posts ready before it installs its editing agent, so a client can connect twice and receive two ports. Closing the earlier port on each connect left a client that took the first one with a dead channel for the rest of the frame load. The agent now keeps earlier ports open (a disposed client closes its own end) and closes all of them on teardown. For an opaque preview: - the restore-seek wait gives up after a 1 s probe when no editing port arrives, so a runtime without the agent no longer holds a reload for 15 s; - the bridge playback mirror keeps a seek until the runtime confirms it, so a state posted before the seek cannot undo a quick frame step; - sceneSwapFor returns no swap instead of reading the frame's window, so a reload falls back to a full reload. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
previewFrameOpaque treated any frame whose contentDocument was null as opaque. A same-origin window can still report a null contentDocument (an iframe that is not in the document), and that sent it down the opaque path. A frame is opaque now only when reading its window's document throws, as it does across origins. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t frame precision The bridge playback mirror took a state or timeline post from any window and made a mirror for it. It now takes a post only from a frame Player registered (watchPreviewFrame, called before the frame loads, so the boot-time timeline is not missed), and only when the post's origin is one that frame can have: null for an opaque sandbox or a data: URL, the parent's origin for srcdoc, about: or no src, else the origin of its src. A pending seek now counts as confirmed by the frame the runtime lands it on, the frame at or before it, rather than by a 1 ms match. An off-grid seek used to drop every state post for 500 ms, freezing the playhead and its play state. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… the document Main's test harness now attaches its fake iframe, and happy-dom then fires that frame's about:blank load on its own, which ends the editing client's frame load mid-test. These tests build their own detached frame instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jrusso1020
force-pushed
the
feat/studio-playback-over-bridge
branch
from
November 12, 2026 09:02
c8f421e to
3d69078
Compare
Contributor
There was a problem hiding this comment.
Verdict: REQUEST CHANGES · 1 blocker · 0 important · 0 nits · c8f421e → 3d69078
The rebased patch is byte-identical to the approved one apart from a hunk offset, and detachedFakeIframe is correct. However, the required Tests on windows-latest check (studio-1) is red on this head because a sibling test hits the same attached-iframe race. ↓ inline
— Genesis
…test The manifest router test had the same race: the attached harness frame's own about:blank load ended the editing client before the port answered, which lost on the slower Windows runner. The harness now exports detachedFakeIframe, which makeFakeIframe builds on, and both opaque-frame test files use it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 12, 2026
Merged
Merged
3 of 5 tasks
Merged
6 of 7 tasks
This was referenced Nov 15, 2026
This was referenced Nov 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Prepares Studio's preview to run on an opaque origin, where Studio cannot read the frame's
window. This is the first slice of moving Studio's playback and timeline readers onto the runtime's message channel (#7556). It also fixes the one-port-per-page-load limit in that channel.Same-origin paths are unchanged. Every preview today is same-origin, and Studio still reads those frames directly, exactly as on
main, so pairing this Studio with any runtime version changes nothing a user sees. Some hosts can pair it with a runtime older than #7556, which has no editing port. The port and the control bridge are used only for an opaque frame, one whose document Studio cannot read. Nothing flipssandbox-origin.What
Fresh port on a later connect (
packages/core/src/runtime/editingAgent.ts). The agent handed its port over once per page load. A parent that disposed its client and made a new one for the same frame got no port, so every request timed out. This happens on a React StrictMode remount, or a remount that keeps the iframe. Now each valid connect fromwindow.parentgets a fresh port. Earlier ports stay open, because the runtime postsreadybefore it installs the agent, so a client can connect twice and take either port. A disposed client closes its own end, and the agent closes every port on teardown. A connect from any other sender is still ignored.player/lib/previewChannel.ts(new).loaddisposes it, and the next call opens a client for the new runtime.previewFrameOpaque(iframe): true only when reading the frame'swindow.documentthrows, as it does across origins. A same-origin window always counts as scriptable, even one that reports a nullcontentDocument. A frame with no window is not opaque, so it keeps its old no-op path.setFrameLoopStart: on a non-opaque frame, calls the runtime's__hf.setLoopStartdirectly, as before. On an opaque frame, it sends the loop start over the port, only when the value changes.AGENT_PROBE_MS). A runtime without the editing agent never sends one, so a reload is not held for the full 15 s budget.player/lib/bridgePlayback.ts(new). For opaque frames only: aPlaybackAdapterthat sendsplay,pauseandseekas control-bridge messages (bridge.ts). It takes time, play state and duration from thestateandtimelinemessages that frame's runtime posts. It keeps a seek until astateconfirms it, with a 500 ms limit, so astateposted before the runtime handled the seek cannot move the playhead back between quick frame steps. The confirming frame is the one the runtime lands the seek on: the frame at or before the target, using the post's fps, or within half a frame at 1 fps when a post carries no fps.It takes posts only from a frame
Playerregistered withwatchPreviewFrame(called before the frame loads, so the boot-timetimelineis not missed), and only from an origin that frame can have. That isnullfor an opaque sandbox or adata:URL, the parent's origin forsrcdoc,about:or nosrc, and otherwise the origin of itssrc. A post from any other window or origin is dropped, never stored.Readers moved:
Each reader keeps its direct path for a same-origin frame and gets a port or bridge path for an opaque one:
useTimelinePlayersetLoopStart, throughsetFrameLoopStart.previewMessageRouter: the state-tick manifest recovery. An opaque frame is asked over the port, one request at a time.playbackAdapterResolution: the newresolveFramePlaybackAdapter. A non-opaque frame gets the same direct adapteruseTimelinePlayer.getAdapterbuilt before.useShadowPreviewReload: the restore-seek wait.sceneSwapsceneSwapFor: an opaque frame gets no in-place scene swap, so a reload falls back to a full shadow reload. On a same-origin frame it reads__hfSwapScenesas before.Why
Before the main preview frame can go opaque, every Studio reader that reaches into the frame has to move onto a message channel. This PR covers the playback transport and the runtime-state reads in the playback and timeline hooks.
Related work
Refs #7556 (the runtime's editing port) and #7522 (the hover preview frame is opaque).
How
Claude Opus 5.5
Port vs bridge. Play, pause and seek go over the existing control bridge, as
<hyperframes-player>already does for an opaque frame. Reads that have no bridge message go over the editing port: loop start, seek painted, and the manifest.Why same-origin keeps the direct adapter. The direct adapter answers
getTime()synchronously, every animation frame. It also wraps a document that runs longer than its adapter (static seek), and it falls back to__timelineswhen a composition has no__player. The bridge adapter can only report the laststatethe runtime posted, and the bridge'sseektakes nokeepPlayingorsettledoption. Using it for same-origin previews would change playback timing for every user today. So the bridge adapter is used only when the frame cannot be scripted, and the switch happens when the frame goes opaque.Port only for opaque frames. A host can pair this Studio with a runtime older than #7556, which has no editing agent. A port-first read would never get an answer there. For the loop start, that means the runtime's own loop wrap would not know where to land. So every reader, not only the playback adapter, keeps the direct same-origin path from
main, and the unchangedmaintest for the loop start (useTimelinePlayer.seek.test.ts) still passes. The port gets real traffic once the frame goes opaque.Per frame load.
load. With the agent fix above, a client created after a dispose still gets a port.timelinewhile it boots, before the frame'sload. A listener added later would never see the duration.Replies are frame data.
clipsarray and a finitedurationInFrames.Same-origin direct paths kept on purpose. These are
main's reads, now behindpreviewFrameOpaque, and they go away when the frame flips (paths underpackages/studio/src/player/):lib/previewChannel.ts:35(setFrameLoopStart)hooks/previewMessageRouter.ts:114hooks/playbackAdapterResolution.ts:45,64,109hooks/useShadowPreviewReload.ts:40Deferred. These direct reads remain and have no opaque path yet, because the runtime cannot supply the data or because this PR keeps to its size. On a same-origin frame they behave as before:
hooks/timelineSyncHydration.ts:202(safeContentDocument),:446(__clipManifestinhydrateTimelineFromPreview), and the DOM normalisation and DOM-parse fallbacks there. These need a runtime snapshot of the DOM rows.hooks/useTimelineSyncCallbacks.ts:184(__clipTreeparent map; the port already answersclipParents) and:221-222(enrichMissingCompositions).hooks/previewMessageRouter.ts:155: the DOM-parse fallback when atimelinemessage produced no rows.hooks/useTimelinePlayer.ts:183(__timelinestimeScaleinapplyPlaybackRate) and:502(gesture check before a scene swap).hooks/usePlaybackKeyboard.ts:205-206: keyboard listeners inside the frame. These need the runtime to forward keys.sceneSwap.ts:58,118: the stale-scene meta write, and the in-place swap (__hfSwapScenes), which an opaque frame skips for a full reload. The swap needs a port request with cancel.hooks/useShadowPreviewReload.ts:46,53-55,168,191: the reload-failure diagnostics and the live gesture checks.seekgainingkeepPlaying/settled, so that a loop wrap over the bridge does not pause and resume.timeline, the adapter can report the old document's duration.Before
After
Both are real Chrome 153 runs. The composition and runtime sit in a
sandbox="allow-scripts"frame, driven by this PR's Studio modules bundled for the browser. For Before, the runtime was built frommainand the adapter lookup ismain'sresolvePlaybackAdapterpath.Test plan
Unit tests added/updated:
editingAgent.test.ts: each later connect from the parent gets a fresh port and the earlier port keeps answering; dispose closes every port handed over; another frame's connect after the handoff leaves the parent's port alone.editingPort.test.ts, with the real agent and the real client: queued deliveries in three orders (readybefore either port,readybetween the two connects, the first port beforeready). Each ends with a working port. The first two orders fail with an agent that closes the previous port on each connect.editingPort.test.ts: a new client for the same frame is served after the first is disposed.previewChannel.test.ts, bridge adapter, two cases that fail onc7b73fd4and pass now:seek(4.01), the runtime's 30 fps post of 4.0 (still playing) is taken at once.previewChannel.test.ts, origins: registered frames loadingsrcdoc,about:blank, adata:URL or another origin are accepted only from their own origin.previewChannel.test.ts, 8 tests: which frames count as opaque (including one with no window); one client per frame load; on a same-origin frame, the loop start goes to the runtime's own hook with no port, and on an opaque frame it goes over the port only on change; the seek-painted wait; manifest shape checks; the bridge adapter's control messages on a frame whose window throws on any read; state and timeline mirrored from that frame only.previewMessageRouter.manifest.test.ts: a same-origin frame's manifest is read straight off it, at once, with no port. An opaque frame's comes from the port, one request at a time.useTimelinePlayer.seek.test.tsis identical tomain, and its loop-start test still passes.Mutation probes for this revision: going back to the
contentDocument === nulltest for opaque failspreviewChannel.test.tsand the existinguseDomEditPreviewSync.test.ts, whose fake same-origin frame has nocontentDocument. In addition: the agent from the previous head (closing the earlier port) and the agent frommain(one handoff per load) each fail the new agent and port tests; removing the 1 s agent probe, the seek confirmation, or the opaque guard insceneSwapForeach fails its test.Mutation probes, earlier revisions. Each change below was reverted on its own, and the named test failed: the agent's close-and-rehand (and, separately, restoring its once-only handoff), the per-load client reset, the loop-start dedupe, the manifest shape check, the bridge branch in
resolveFramePlaybackAdapter, the mirror's time guard, and the router's one-at-a-time guard. For both the loop start and the router, forcing the port path for every frame fails the same-origin test (for the loop start,main's seek test as well), and forcing the direct path fails the opaque test. Treating a windowless frame as opaque also fails a test.Studio
src/playerplus the 6 other test files that mount the player: the full Studio suite, 745 files and 8,496 tests, passed. CoreeditingAgent,editingPortandbridge: 70 passed.tsc --noEmit(studio), oxlint, oxfmt, fallow, the comment ratchet and citation checks,check:package-cycles,check:package-subpathsandcheck:studio-copy-dashesall passed.Manual testing performed: the real-Chrome run above.
Same-origin UX parity in a real Studio session. The Studio dev server ran the
studio-openfixture (12 scenes, 60 s) in headless Chrome 153, with the same scripted journey on three setups:ef5cdeb0;Results came from the runtime's own
stateposts and Studio's buttons, and the three runs matched:Opaque-preview parity in a real Studio session. The same journey ran on this head with every
<hyperframes-player>Studio created set tosandbox-origin="opaque", a scratch patch applied in the page and not committed. The frame'ssandboxwasallow-scriptsand itscontentDocumentread asnull, so the bridge adapter and the port reads ran. Compared with the same-origin run on the same head:<hyperframes-player>cannot scan assets and waits for the runtime'sassets-ready, and the hidden reload frame posted that after about 8.3 s (0.3 s same-origin). The previous preview stays on screen meanwhile. This has to be fixed before any preview is switched to opaque.__hfSwapScenes. Quick frame steps lost a step (20 of 30 frames) to a stalestatepost.Not exercised: the Desktop app's browser view. Desktop picks this up only on its next
@hyperframespin bump, and parity gets checked there.Comments follow CONTRIBUTING.md "Comments".
— Rames Jusso
🤖 Generated with Claude Code