Skip to content

fix(studio): an edit goes to the file a host was mounted from, never one its markup names - #8844

Merged
miguel-heygen merged 2 commits into
mainfrom
fix/edit-target-file-stamp
Nov 25, 2026
Merged

miguel-heygen merged 2 commits into
mainfrom
fix/edit-target-file-stamp

Conversation

@miguel-heygen

Copy link
Copy Markdown
Collaborator

What

Studio decides which file an element's edits are written to only from the data-composition-file mark that the build or the runtime mount places on a host it actually mounted. A data-composition-src attribute that stays in the page's markup no longer names the file for the elements inside it. Empty, unresolved, skipped, nested-and-unmounted and inline-template hosts all still carry it.

Why

readElementSource returned data-composition-file ?? data-composition-src from the nearest host carrying either one. The compiler stamps data-composition-file and removes data-composition-src on every host it inlines, so on a bundled page any data-composition-src still present is on a host nothing mounted. A composition file could wrap elements in such a host (for example data-composition-src="", which the compiler and the runtime skip). Those elements then reported a file the markup chose: the empty value fell back to the active composition, and a non-empty one named any project file. Give them data-hf-ids copied from the person's own index.html, and a delete, restyle, retime or text edit on them was patched into that other element in that other file.

Two Studio helpers repeated the same fallback: the GSAP motion source-file walk and the audio-group volume walk.

Related work

