Skip to content

feat(core): paint a sealed preview's drag chrome in the same frame as the layer - #8961

Open
miguel-heygen wants to merge 5 commits into
mainfrom
fix/sealed-drag-chrome-in-frame
Open

miguel-heygen wants to merge 5 commits into
mainfrom
fix/sealed-drag-chrome-in-frame

Conversation

@miguel-heygen

Copy link
Copy Markdown
Collaborator

What

A sealed preview can now paint Studio's selection chrome itself, in the same turn as the gesture draft that moves the layer. Studio sends a copy of its own chrome (structured data, never markup) with a drag's first draft, then only each node's placement with every later draft. The frame builds the copy in a closed shadow root on one marked host under <html>, and removes the host when the drag ends.

Nothing sends chrome yet: Studio's half follows in a separate PR. Until then this path is inert.

Why

In stock Chrome a sealed preview renders out of process, so Studio's outline and the dragged layer are two compositor surfaces that Viz shows independently. Even with Studio writing its outline in the move event (0 frames late), the frame's surface for step N+1 is shown with Studio's surface for step N. On the 4x CPU bench, outline minus layer sits at +0.68 to +1.09 steps per drag on a sealed preview and 0.00 on an open one. Only a chrome the frame paints itself can share the layer's compositor frame.

Related work

Refs the selection-chrome lag work in #8909, #8919, #8921, #8931 and the raw-step drafts in #8912.

