Skip to content

fix(core): a redo in a sealed preview puts Studio's edit marks back in place - #8264

Merged
miguel-heygen merged 8 commits into
mainfrom
fix/core-sealed-redo-studio-marks
Nov 20, 2026
Merged

miguel-heygen merged 8 commits into
mainfrom
fix/core-sealed-redo-studio-marks

Conversation

@miguel-heygen

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

Copy link
Copy Markdown
Collaborator

What

An undo or redo in a sealed preview (Studio cannot script the frame) is applied in place only when the result will hold, and reloads the preview otherwise. Before this PR, a redo of a move, nudge, resize or rotate was always refused in place, and some in-place restores reported success while the preview showed the wrong thing.

Why

Studio saves its own edit marks on an element it moves, sizes or rotates (data-hf-studio-*), for example data-hf-studio-original-inline-translate next to the new translate. An undo removes them, and the frame already accepted removing any data-* attribute. A redo has to set them again, but the frame only set attributes from a fixed list that left them out, so every such redo fell back to a full reload.

Some marks only work through the seek-reapply script the preview server adds to a page. It adds that script only when the page it serves already carries one of them, and the script does nothing on a page that has none. A mark on the page does not prove the script is running: the server's check only recognised double-quoted marks, so a page with a single-quoted mark got no script. Putting such a mark back in place is only safe once the script has actually started.

How

studioReappliedMarks.ts (new, core): the marks that script keeps applied, the motion marks, the name of the flag the script sets when it starts, and the check that finds the marks in a page's HTML, in one place. restoreAttributes.ts, the in-frame script's tests and the preview server's check for adding the script all read it.

The seek-reapply script now sets that flag on the page's window when it starts keeping marks applied. The server's check now finds a mark in any quoting (double, single or none) and any letter case of the attribute name; the value must match exactly, as the script's own selector requires. The producer's render uses the same check (htmlCompiler.ts), so a single-quoted mark now gets the script there too.

restoreAttributes.ts:

  • A restore may now set Studio's edit marks (data-hf-studio-*), next to the unchanged fixed list. Handlers, URLs, sandbox and other data-* names are still refused.
  • It still reloads the preview when:
    • it sets a mark the seek-reapply script keeps applied (data-hf-studio-path-offset, -box-size, -rotation) on a page where that script has not started, because nothing would keep it applied after the next seek;
    • it sets or removes a motion mark (data-hf-studio-motion, data-hf-studio-motion-original-*), because a motion runs through a timeline the script builds when the page loads.
  • The script-started rule lives in planRestore, the planner restore-attributes and fix(studio): a sealed undo or redo of a keyframe edit re-runs in place instead of reloading #8272's in-place undo re-run (soft-reload with restore) share, so that re-run is refused for the same marks and the preview reloads.

Tests

restoreAttributes.test.ts:

  • A restore that sets data-hf-studio-original-inline-translate and a translate style applies in place.
  • Setting data-hf-studio-box-size reloads on a page that carries a rotation mark but whose script has not started, and applies in place once the script has started.
  • Removing data-hf-studio-motion reloads.
  • The refusal test also covers onerror, a non-Studio data-hf-handle, the near misses data-hf-studio and data-studio-x, and setting the motion marks.

softReload.test.ts: an undo re-run that restores data-hf-studio-box-size on a page whose seek-reapply script has not started answers cannot-soft-reload and changes nothing; once the script has started it applies.

manualEditsRenderScript.test.ts:

  • The in-frame script starts, sets the flag, and the server adds it, on a page with any one of the core list's marks; none of the three for a page with only a plain-translate mark. It fails if the core list and the script disagree on a mark's name or the flag.
  • The server's check finds single-quoted, unquoted and upper-case marks, and not near misses ("false", "truey", "TRUE", a motion-original mark, a name glued to another word).

fails without the fix: with the set check as on main, the in-place test fails. With the old check (a mark on the page), the box-size test fails; with the rule outside the shared planner, the soft-reload test fails; with the old double-quote-only server check, the quoting test fails; without the script setting its flag, the script test fails; with motion removal allowed, the motion test fails; renaming a mark in the core list fails the script test.

Run on Linux at this head (main merged in): core restoreAttributes, softReload, editingAgent and editingPort (200 tests), a Studio run filtered to gsapSoftReload.sealed (5 files, 131 tests) and studio-server manualEditsRenderScript (21) three runs in a row; core and Studio tsc no errors; format clean; the code audit passes.

Bench

Edit-accuracy cases with the sealed preview on, at rotation 0, two at a time on macOS; cases whose redo left the box more than 2 px off. Before: the sealed-by-default change with the sealed nudge fixes. After: the same plus this PR's first commit (edit marks settable, no page check yet).

gesture cases redo off, before redo off, after
move 60 8 5
nudge 60 10 8
resize 66 36 32
rotate 62 52 53

The bench scores a redo against the screen right after the gesture, so a gesture that saved the wrong size or angle also counts as a redo miss. Traced one case at a time at this head (rotation 0, root level): of 63 resize and rotate redos off, 61 match a fresh load of the saved file, and the save itself is off by the same amount (rotate 45 of 49 saves, resize 31 of 48). Those redos show the file correctly; the sealed resize and rotate save is a separate fix. Two resize redos (idle and late fixtures) are off while their save is right; those are still open.

@terencecho terencecho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 · Edge case — restoring motion can report success while the animation stays absent. The prefix accepts Studio's motion metadata as well as move, resize, and rotation markers. A sealed preview that loaded without any Studio edits has no seek reapply script. Restoring its first motion marker now returns applied: true, which suppresses the reload that would install the script. A focused DOM test with real GSAP confirmed that the frame accepts the attribute without creating a motion timeline, while reloading the saved HTML produces the expected animation. Restrict in-place restore to the geometry attributes it can apply, or retain the reload fallback for motion. Restore allowlist

