Skip to content

feat(core): stand a removed element back as a ghost in a sealed preview - #8956

Merged
miguel-heygen merged 5 commits into
mainfrom
feat/stage-act-ghost
Nov 27, 2026
Merged

miguel-heygen merged 5 commits into
mainfrom
feat/stage-act-ghost

Conversation

@miguel-heygen

Copy link
Copy Markdown
Collaborator

Stacked on #8950 (base feat/stage-act-port).

What changed

When an edit removes an element, the open preview stands it back for a moment and flicks it away: the host imports the old element from the document it left. A sealed (opaque-origin) preview's old document is closed to the host, so this PR relays the element's markup instead, for the host to request before the replacing frame is promoted.

  • capture op on stage-act (packages/core/src/runtime/editing/stageGhost.ts): the frame being replaced writes out each asked element's subtree, with its computed look on the root (the same 14 properties the open path copies) and without its id or data-hf-id. A subtree over MAX_STAGE_GHOST_MARKUP = 65_536 characters is left out. Each call takes at most MAX_STAGE_ACTS targets.
  • Ghost hold in stageAct.ts: the replacing frame parses the markup inert (DOMParser) and strips script, iframe, object, embed, frame, frameset, base, meta and link elements, every on* attribute, srcdoc, and any attribute whose value, with spaces and control characters removed, contains javascript: or data:text/html. It refuses markup that is not exactly one element, or whose root is itself stripped. The ghost is appended as position: fixed, aria-hidden, pointer-events: none at the removed element's box, takes the usual frame draws for its flick, and is removed on restore or dispose.
  • capturePreviewGhosts in packages/studio/src/player/lib/previewStageAct.ts: Studio treats each ghost as an opaque string. It checks only that each entry is a string, capped, for a key it asked, and at most as many as asked. It never parses the markup or puts it in its own DOM.

The replacing frame shows the same film in the same seal, so it loads the ghost's pictures and fonts itself, as the open path's import does, and no pixels cross. The host's rule is that a capture goes only to the replacing frame of the same film and load; that lands with the host change.

No visible change

.ts only, and no host calls it yet.

What I measured

  • One row per stripped thing in stageGhost.test.ts (each element kind, on* lower and upper case, srcdoc, javascript: plain, split by a newline, in an SVG xlink:href and in an SVG <set to>, and data:text/html), plus a frameset root.
  • fails without the fix: removing each guard fails a test. Guards checked: every stripped element kind, the on* and srcdoc rules, both URL patterns, the control-character fold, the capture size cap, removing identity on capture, the ghost parse cap and field check, aria-hidden, the capture target cap, and in Studio the asked-key, cap and string checks. 22 guards, 22 caught.
  • Parity with the open path: a removed <figure> with a picture, nested inline elements and an SVG stands back with exactly the subtree cloneNode(true) gives, which is what the open path's import copies.
  • src/runtime/editing, editingPort.test.ts and editingAgent.test.ts: 612 passed. stageAct.test.ts + stageGhost.test.ts 3x with --sequence.shuffle: 56/56 each time. Studio src/player/lib: 493 passed, and previewStageAct.test.ts 20/20 3x with --sequence.shuffle.
  • tsc --noEmit for core (tsconfig.json, tsconfig.runtime.json) and studio passed. lint:runtime-preview-guards passed. Core and studio builds passed, and verify-packed-manifests.mjs shows 15 packages within budget. oxlint 0/0. comment-ratchet.mjs passes against the base.

What I did NOT exercise

  • A real browser or a pixel comparison. The pixel parity check (picture and nested element, both modes) runs in the host's walk once it is wired.
  • The host's capture timing between "replacing frame ready" and promotion. That lands with the host change.

Base automatically changed from feat/stage-act-port to main November 27, 2026 01:31
@github-actions

github-actions Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

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

# Conflicts:
#	packages/core/src/runtime/editing/stageAct.test.ts
#	packages/core/src/runtime/editing/stageAct.ts
#	packages/core/src/runtime/editingPort.ts
#	packages/studio/src/index.ts
#	packages/studio/src/player/lib/previewStageAct.test.ts
#	packages/studio/src/player/lib/previewStageAct.ts

@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 5921770. No blocker.

What I checked

  • stageGhost.ts: capture clones each located target, writes the 14 computed properties on the clone's root, drops the root's id and data-hf-id, and leaves out a subtree over the cap. inertStageGhost parses in a separate document, refuses anything but exactly one element or a root on the strip list, removes the listed elements and attributes, then imports the result.
  • stageAct.ts: capture is parsed with the same target check and the 64 cap; a ghost hold takes only key, ghost, draw, a string within the cap and a finite box; the existing duplicate-key check covers ghosts. The ghost is appended fixed at its box, aria-hidden, root pointer-events: none, takes frame draws through the same held map, and is removed by restore and by endStageAct (so by dispose and by a new hold).
  • previewStageAct.ts: the reply must match the op, be a list no longer than asked, and each entry a string within the cap for an asked key; Studio never parses the markup.
  • Tests: one row per stripped element and attribute kind, the reject cases on both ends, capture then stand-back against cloneNode(true), cap and missing key.

Notes, not blocking

  1. <style> is not on the strip list. A removed subtree that carries its own <style> child applies those rules to the whole replacing document while the ghost stands. That matches what an import of the same subtree does, so it is parity today, but it is worth a line in the comment or a strip.
  2. Only the root loses id and data-hf-id; descendants keep theirs. While the ghost stands, a later hold or measure keyed by a descendant's data-hf-id can resolve to the ghost's copy when the live one is gone. Dropping both on every descendant at capture would rule that out.
  3. pointer-events: none is set on the root only; a descendant with its own inline pointer-events still takes a press, including a plain link. Stripping href is not needed, but inert on the ghost root would cover it in one attribute.
  4. The ghost's apply ignores rotate and typed; fine for the flick, just not stated.

Feature PR; the body still lists the guards each test catches, so the fails without the fix: line is met.

Read: stageGhost.ts, stageAct.ts, previewStageAct.ts and stageGhost.test.ts whole; the other two test files and the two export files as hunks. Nothing was run.

Need: yes, the closed preview had no way to show a removed element · Size: fits · Reuse: same hold, frame and restore path as held elements · Simpler: no · Structure: ghost code in its own file
Risk: low; no host calls it yet.

— 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 failed status checks Nov 27, 2026
@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 27, 2026
Merged via the queue into main with commit ad49fd5 Nov 27, 2026
103 checks passed
@miguel-heygen
miguel-heygen deleted the feat/stage-act-ghost branch November 27, 2026 04:38
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