How

  • runtime/editing/dragChrome.ts (new): parseDragChrome checks the copy, and drawDragChrome mounts, places or clears it. The copy may only use div, span, svg and path, SVG geometry attributes, and style maps whose names are CSS properties. A value that would make the frame fetch (url(, image(, image-set(, src() is refused. Caps: 64 nodes, depth 6, 32 KB of nodes, 48 properties per map, 512 characters per value. An over-cap copy fails the request's validation.
  • The host is <div data-hf-ignore data-hyperframes-ignore data-hyperframes-picker-ignore data-layout-ignore aria-hidden>, marked like the paused-frame canvas (pausedVideoFrames.ts markFrameCanvas), with all:initial; position:fixed; inset:0; pointer-events:none. Every chrome node is forced to pointer-events: none !important. The copy maps overlay px to frame px with one transform: scale(1/s) translate(-origin).
  • runtime/editingPort.ts: the draft request takes an optional chrome (null clears it). A request that carries chrome may name no draft.
  • runtime/editingDraft.ts: drawDrafts(drafts, chrome) draws the chrome after the drafts in the same call. When no chrome comes and the last live draft ends, the chrome is cleared, so a cancel can never leave it behind. editingAgent.ts also clears it when the agent is disposed.
  • Per-step placement writes happen inside the shadow root, so the document's MutationObservers see only the host's one add and one remove per drag.

Every frame-side reader of the document, checked against the host:

Reader Why it never carries the chrome
editing/documentMarkup.ts (documentElement.outerHTML) runs with the host taken out (withoutDragChrome), and put back in the same turn
editingHandles.ts queryElements, readEveryMatch (document.querySelectorAll) skip the host
editingAgent.ts computed-styles and editing/motionPathHome.ts (document.querySelector) Studio's stable selectors name composition elements; the host has no id or class and sits after <body>
editingLayers.ts:102, editingGestureStart.ts:238 walk the composition root, not <html>
editing/maxZIndex.ts, editing/stageMeasure.ts walk document.body
sceneWindow.ts (host.outerHTML of scene hosts) scene hosts live inside <body>
picker.ts skips [data-hf-ignore]
elements-at-point, pointer-targets (elementsFromPoint) host and nodes are pointer-events: none
MutationObservers on <html> (init.ts, preloadMedia.ts, sealedMediaCors.ts, previewRasterHints.ts, frameSources.ts, staticCompositionPost.ts, editing/stageAct.ts) selector-based filters; per-step writes are inside the shadow root
editing/textEdit.ts removal observer only checks that the edited element is still connected

Every Studio reader of a sealed frame's document goes through document-markup (previewChannel.ts previewDocumentMarkup / previewDocumentCopy): the property panel, clipboard, GSAP reads (gsapShared.ts), timing patches, audio-group volume, automation sync, the timeline header and sync callbacks, and first-frame telemetry. All of them get the stripped markup.

Renders: chrome only arrives over the editing port, and the port is only handed to a parent that connects to a page marked for Studio (editingAgent.ts installEditingAgent). A render page is its own top window and carries no Studio mark.

Test plan

Proof: 4x bench pending. The bench run (outline minus layer per drag, sealed and open, at 4x CPU) lands with the Studio PR's numbers.

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

fails without the fix:

  • editing/dragChrome.test.ts "is drawn in the same call as the draft it rides, at the step's place, mapped into frame px" fails with the drawDragChrome call removed from drawDrafts.
  • "goes with a null chrome, and with the last draft's end when Studio sends none" fails with the last-draft clear removed.
  • "is in no document markup or query a drag answers" fails with withoutDragChrome removed from documentMarkup, and again with the query skip removed (expected [ …(2) ] to have a length of 1 but got 2).
  • "refuses a copy over the node or byte caps, and anything but paint" fails with the node cap, the byte cap or the fetch check removed, one at a time.
  • The pointer-events override and the chrome-only request each fail their assertion when removed.
  • producer/src/services/coreRuntimeBrowser.test.ts "hands a render page no editing port, so it never paints drag chrome" (real Chrome, built runtime) fails with the agent's top-window and Studio-mark checks removed (expected [ 'editing-connect', …(2) ] to not include 'editing-port').

Three runs of the touched core files (dragChrome, editingDraft, editingDraftRestore, editingPort, editingAgent, editingHandles, gsapSet, patchTween): 281/281 each. Full packages/core/src/runtime: 3860/3860 on current main. coreRuntimeBrowser.test.ts: 94/94. tsc --noEmit, oxlint, oxfmt, fallow clean.

@github-actions

github-actions Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 273 (base branch 271), smooth 73 of those

The gate passes.
Smoothness is reported in the artifact, not gated. A case fails only if it fails 2 of 3 runs.

Newly passing (2)

  • seqscaletwice-scale-px-r0-nested-z100
  • seqscaletwice-scale-px-r0-root-z100

Not banked yet, reported and not gated (bank a full-grid run's baseline.json) (2)

  • seqscaletwice-scale-px-r0-nested-z100
  • seqscaletwice-scale-px-r0-root-z100

Quarantined, measured but not gated (0)

Unstable (1)

  • seqplainkeys-none-center-r0-root-z100: 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 / tracking 0.06, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo true, teleport true

@miguel-heygen

Copy link
Copy Markdown
Collaborator Author

Correction to the test plan, as of dfd905d0:

  • The render-page check moved to its own file, producer/src/services/renderPageEditingPort.test.ts ("hands out no editing port, so it never paints drag chrome"). It now waits on two marker messages instead of a fixed 50 ms. With the agent's top-window and Studio-mark checks removed, it fails with expected [ 'editing-connect', …(3) ] to not include 'editing-port'. It passed 3 runs in a row.
  • Why the move: the flake gate re-runs a touched test file 10 times under CPU load, 120 s per run. coreRuntimeBrowser.test.ts timed out on all 10 runs, so this PR leaves that file untouched.
  • Also at 48e633be: two doc comments trimmed to one line each, for the comment-share check.

@miguel-heygen

Copy link
Copy Markdown
Collaborator Author

Two additions to the description, as of e7149ed4:

  • A film's own observers see the host. During a sealed drag, the host is a child of <html>, so a film's own MutationObserver on the document gets one add when the drag starts and one remove at release. Per-step placement writes stay inside the closed shadow root and never reach it. An open preview adds nothing. The host is removed at release, on cancel, when the last draft ends, and when the agent is disposed.
  • CSS escapes are refused. style.setProperty decodes CSS escapes, so u\72l(...) or \75rl(...) would become a url() and make the frame fetch. A chrome value may not contain a backslash; computed paint values never need one. dragChrome.test.ts "refuses a copy over the node or byte caps, and anything but paint" now covers both escape forms. It fails without the check (expected true to be false) and passed 3 runs in a row.

This branch has not been deployed

No deployments
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