Skip to content

fix(studio): an undo on a sealed preview shows in place, not after a reload - #8009

Merged
miguel-heygen merged 2 commits into
mainfrom
fix/studio-sealed-undo-restore
Nov 17, 2026
Merged

miguel-heygen merged 2 commits into
mainfrom
fix/studio-sealed-undo-restore

Conversation

@miguel-heygen

@miguel-heygen miguel-heygen commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

What

An undo or redo on a sealed preview (the preview on an opaque origin, VITE_STUDIO_OPAQUE_PREVIEW_ENABLED) now shows in place, as it does on a same-origin preview. Before, Studio could not reach a sealed frame's document, so every undo fell back to a full reload of the preview, and the moved element stayed where the edit left it until that reload landed: 8.5 s later in the edit accuracy bench on a Linux box.

Studio still works out the restore from the saved files alone: which identified elements changed, and each one's restored attributes. It sends that to the frame over the editing port as a new restore-attributes request with the playhead time. The frame finds each element by its data-hf-id or id (in the document, or in every host that inlines a sub-composition), checks all of them before touching any, sets their attributes, then rebinds the timeline at the playhead (seek, __hfForceTimelineRebind, manual edits reapplied), with no script run. It answers applied: false and changes nothing when an element is missing, shares its key with another, is a sub-composition's rewritten root, or has been parsed by GSAP while the files keep a GSAP script; Studio then reloads the preview as before. A restore whose GSAP script itself changed still reloads.

A same-origin preview takes the same path as before; nothing changes with the flag off.

The new request is part of the preview runtime, which @hyperframes/inspector bundles: its unpacked size measured 3,819,701 bytes in CI, so its budget in scripts/package-size-budgets.json moves from 3,780,000 to 3,820,000.

Why

A sealed preview keeps a composition's scripts apart from Studio's page. Undo was one of the editing paths that still read the frame directly, and the one the edit accuracy bench fails on with the preview sealed.

What I measured

On a Linux box, against this main:

  • Edit accuracy bench, --grid pr --filter '^move-idle-px-r0-(root|nested)-z100$', with the sealed default from feat(studio): Studio's preview runs sealed by default #7846 applied: undo goes from 0/2 to 1/2. The root case passes (box back within 0.5 px, file byte-identical). The nested case still reloads: its sub-composition has its own GSAP script, which takes the reload path on a same-origin preview too, and a sealed reload is slow; that is a separate change.
  • On main with the sealed default, the undone box stays at the dragged position (90, 60 px off, 108 px) at the bench's measure, still there 2.5 s later, and back only after 8.5 s.
  • packages/core: restoreAttributes.test.ts, editingAgent.test.ts, editingPort.test.ts, 149 tests, 3 runs, all pass. bun run typecheck (with typecheck:runtime) clean.
  • packages/studio: gsapUndoRestore.sealed.test.ts and gsapUndoRestore.test.ts, 47 tests, 3 runs, all pass. bun run typecheck clean.
  • fails without the fix: with gsapUndoRestore.ts as on main, two of the three cases in gsapUndoRestore.sealed.test.ts fail (nothing is sent to the frame, the preview reloads); with the GSAP-parsed check removed from restoreAttributes, "changes nothing when an element is missing, shared by two, or GSAP-parsed under a script" fails.

What I did NOT exercise

  • A restore that changes a GSAP script on a sealed preview still reloads; moving that re-run into the frame is a separate change.
  • A gesture in progress while an undo lands is not detected on a sealed preview (Studio cannot read the frame's gesture marks), so the restore applies under it.
  • No macOS or Windows run.

Before

On main with the sealed default: the edit accuracy bench's root move case, captured right after Ctrl+Z. The toast says the move was undone, but the box is still where the drag left it.

Before: sealed preview, right after Ctrl+Z, the box is still where the drag left it

After

This branch with the sealed default, same case and moment: the box is back where it started and Studio shows "Undid: Move layer".

After: sealed preview, right after Ctrl+Z, the box is back

@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 267 (base branch 267), smooth 90 of those

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

Quarantined, measured but not gated (8)

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

APPROVE at f5b6ddd7.

  • The new request goes through the existing typed editing port. It enters PARAM_PARSERS like every other kind, and parseRestoreAttributes is strict:

    • exact key sets at every level;
    • time finite and ≥ 0;
    • bounded scopes, elements and attributes (64 / 2,000 / 256);
    • keys must be hf:… or id:…;
    • attribute names match /^[^\s"'>/=]{1,256}$/, and values are capped at 200 KB;
    • anything else becomes a typed error, never a throw.
  • It's all-or-nothing in the frame. planRestore resolves every element first and refuses on any of these:

    • a missing key;
    • a key shared by two elements (identityMap returns null);
    • a sub-composition's rewritten root (data-hf-inner-root);
    • a GSAP-parsed element while the files keep a GSAP script;
    • no __player.seek.

    Only then does it set attributes and rebind. applied: false changes nothing, and Studio falls back to the old reload, so a wrong or partial apply can't leave the preview half-restored.

  • The isolation boundary is unchanged. The request flows Studio → sealed frame, carrying attributes Studio diffed from the saved files: the composition's own content, which a reload would load anyway. Setting attributes on existing nodes doesn't re-run a <script>, and the frame's opaque origin and CSP still apply. The frame's only answer is applied, so a composition that lies about it can at worst skip a reload. It can't make Studio do anything else.

  • Fails-without lines hold. With main's gsapUndoRestore.ts, two of the three sealed cases fail. Dropping the GSAP-parsed check fails the "changes nothing when…" case. The same-origin path and flag-off behaviour are unchanged.

  • The @hyperframes/inspector budget moves from 3,780,000 to 3,820,000 for the measured 3,819,701 bytes.

CI: 65 pass, 1 pending, 0 failing. Both commits are signed, and the title, body and commit messages carry no internal references.

Note: the body says an undo landing during a gesture in progress isn't detected on a sealed preview. That's a UX edge, not a boundary issue.

Need ✅ · Size ✅ · Reuse ✅ (the existing editing port and rebind path) · Simpler ✅

Risk: low. It's all-or-nothing, and any refusal falls back to the old reload.

— Rames

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 17, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 17, 2026
@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 17, 2026
Merged via the queue into main with commit fee03bf Nov 17, 2026
144 of 145 checks passed
@miguel-heygen
miguel-heygen deleted the fix/studio-sealed-undo-restore branch November 17, 2026 04:15
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