Repository navigation
fix(studio): a script edit re-runs in place in a sealed preview, without a reload - #8158
Conversation
eddy-heygen
left a comment
There was a problem hiding this comment.
(Eddy's agent) Reviewed by Eddy's Claude agent at commit 6a6fa0c.
Verdict: comment only, not approved (stacked PR; one finding to fix before the sealed-preview flag is turned on).
Summary. This PR moves the "re-run the edited GSAP script in place" logic from Studio into core and adds an editing-port request kind, soft-reload, so a sealed (opaque-origin) preview frame re-runs the saved script itself instead of doing a full reload. The security side is sound: no handshake or source check is weakened, the script runs with the same privileges the composition's own script already has, and the reply is read as one enum value. It is not ready because a timeline move or resize in a sealed preview now re-runs the script against stale timing attributes in the frame, where the base did a correct full reload; the sealed preview is behind a build flag that defaults to off.
I read the timing-sync path and the sealed re-run path myself and confirm finding 1 by reading: with the sealed preview on, a timeline move or resize of a clip with tweens now reports the re-run as applied, while nothing sends the changed timing attributes to the frame, so the full reload the base did no longer happens. The sealed preview is behind a build flag that is off by default, so this does not affect users today; it should be fixed before the flag is turned on. This PR is stacked on another branch, so I am commenting rather than approving.
To fix before the sealed-preview flag is turned on
packages/studio/src/hooks/timelineTimingSync.ts:150: Sealed preview: a timeline move or resize now re-runs the script against stale timing attributes instead of reloading. With the opaque-preview build flag on (it defaults to off), moving or resizing a clip that has GSAP tweens leaves the preview wrong. The optimistic attribute patch is a no-op in a sealed frame: patchIframeDomTiming calls findTimelineElementInIframe, which returns null when iframe.contentDocument is null (packages/studio/src/hooks/timelineEditingHelpers.ts:160-161), and nothing in the timeline timing hooks writes those attributes over the editing port. After the save, syncTimingEditPreview gets mutated=true with scriptText, before and after from the server. moveLiveTweens returns false because planLiveRetimeFromPreview needs contentDocument (packages/studio/src/utils/gsapLiveRetime.ts:107-109). applySoftReload then takes the new sealed branch (packages/studio/src/utils/gsapSoftReload.ts:216) and returns "applied", because previousHtml is now passed at this line. The frame re-runs the rewritten script and rebinds, and the rebind derives clip windows from the frame's still-old data-start/data-duration. Result: tweens sit at the new times, clip visibility and root duration at the old ones, and Studio does not reload. On the base the same edit returned "cannot-soft-reload" and did a correct full reload. The PR description says the timing-drag retime still takes the full-reload path in a sealed preview; the code does not do that. To resolve: Either do not pass previousHtml from syncTimingEditPreview, so a sealed timing edit keeps the full reload until the timing attributes can be sent over the port, or carry the changed timing attributes in the request and apply them in the frame before the rebind. Add a sealed test for a timing edit.
Non-blockers
packages/studio/src/utils/gsapSoftReload.sealed.test.ts:1: The sealed path was never run in a real sealed session, and no test covers a sealed timing edit. The new Studio test mocks previewFrameOpaque and previewRequest, and the core tests stub gsap and appendChild. No test drives a real opaque frame or the timeline timing path, which is how finding 1 got through. The PR body says the same: no real sealed browser session was exercised, and the MotionPath plugin load inside a sealed frame is covered only by the unsealed tests. To resolve: Add a test that drives syncTimingEditPreview with an opaque frame and asserts a full reload (or the attribute sync), and exercise one sealed session by hand before the flag is turned on.
What the change needed to do
- Only the frame's own parent editor can send the new request; the handshake is not weakened: met (packages/core/src/runtime/editingAgent.ts:270-296 (unchanged): the port is created only for a connect message whose event.source is the parent, only in a document carrying the Studio mark and not marked as served to another site. The diff only adds one entry to HANDLERS at :226.)
- The script runs with no more privilege than the page's own script on a normal reload: met (packages/core/src/runtime/editing/softReload.ts:353-357: the text is appended as an inline script element in the frame's own document. This is the code the unsealed path already ran, moved unchanged.)
- Request content comes only from Studio's saved files, never from the frame: met (packages/studio/src/utils/gsapSoftReload.ts:193-207: script is the mutation result's scriptText from the Studio server, sets are parsed from previousHtml, authored from authoredHtml, time from the player store. The sealed branch reads no frame value.)
- Nothing in the frame's reply is executed: met (packages/studio/src/utils/gsapSoftReload.ts:180-186: the reply must be an object with exactly one key whose value is one of three known strings; anything else triggers a reload. :204-206 uses it only to decide whether to reload.)
- The request is bounded and refused when malformed: met (packages/core/src/runtime/editing/softReload.ts:444-455: exact key set; script 1 to 1,000,000 chars; finite non-negative time; at most 1,000 sets and 10,000 authored entries, each bounded. Wired at packages/core/src/runtime/editingPort.ts:528.)
- A failed or refused re-run leaves Studio knowing the frame is not current: partly met (A refusal, timeout, thrown handler or missing agent all resolve to a reload (packages/studio/src/utils/gsapSoftReload.ts:204-206; packages/studio/src/player/lib/previewChannel.ts:76-85). But a sealed timing edit reports applied while the frame's timing attributes are stale; see finding 1 above.)
- No guard is lost in the roughly 580 removed lines: met (The nestedFiles === null refusal stays at packages/studio/src/utils/gsapSoftReload.ts:219. The gsap/rebind-hook, no-key, no-script and ambiguous-script refusals are present at packages/core/src/runtime/editing/softReload.ts:287-295, and the built-DOM and plugin-load-failure refusals at :358-392.)
CI: 30 checks pass at the head, 1 skipped (a docs deployment), none failing or pending. No check in the list is named as a unit-test run, so I could not confirm that CI ran the new test files.
How this was reviewed: a code-review pass and a security-review pass, by a reviewer agent in an isolated checkout of this commit; I then read the core of the fix and the cited lines myself. Nothing was built or run.
|
Thanks. The timing-edit finding is right, and it applies to the live retime in #8163 too: in an unsealed preview the drag commit writes the clip's new timing attributes onto the live element first, a sealed preview skips that write, so after a move or resize the tweens moved while the clip window and root duration stayed at the old times. Fixing it on this branch (and #8163's) now: a sealed timing edit that takes the in-place path will also apply the edited elements' timing attributes and the root duration from Studio's saved file in the same step, or fall back to a full reload, with a test that drives a sealed timing edit end to end. I'll post here when it is pushed. |
|
Fixed at d964757 (and the same for the live retime in #8163 at e7a6bff; #8162 and #8164 restacked). One correction to the suggested approach: the before/after pair the timing sync has comes from the GSAP rewrite, which runs after the drag commit already saved the new data-start/data-duration, so that pair differs only in its script and a diff of it sends nothing. Instead, a sealed timing edit now sends one bounded timing field read from the saved file: the timing attributes of every timed element in the file, the film root included, so the root duration is what a full reload shows. The frame matches each to a live element of the edited composition by hf-id or id, refuses and changes nothing if one is missing or ambiguous (Studio then reloads), and applies them with the same core function the unsealed commit uses, just before the rebind that derives clip windows and film length. Other script edits send an empty list. New end-to-end test timelineTimingSync.sealed.test.ts drives a sealed timing edit through the timing sync and fails without the field; frame tests show the attributes are set before the rebind and a missing element changes nothing. Known limit: a timed element in a parked (unmounted) scene counts as missing, so that edit reloads in full. |
eddy-heygen
left a comment
There was a problem hiding this comment.
(Eddy's agent) Re-reviewed by Eddy's Claude agent at commit d964757.
Verdict: changes requested. One blocker: this PR's own lint check fails at this head. Reply when it is fixed and I will re-review and clear this. (The PR is also stacked, so after that it gets a comment, not an approval, until it targets the default branch.)
Summary of the change since 6a6fa0c. I read the new commit myself. A sealed timing edit now sends the saved file's clip and film timing with the soft-reload request. The frame refuses the request unless every entry is keyed by an element key and carries only allowlisted timing attributes with bounded values, refuses to proceed when a keyed element is missing or two share a key (the editor then reloads), and writes the attributes before the timelines are rebuilt. By reading, that addresses the earlier finding that a sealed timeline move or resize re-ran the script against stale timing attributes. The request stays data only apart from the script text the earlier review covered; attribute names cannot be chosen freely.
Blockers
packages/studio/src/hooks/timelineTimingSync.sealed.test.ts:41: the lint job fails on this PR's own new test file with "Unsafe usage of optional chaining" (I read the job log and its annotation). The expression reads a property of an optionally chained value that is then cast. The three other red jobs (player-perf, preview-regression, regression) report that their shards were skipped or did not succeed after that failure. To resolve: fix the expression (for example assert the call exists before indexing it) and get the lint job green.
Non-blockers
- The new tests still mock the sealed check and the port; no real sealed session was exercised.
- The workflow that runs type checks and unit tests only triggers for pull requests based on the default branch, so the new unit tests have not been run by CI.
CI: at this head 7 checks pass, 6 fail, 2 pending, 3 skipped. Failing: the lint job (three runs of it, cause above) and player-perf, preview-regression and regression.
How this was reviewed: I read the full change between the previously reviewed commit and this head, and the logs of the failing checks. Nothing was built or run.
(Eddy's agent) Superseded by the re-review at b9def7d.
eddy-heygen
left a comment
There was a problem hiding this comment.
(Eddy's agent) Re-reviewed by Eddy's Claude agent at commit b9def7d.
Verdict: comment only, not approved (stacked PR). My change request is cleared; no open blocker.
Summary of the change since d964757. One commit, test only: the sealed timing test now throws if no soft-reload request was sent, then reads it without the optional chain. I read it. The lint job that failed at the previous head now passes in all three of its runs.
Blockers
None open.
Non-blockers
- The new tests still mock the sealed check and the port; no real sealed session was exercised.
- The workflow that runs type checks and unit tests only triggers for pull requests based on the default branch, so the new unit tests have not been run by CI.
CI: at this head 9 checks pass and 18 are still pending; none failing. The lint job passes.
How this was reviewed: I read the change between the previously reviewed commit and this head, and the check list. Nothing was built or run.
c15654a to
1ba37c1
Compare
b9def7d to
2623310
Compare
1ba37c1 to
4aa54d9
Compare
2623310 to
8943bc0
Compare
4aa54d9 to
6c03094
Compare
8943bc0 to
2052ab1
Compare
32a38e7 to
60970d6
Compare
…g along with its soft reload
…t without suppressions
2052ab1 to
bd2430c
Compare
Edit accuracy: accurate 271 (base branch 271), smooth 77 of thoseThe gate passes. Quarantined, measured but not gated (0) Unstable (1)
|
…rame-side editing code Main already measured 1,841,737 bytes packed against a 1,830,000 budget; the sealed soft reload brings it to 1,855,277. Budgets follow SIZE_BUDGET_HEADROOM: ceil(1,855,277 x 1.05) packed, ceil(4,665,659 x 1.05) unpacked.
|
Before and After captures are now in the description, sealed Studio preview, headless Chrome on Linux. The edit: a card's animation Length changed from 2 to 1 in the Design panel's Motion section, playhead at 1.5 s.
Both runs end with the card at the same place and save the same A timeline clip move was also run and still reloads the sealed preview on this branch: the fixture's file has no saved element ids, so the moved clip's id is minted from its new start and differs from the live element's, and the frame refuses the saved timing. That is noted under "What I did NOT exercise". |
jrusso1020
left a comment
There was a problem hiding this comment.
Reviewed at f88e3ea6f8b14c5b9a5f917642feead90c639fa5.
The shared core implementation preserves the unsealed reset/seek path, and the sealed reply is validated as data before deciding whether to reload. I checked the supplied before/after images: the selection outline matches the edited card afterward. Eddy's earlier timing-field finding is addressed, but one cross-file identity case remains.
Important — scope rewritten-root keys to their authoring file (packages/core/src/runtime/editing/softReload.ts:82–84,103). liveTimedElements adds every nested data-hf-inner-root key to rewritten before checking authoringFile. If card.html has an inner root with data-hf-id="shared" before a clip in main.html with the same per-file ID, the main clip is excluded from live. planSavedTiming then treats it as a rewritten root and silently skips its update. The frame answers applied, so no fallback reload repairs the old visibility window.
I reproduced this through softReload: stamped main root, a nested card root with hf:shared, then the main clip at data-start="1"; sending the main clip's saved start 4 returns applied while its start remains 1. A main file without an explicit root duration reaches this case: setCompositionDurationToContent preserves that omission, so the saved timing list has no root entry to force a fallback.
Fix: collect rewritten only from elements whose authoring file equals ownFile, or refuse ambiguous cross-file matches instead of silently skipping the edited file's element. Add the repeated-ID fixture to the timing tests. With the ownership condition applied locally, the new probe and all existing soft-reload tests pass (18 passed); review sources were restored.
Nit: include the real top-root data-composition-file stamp in timing fixtures too. Its parent-based authoringFile currently causes conservative full reloads for a saved root-duration entry. That fallback is safe; it is separate from the incorrect applied result above.
Validation: bun install --frozen-lockfile and full bun run build succeeded. Gated focused tests: 185 core + 154 Studio passed. The required fails without the fix: line is present; removing the sealed branch makes its named test fail, and restoration gives 8 passed. The additional nested-ID probe fails with expected '1' to be '4' at this head. No new browser session was run; inspected the author's supplied captures. The merged parent is an ancestor of this head.
Audited: moved soft-reload core and legacy implementation, request/agent integration, authored styles/timing, live-set recording, Studio commit/fallback callers. Trusting: broader browser combinations beyond the supplied captures remain unexercised.
Need: yes · Size: ok · Reuse: shared core softReloadFrame and existing editing port · Simpler: one frame implementation for both callers · Structure: fine (checked legacy gsapSoftReload/softReloadTargets and applyAuthoredTiming; extraction avoids a second implementation)
Risk: medium — live preview state spans nested files and asynchronous requests.
Verdict: REQUEST CHANGES
Reasoning: The repeated-ID case reports success with stale timing. Scope the rewritten keys and retain a regression before approval.
— cutroom-review
…oot repeats a clip's id
|
Fixed at 9bd6bb8, as you suggested: Regression test in fails without the fix: with the previous Nit (top-root |
jrusso1020
left a comment
There was a problem hiding this comment.
Reviewed at 9bd6bb8f85932387979b3aff14be48b7d65c7dd9, delta from f88e3ea6.
The previous cross-file repeated-ID blocker is resolved. liveTimedElements now applies authoringFile ownership before collecting rewritten-root keys, so a nested file's root cannot suppress the saved file's clip. Same-file ordinary duplicate keys still refuse before mutation. Independent adversarial review of the delta and its identity/caller paths found no blocker.
Validation: clean-worktree bun install --frozen-lockfile and full bun run build succeeded. Through pytest-gate.sh, the soft-reload, editing-port and editing-agent suites passed 187 tests, including the supplied regression and my original stamped-main-root probe. Restoring f88e3ea6's implementation makes both regressions fail with expected '1' to be '4' (2 failed / 17 passed); restoring the fix gives 19 passed. Required fails without the fix: body line remains present. Parent #8151's head and merge commit are ancestors of this head.
The earlier top-root-duration fixture nit remains a safe conservative reload and is nonblocking. No new browser session was run; this re-review covers the ownership delta, not a new end-to-end security certification.
Need: yes, preserve sealed edits · Size: ok · Reuse: existing authoringFile and authoredKey · Simpler: already minimal · Structure: fine (checked savedTiming and planSavedTiming; no split)
Risk: medium — live preview timing spans nested files; the bounded delta restores file ownership.
Verdict: APPROVE
Reasoning: The repeated-ID regression now updates the correct clip rather than returning success with stale timing.
— cutroom-review
What
In a sealed Studio preview, a GSAP script edit (an animation added or removed, a timing change, an edit the value patch cannot place) now re-runs the edited composition's script in place, as it does in an unsealed preview. Before, every such edit in a sealed preview fell back to a full reload of the preview.
Why
The soft reload swapped the composition's script by reaching into the preview frame's document and timelines, which a sealed frame does not allow, so each script edit reloaded the whole preview: a flash and a wait. This is one of the remaining writers to move onto the editing port before Studio's preview can run sealed by default.
Related work
Stacked on #8151 (value edits in place). Same pattern: the frame-side logic moves into core, Studio's unsealed path calls the same core code with the frame it can reach, and the sealed path sends one editing port request and reloads the preview when the reply says it did not apply.
Scene swap, scene hold, the live retime of a timing drag and the shadow reload's gesture hold still take the full-reload path in a sealed preview; they follow in their own PRs.
How
soft-reload. Everything it carries comes from the files Studio saved, never from the frame: the saved script, the authored inline style of each element of the saved file, and what the previous version's standalonegsap.setcalls wrote (Studio parses the previous file; the frame has no parser). The frame derives the timeline keys from the script itself.{ result }with a known result counts as a refusal and reloads the preview. Nothing in a reply is run.data-start,data-duration, track, media offsets) for every timed element, the film's root included. The frame puts them on the live elements inside the same step, before the rebind that derives the clip windows and the film's length, and refuses, changing nothing, when an element of the saved file is not in the preview; Studio then reloads. A reachable preview's commit already patches these live, so only the sealed request carries them.gsap.setpatch wrote is now recorded where the patch is applied (core), so a sealed frame's own patches are reset by its next soft reload too.Core's size budget rises to 1,948,041 bytes packed and 4,898,942 unpacked. Main already measured 1,841,737 bytes packed against its 1,830,000 budget, and this PR's frame-side soft reload brings core to 1,855,277 (CI's measurement), more than 1% over. The new numbers follow the budget file's own rule, ceil(measured x 1.05) (
SIZE_BUDGET_HEADROOM), as #8176 did for aws-lambda; the 85% ratchet floor still holds.Test plan
fails without the fix:
packages/studio/src/utils/gsapSoftReload.sealed.test.ts("sends one request built only from the saved files") fails on the base, where a sealed preview's soft reload sends nothing and asks for a full reload. The same file checks that a reply carrying a script, an unknown result or an extra field reloads the preview and runs nothing, and that an edit with no known previous file reloads without sending.packages/core/src/runtime/editing/softReload.test.tscovers the frame side: the sent authored style lands on a reset element, a removed standalone set is cleared from the sent selector, an element from another file makes it refuse before touching anything, and the parser refuses unknown fields, oversized scripts and bad times.editingAgent.test.tssends the request through the real port. Studio's existinggsapSoftReload.test.tsandgsapUndoRestore.test.tsnow run against the moved core code.Before
Sealed Studio preview on main. A card animated by
tl.to("#card", { x: 1200, duration: 2, ease: "none" }, 0), the playhead at 1.5 s, the card selected, and the animation's Length changed from 2 to 1 in the Design panel's Motion section: one edit that rewrites the GSAP script. About 0.25 s after the change the preview frame navigates once: it reloads. The card lands at its new place (the tween now ends at 1 s), but the selection outline is left where the card was before the reload. The still is 5 s after the edit.Preview frame navigations from the start of the recording (before the card is selected) to 5 s after the change: 1.
before.mp4
After
Same fixture, same edit, on this branch's change. The card moves to its new place in the running preview, which is never reloaded, and the selection outline moves with it. The still is from the same moment as the Before still.
Preview frame navigations over the same window: 0. In both runs the card ends at the same transform (x 1200 at 1.5 s) and the file saves
tl.to("#card", { x: 1200, duration: 1, ease: "none" }, 0).after.mp4
What I measured
Core 187 and Studio 239 tests pass in the touched and neighbouring files (soft reload, undo, commit hooks, timing sync, drafts, property debounce), after building core so Studio reads the moved module; core, core runtime and Studio type checks pass, and the subpaths check verifies the new export. With the frame taking an element from another file, ignoring the sent sets, ignoring the sent authored style, or taking extra request fields, and with Studio accepting a reply with extra fields, dropping the sealed branch, not reloading on a refusal, or not sending the previous file's sets, the matching test fails each time.
What I did NOT exercise
The captures exercise one script edit, an animation's Length changed in the Design panel, in headless Chrome on Linux. Known gap, follow-up branch
fix/studio-sealed-clip-move-ids: a timeline clip move still reloads the sealed preview, as it does on main, when the file has no saved element ids. The moved clip's id is minted from its new start, so it differs from the live element's, and the frame refuses the saved timing as naming an element it does not have. The follow-up keys the saved timing by the pre-edit file's ids (a timing edit never changes the element structure) and lands right after this stack. Not exercised in a browser: an animation added or deleted, a keyframe edit, a resize, undo, other browsers, and unsealed previews, which keep their existing path. The MotionPath plugin load inside a sealed frame is covered only by the moved code's existing unsealed tests.