Repository navigation
feat(core): stand a removed element back as a ghost in a sealed preview - #8956
Conversation
Edit accuracy: accurate 273 (base branch 271), smooth 59 of thoseThe gate passes. Newly passing (2)
Not banked yet, reported and not gated (bank a full-grid run's baseline.json) (2)
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
left a comment
There was a problem hiding this comment.
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'sidanddata-hf-id, and leaves out a subtree over the cap.inertStageGhostparses 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:captureis parsed with the same target check and the 64 cap; a ghost hold takes onlykey,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, rootpointer-events: none, takesframedraws through the sameheldmap, and is removed byrestoreand byendStageAct(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
<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.- Only the root loses
idanddata-hf-id; descendants keep theirs. While the ghost stands, a later hold or measure keyed by a descendant'sdata-hf-idcan resolve to the ghost's copy when the live one is gone. Dropping both on every descendant at capture would rule that out. pointer-events: noneis set on the root only; a descendant with its own inlinepointer-eventsstill takes a press, including a plain link. Strippinghrefis not needed, butinerton the ghost root would cover it in one attribute.- The ghost's
applyignoresrotateandtyped; 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
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.
captureop onstage-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 itsidordata-hf-id. A subtree overMAX_STAGE_GHOST_MARKUP = 65_536characters is left out. Each call takes at mostMAX_STAGE_ACTStargets.holdinstageAct.ts: the replacing frame parses the markup inert (DOMParser) and stripsscript,iframe,object,embed,frame,frameset,base,metaandlinkelements, everyon*attribute,srcdoc, and any attribute whose value, with spaces and control characters removed, containsjavascript:ordata:text/html. It refuses markup that is not exactly one element, or whose root is itself stripped. The ghost is appended asposition: fixed,aria-hidden,pointer-events: noneat the removed element's box, takes the usualframedraws for its flick, and is removed onrestoreordispose.capturePreviewGhostsinpackages/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
.tsonly, and no host calls it yet.What I measured
stageGhost.test.ts(each element kind,on*lower and upper case,srcdoc,javascript:plain, split by a newline, in an SVGxlink:hrefand in an SVG<set to>, anddata:text/html), plus a frameset root.on*andsrcdocrules, 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.<figure>with a picture, nested inline elements and an SVG stands back with exactly the subtreecloneNode(true)gives, which is what the open path's import copies.src/runtime/editing,editingPort.test.tsandeditingAgent.test.ts: 612 passed.stageAct.test.ts+stageGhost.test.ts3x with--sequence.shuffle: 56/56 each time. Studiosrc/player/lib: 493 passed, andpreviewStageAct.test.ts20/20 3x with--sequence.shuffle.tsc --noEmitfor core (tsconfig.json,tsconfig.runtime.json) and studio passed.lint:runtime-preview-guardspassed. Core and studio builds passed, andverify-packed-manifests.mjsshows 15 packages within budget.oxlint0/0.comment-ratchet.mjspasses against the base.What I did NOT exercise