Skip to content

feat(core): sealed previews can run Delete and arrow nudges in-frame once Studio arms them - #8946

Merged
miguel-heygen merged 3 commits into
mainfrom
feat/sealed-runtime-keys-core
Nov 27, 2026
Merged

miguel-heygen merged 3 commits into
mainfrom
feat/sealed-runtime-keys-core

Conversation

@miguel-heygen

Copy link
Copy Markdown
Collaborator

What

Core half of #8935: the preview runtime can run canvas Delete and arrow-key nudges inside a sealed (opaque-origin) preview frame, and forward Studio's shortcuts back to it. All of it is gated on Studio sending arm-canvas-keys over the editing port. Studio does not send it until #8935 lands, so this PR changes nothing users see.

Why

In a sealed preview, Delete and nudge round-trip from Studio's window over the MessagePort before the first frame paints, which adds visible lag in Firefox and WebKit. Running them in-frame removes that round trip. #8935 was about 2,000 changed lines; this splits it at the core/studio seam so each half can be reviewed on its own.

Related work

Refs #8935 (the Studio half, stacked on this branch).

How

  • runtime/editing/canvasKeys.ts: a capture-first key shield plus armed actions. Once armed, a trusted Delete removes the armed elements in the same frame and posts a canvas-key-action that Studio commits or rolls back (resolve-canvas-key-action). Arrow combos draw the nudge in-frame and post cumulative steps. Other trusted keys are kept from the composition and forwarded to Studio. Inline text being edited, render, capture and export pages, and same-origin previews are never shielded.
  • editingPort.ts / editingAgent.ts: the two new request kinds, with their params parsed at the port boundary. The agent's dispose also resets canvas-key state.
  • domRealm.ts: isDomNode, so node checks work across realms (instanceof Node is banned in runtime code).
  • Reuse over copies: removeElements.ts exports its removable-node and outermost-element checks, editingGestureStart.ts exports gsapPosition, and textEdit.ts adds isActiveTextEditTarget, so the in-frame Delete, nudge and text carve-out run the same code as the port paths. generated/position-edits-render-inline.ts is rebuilt output.
  • Not in this PR: the load-time installPreviewKeyShield() call in entry.ts. With it, the shield would stop the editing agent's existing key-watch forwarding before Studio arms anything. It ships with feat(studio): handle canvas Delete and arrow-key nudge in opaque preview runtime #8935, so this PR stays inert until then.

Test plan

  • Unit tests added/updated: canvasKeys.test.ts (shield, untrusted keys ignored, film-owned inputs blocked, same-origin and render pages never shielded, Delete commit/rollback, nudge steps), plus editingPort.test.ts and editingAgent.test.ts for the new kinds.
  • fails without the fix: canvasKeys.test.ts > "blocks film listeners, ignores untrusted keys, and removes armed targets in the same frame" fails when the shield's stop call is removed from onShieldEvent, and passes with it.
  • Core runtime and editing suites: 34 files, 648 tests, 3 consecutive runs, exit 0. test:hyperframe-runtime-ci exit 0. tsc --noEmit clean.
  • Inert check: main's Studio sealed-preview, hotkey and preview-channel suites run against this core: 55 files, 471 tests, exit 0.
  • Comments follow CONTRIBUTING.md "Comments".

@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

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

…s first draw

Studio's first nudge on a cold read now uses this start, so a GSAP clip is not moved twice.

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

Reviewed at fe32890. Approving: no blocker.

Read whole: runtime/editing/canvasKeys.ts and canvasKeys.test.ts. Read as hunks: editingPort.ts, editingAgent.ts (plus its key-watch section whole), removeElements.ts, textEdit.ts, domRealm.ts, editingGestureStart.ts and the two test list updates. The regenerated generated/position-edits-render-inline.ts was not read. Nothing was run.

This is a feature, so the "fails without the fix:" rule does not strictly apply; the line is there anyway and names a real test.

What I checked:

  • Inert claim: nothing calls installPreviewKeyShield at load, and the only other caller is armCanvasKeys, reachable only through the new port request. With no Studio sending it, no listener is added.
  • Both new requests parse at the port boundary with exact key sets, handle and combo caps and bounded steps; the event back to Studio is validated the same way.
  • Only trusted events act; a dispatched Delete does nothing. An active text edit is left alone.
  • Delete keeps what it removed until Studio answers, and rollback puts each node back at its old place (test 3 pins order).
  • The agent's dispose clears armed state, pending deletes and the listeners.

Notes for the Studio half, none blocking here:

  1. armCanvasKeys installs the shield with allowSameOrigin = true, and tests 2 to 4 rely on that. So "same-origin previews are never shielded" holds for the load-time path only (the last test covers just that path). If Studio ever arms a same-origin preview, typing into the film's own editable elements stops. Either Studio must never arm there, or the arm path should keep the origin check.
  2. When the shield is added at arm time, the agent's existing key watch may already be listening on window in capture and runs first. A watched combo is then forwarded by the watch and handled again by the shield (a second forward, or a local Delete on top of the forwarded one). The load-time install avoids it, but after a dispose and re-arm the order can flip.
  3. Arming with nothing to do clears armed but leaves the shield on: trusted keys are then stopped for the film and forwarded to nobody until the next arm.
  4. In-frame Delete uses isRemovableNode, which is looser than the port path's removableClip (no clip selector check). Studio's commit or rollback is the backstop.
  5. A Delete whose armed handles are all stale is swallowed with no event, so Studio does not hear about that key press.
  6. armCanvasKeys answers armed: true even when the shield declined to install.

Need: yes, removes a round trip per key · Size: +1063/-11, 590 in one new file · Reuse: remove, GSAP position and text-edit checks are shared, not copied · Simpler: no · Structure: fine
Risk: low while unarmed; notes 1 and 2 decide how it behaves once armed.

— Rames

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 27, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Nov 27, 2026
Keeps both the canvas-key and stage-act request kinds and push listeners.
The editing port's push handling becomes a table so both fit under the complexity gate.

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

Reviewed at e83c3e0. Approving: no blocker. This is a re-review after the merge of main; my earlier approval was at fe32890.

What changed since fe32890

  • The PR's own diff against main is the same as before except in editingPort.ts. I compared the two diffs line by line.
  • The merge keeps both sets of request kinds, param parsers, handlers and listeners (the canvas-key ones from this branch, the stage-act ones from main). The agent's dispose runs both resets.
  • onPush became a table of routes. It tries the same parsers in the same order and stops at the first match, so each push still reaches one listener set. The canvas-key route sits before the two stage routes, and their event shapes do not overlap.
  • The two kind-list tests carry both new sets in the same order as EDITING_REQUEST_KINDS.

My earlier non-blocking notes still stand unchanged.

Read: the merge commit's combined diff whole, and the old and new PR diffs compared. Files outside the merge's conflict set were not re-read. Nothing was run.

Need: yes · Size: merge only since last review · Reuse: one pushRoute helper for all seven routes · Simpler: no · Structure: fine
Risk: low; still inert until the editor arms it.

— Rames

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 27, 2026
Merged via the queue into main with commit 79a4ee0 Nov 27, 2026
105 checks passed
@miguel-heygen
miguel-heygen deleted the feat/sealed-runtime-keys-core branch November 27, 2026 03:01
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