The named move-redo test passes here and fails with the predicate reverted. The Comments check is red on the added comment. Full browser gestures were outside this run. Comments check

— tai (automated review)

@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

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

Unstable (1)

  • seqresize-none-px-r0-root-z100: tracking 0.06, pressJump 0, drop 0, reload 0, render 0.02, renderKey -, undo false, teleport true / tracking 0.06, pressJump 0, drop 0, reload 0, render 0.02, renderKey -, undo true, teleport true / tracking 0.06, pressJump 0, drop 0, reload 0, render 0.02, renderKey -, undo true, teleport true

@miguel-heygen

Copy link
Copy Markdown
Collaborator Author

Fixed in 2e28dcc. The rule now takes Studio's edit marks except its motion marks (data-hf-studio-motion, data-hf-studio-motion-original-*), so a redo that sets one answers "not applied" and Studio reloads the preview as before. The refusal test covers data-hf-studio-motion and data-hf-studio-motion-original-opacity; with the plain data-hf-studio- prefix it fails.

@terencecho terencecho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The motion setter now requests a reload, which closes the previous finding. The named regression test fails with the original fixed list, and the refusal test fails with the motion exception removed.

Both remaining findings come from accepting attribute changes when the frame’s seek behavior still reflects the old document.

  • P2 · Edge case · packages/core/src/runtime/editing/restoreAttributes.ts:45. The first resize redo on a frame loaded without edit markers can report success while the authored timeline immediately overrides the restored width. The server installs its seek-reapply script only when the loaded HTML already has an edit marker. In a targeted jsdom probe with real GSAP, a timeline callback wrote 150px on redo and 175px on the next seek. Reloading the restored markup kept the intended 240px. The animation works through a callback, so the element has no _gsap field and the existing guard lets it through.
  • P2 · Edge case · packages/core/src/runtime/editing/restoreAttributes.ts:47. A restore that adds a geometry marker and removes the last motion marker now succeeds in place. The sealed seek handler leaves the old motion timeline registered after that removal. In Chromium, the restored translation applied, but the old animation still set opacity to 0.25 where a reload of the same markup gave 1. Preserve the reload fallback for mixed restores that remove motion unless the old timeline is retired before reporting success.

The capture check passed. Required build, typecheck, runtime contract and Windows render checks were pending. I ran targeted probes and skipped the full edit-accuracy benchmark.

— tai (automated review)

@miguel-heygen

Copy link
Copy Markdown
Collaborator Author

Fixed in a42bdd1.

  • Resize on a page loaded without edit marks: a restore that sets a mark the seek-reapply script keeps applied (data-hf-studio-path-offset, -box-size, -rotation) now applies in place only if the page already carries one of those marks, since the server adds the script only to such a page and the script does nothing on a page without one. Otherwise the frame answers "not applied" and Studio reloads. Test: setting data-hf-studio-box-size reloads on a bare page and applies on a page that has a rotation mark.
  • A mixed restore that removes the last motion mark: removing a motion mark is now refused, so it reloads. Test: removing data-hf-studio-motion answers "not applied".

The mark list has one owner in core (studioReappliedMarks.ts); the server's check for adding the script reads it, and a test runs the in-frame script against each mark so the two cannot disagree.

@terencecho terencecho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 · Edge case — packages/core/src/runtime/editing/restoreAttributes.ts:54. An edit attribute in the DOM can exist without the seek-reapply script running. The preview fallback preserved a valid single-quoted rotation marker, while the server’s script detector in manualEditsRenderScript.ts:25 only matched double quotes. In Chromium the sealed frame accepted a resize from 80 px to 160 px, then the next seek put it back at 80 px. A fresh load held at 160 px. Check for script startup before accepting a restore that depends on it.

The earlier motion cases now reload without partially applying geometry. The named mutations failed as expected. Windows render was still running.

— tai (automated review)

@miguel-heygen

Copy link
Copy Markdown
Collaborator Author

Fixed in c11e76a, at both ends.

  • The seek-reapply script now sets a flag on the page's window when it starts keeping marks applied, and a restore that sets a mark the script keeps applied goes in place only once that flag is set; otherwise the frame answers "not applied" and Studio reloads. Test: a page that carries a rotation mark but whose script has not started reloads the box-size restore.
  • The server's check for adding the script (also used by the producer's render) now finds a mark in any quoting and attribute-name case, with the value matched exactly. Test: single-quoted, unquoted and upper-case marks are found; near misses are not. It fails with the old double-quote-only check.

The flag name, the marks and the check live in one core module; a test runs the real in-frame script against each mark and fails if the script stops setting the flag.

@terencecho terencecho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The single-quoted marker now receives the seek-reapply script from the preview route. In Chromium, the restored width held after seeking. With a parsed marker and no running script, both attribute restore and soft reload declined before changing the preview. The sealed move round trip and mixed motion fallback also passed.

Targeted core, Studio, and server tests passed. The quoting and startup-guard regression tests failed when their corresponding fixes were removed. The merge includes #8272. Required CI was still running at review time, and the full gesture benchmark was outside this targeted review.

— tai (automated review)

@terencecho terencecho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The delta from the approved head is one shortened test comment. The Comments check passed, and the test and production code match the prior review.

— tai (automated review)

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 20, 2026
Merged via the queue into main with commit 95a8a91 Nov 20, 2026
99 checks passed
@miguel-heygen
miguel-heygen deleted the fix/core-sealed-redo-studio-marks branch November 20, 2026 07:46
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