Follows the data-composition-file drop for authored markup (#8812), which covered the other attribute.

How

  • packages/core/src/runtime/editingElement.ts: readElementSource reads only data-composition-file, and an empty value is no file.
  • packages/core/src/runtime/compositionLoader.ts: a host the runtime mounted from a fetched file is stamped data-composition-file with that file, as the compiler stamps the hosts it inlines (inlineSubCompositions.ts). A host mounted from a template in the same page, or one whose file failed to load, is not stamped.
  • packages/studio/src/components/editor/studioMotion.ts: the source-file walk calls readElementSource.
  • packages/studio/src/hooks/timelineAudioGroupVolume.ts: resolveGroupSourceFile reads only data-composition-file.
  • Test fixtures that model a runtime-mounted host now carry the stamp the runtime adds.

Known effect: the timeline's live preview patch (retime or delete applied to the open preview before it reloads) no longer finds a host whose file never mounted. That patch is best-effort, and the write to the file is unchanged.

Not in this PR: the server-side check that the file named by the client is the file the element's markup came from.

Test plan

  • Unit tests added/updated
  • Manual testing performed
  • Documentation updated (if applicable)
  • Comments follow CONTRIBUTING.md "Comments": they say why, not what, and a bug fix says what the code must do and how to reproduce the bug

New:

  • packages/core/src/runtime/editingElement.source.test.ts: under an empty authored data-composition-src, and under one naming index.html, an element keeps its stamped host's file. Under only authored markup it names no file. The nearest stamped host wins.
  • packages/core/src/runtime/compositionLoader.fileMark.test.ts: a fetched mount is stamped with its file. An in-page template mount and a failed load are not.
  • packages/studio/src/hooks/timelineAudioGroupVolume.test.ts: "ignores a data-composition-src the page's markup kept, which no mount stamped".

fails without the fix: editingElement.source.test.ts (3 of 4: the empty value, the value naming index.html, authored-only markup) and compositionLoader.fileMark.test.ts ("stamps a host the runtime mounted from a fetched file with that file") fail with main's editingElement.ts and compositionLoader.ts. With the change, all pass 3 runs in a row.

Also run: core src (compositionLoader, editingHandles and the rest of runtime). In Studio, every test file that touches source files or composition hosts.

@miguel-heygen

Copy link
Copy Markdown
Collaborator Author

Corrections to the description at this head:

  • The runtime stamps data-composition-file on a host as soon as its file is fetched, before the content mounts. It is one inserted line, so it stays clear of the mount call.
  • The new timelineAudioGroupVolume.test.ts case also fails with main's timelineAudioGroupVolume.ts.
  • Also run: the type check of core and Studio, and all 159 Studio test files that touch source files or composition hosts. Nine fixtures that model a mounted host now carry its stamp.

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

Request changes at 24933d08. The change is right for the paths it covers, but the timeline still reads the file from an authored data-composition-src. So a timeline delete or retime can still be written to a file the markup names, which is what this PR sets out to stop.

Blocker: previewElementSourceFile in packages/core/src/studioPreviewMark.ts keeps the fallback.

  • It returns data-composition-file ?? data-composition-src of the element's nearest [data-composition-id] ancestor. Studio imports it as getTimelineElementSourceFile (timelineElementHelpers.ts), and timelineDOM.ts and timelineIframeHelpers.ts set every timeline element's sourceFile from it.
  • That sourceFile is the write target for timeline edits: useTimelineDeleteOps.ts:121, useTimelineClipTimingEditing.ts:133/269, timelineEditingHelpers.ts:265/362/380, timelineElementsAttribute.ts, timelineElementFxAttribute.ts and useFreezeFrame.ts all write to element.sourceFile || activeCompPath.
  • Probe: this PR's own second test case, plus a data-composition-id on the inner host so the timeline sees an owner: <div data-composition-id="scene" data-composition-file="compositions/scene.html"><div data-composition-id="x" data-composition-src="index.html"><p id="target" …>. At this head, previewElementSourceFile(target) returns "index.html", not "compositions/scene.html".
  • timelineAudioGroupVolume.ts (fixed here) documents that it mirrors this helper, so the two now disagree.

To clear it:

  • Make previewElementSourceFile read only data-composition-file, with an empty value meaning no file. Better still, have it share readElementSource's rule so there is one reader.
  • Add a test through it in the shape of the probe above.
  • While there, check timelineIframeHelpers.ts:370: a clip's compositionSrc still prefers data-composition-src, and timelineElementLookup uses it as sourceFile.

Checked and fine:

  • Fails without the fix: with main's editingElement.ts and compositionLoader.ts, the 4 named tests fail (3 in editingElement.source.test.ts, plus "stamps a host the runtime mounted from a fetched file…"). At head, both files pass 7/7 on 3 runs.
  • readElementSource reads only data-composition-file, and an empty value gives null. The nearest stamped host wins.
  • studioMotion.ts now delegates to readElementSource.
  • The runtime stamps a host after its fetch succeeds and before parsing. A template mount or a failed load is not stamped, which matches the compiler.
  • The stamp uses the same src value Studio already used as the file, so its format is unchanged.

CI: "Studio and player captures" is red because the body has no Before and After captures.

Need ✅ · Size ✅ (+130/−20, mostly tests) · Reuse ⚠️ (a third reader keeps its own rule; share readElementSource) · Simpler ✅ · Structure ⚠️ (same rule in three helpers)
Risk: low for normal projects. The stated goal isn't met for timeline edits.

— Rames

@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

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

@miguel-heygen

Copy link
Copy Markdown
Collaborator Author

At 10dfa52, answering the review:

  • previewElementSourceFile (studioPreviewMark.ts) reads only data-composition-file, from the nearest stamped host above the element. The probe (an authored data-composition-id + data-composition-src="index.html" host inside a stamped scene) now returns the scene's file. New tests in studioPreviewMark.test.ts.
  • The render-time scripts that re-apply saved manual edits and motion (studio-server manualEditsRenderScript.ts, studioMotionRenderScript.ts, which core re-exports and the CLI render uses) had the same fallback; both now read only the stamp. New test in manualEditsRenderScript.test.ts: a saved edit to index.html no longer lands on a copy under an authored host naming it.
  • timelineIframeHelpers.ts:370 now prefers the stamp. That value names the file a host mounts (clip identity, drill-down), not where edits go, so it still falls back to data-composition-src to keep a host whose file never loaded on the timeline.
  • Every package was searched for data-composition-src reads. The rest name what a host mounts (labels, drill-down, host lookup), or belong to the compiler, lint, the CLI or the server reading source files.

fails without the fix: the two previewElementSourceFile tests and the render-script test fail with main's studioPreviewMark.ts and render scripts, and pass 3 runs in a row with the change. The motion render script is the same code and has no case of its own.

Also run: all Studio unit tests (863 files) and core src (349 files), and the type checks of core, Studio and studio-server. Two more fixtures that model a mounted host (automationStoreSync.test.ts, scrubAudio.test.ts) now carry its stamp.

No visible change

The diff touches only .ts files: which file an edit is saved to, and which elements a saved edit is applied to at render time. Nothing Studio or the player draws changes.

@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 10dfa524. My blocker is cleared: no timeline, render or edit path takes its write target from an authored data-composition-src any more.

What the new commit fixes:

  • previewElementSourceFile (core): it now reads the nearest [data-composition-file] ancestor, and an empty value means no file. My probe shape (stamped compositions/scene.html → authored data-composition-src="index.html" → element) now gives compositions/scene.html. Authored markup alone gives no file, so timeline writes fall back to the active composition.
  • Render scripts (studio-server): manualEditsRenderScript.ts and studioMotionRenderScript.ts had the same ?? data-composition-src walk, and both are fixed. A saved edit to index.html no longer lands on an authored copy inside a scene.
  • timelineIframeHelpers.ts:370: compositionSrc now prefers the stamp.

Red-first, which I ran myself:

  • With studioPreviewMark.ts from 24933d08, both new previewElementSourceFile tests fail.
  • With manualEditsRenderScript.ts from 24933d08, "applies an edit to index.html to no element under an authored data-composition-src naming it" fails.
  • At head, these pass on 3 runs each: core studioPreviewMark + editingElement.source + compositionLoader.fileMark (16/16), and studio-server manualEditsRenderScript (26/26).
  • This body's "fails without the fix:" line names the round-1 tests, and the new tests carry their own markers.

Remaining readers of data-composition-src, checked: labels (buildElementLabel), composition-host detection, caption discovery, and timelineElementLookup's selector and lookup sourceFile. The lookup only finds the element. The edit's write target still comes from getSourceFileForElement → readElementSource, which reads only the stamp. None of them names a file an edit is written to.

I couldn't run Studio's own vitest locally because of the build chain (lint dist), so CI's Studio run covers it.

Need ✅ · Size ✅ (+188/−37, mostly tests) · Reuse ✅ (one rule across core, Studio and the render scripts) · Simpler ✅ · Structure ✅
Risk: low. The live timeline patch no longer finds a host whose file never mounted, as the body says; the write is unchanged.

— Rames

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 25, 2026
Merged via the queue into main with commit 9dc416a Nov 25, 2026
105 of 106 checks passed
@miguel-heygen
miguel-heygen deleted the fix/edit-target-file-stamp branch November 25, 2026 15:06
@miguel-heygen miguel-heygen mentioned this pull request Nov 25, 2026
3 of 4 tasks
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