Repository navigation
fix(studio): an edit goes to the file a host was mounted from, never one its markup names - #8844
Conversation
…ever one its markup names
|
Corrections to the description at this head:
|
jrusso1020
left a comment
There was a problem hiding this comment.
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-srcof the element's nearest[data-composition-id]ancestor. Studio imports it asgetTimelineElementSourceFile(timelineElementHelpers.ts), andtimelineDOM.tsandtimelineIframeHelpers.tsset every timeline element'ssourceFilefrom it. - That
sourceFileis the write target for timeline edits:useTimelineDeleteOps.ts:121,useTimelineClipTimingEditing.ts:133/269,timelineEditingHelpers.ts:265/362/380,timelineElementsAttribute.ts,timelineElementFxAttribute.tsanduseFreezeFrame.tsall write toelement.sourceFile || activeCompPath. - Probe: this PR's own second test case, plus a
data-composition-idon 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
previewElementSourceFileread onlydata-composition-file, with an empty value meaning no file. Better still, have it sharereadElementSource'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'scompositionSrcstill prefersdata-composition-src, andtimelineElementLookupuses it assourceFile.
Checked and fine:
- Fails without the fix: with main's
editingElement.tsandcompositionLoader.ts, the 4 named tests fail (3 ineditingElement.source.test.ts, plus "stamps a host the runtime mounted from a fetched file…"). At head, both files pass 7/7 on 3 runs. readElementSourcereads onlydata-composition-file, and an empty value givesnull. The nearest stamped host wins.studioMotion.tsnow delegates toreadElementSource.- 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
srcvalue 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 readElementSource) · Simpler ✅ · Structure
Risk: low for normal projects. The stated goal isn't met for timeline edits.
— Rames
Edit accuracy: accurate 273 (base branch 271), smooth 46 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) |
…e, never authored markup
|
At 10dfa52, answering the review:
fails without the fix: the two Also run: all Studio unit tests (863 files) and core No visible changeThe diff touches only |
jrusso1020
left a comment
There was a problem hiding this comment.
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 (stampedcompositions/scene.html→ authoreddata-composition-src="index.html"→ element) now givescompositions/scene.html. Authored markup alone gives no file, so timeline writes fall back to the active composition.- Render scripts (studio-server):
manualEditsRenderScript.tsandstudioMotionRenderScript.tshad the same?? data-composition-srcwalk, and both are fixed. A saved edit toindex.htmlno longer lands on an authored copy inside a scene. timelineIframeHelpers.ts:370:compositionSrcnow prefers the stamp.
Red-first, which I ran myself:
- With
studioPreviewMark.tsfrom24933d08, both newpreviewElementSourceFiletests fail. - With
manualEditsRenderScript.tsfrom24933d08, "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-servermanualEditsRenderScript(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
What
Studio decides which file an element's edits are written to only from the
data-composition-filemark that the build or the runtime mount places on a host it actually mounted. Adata-composition-srcattribute 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
readElementSourcereturneddata-composition-file ?? data-composition-srcfrom the nearest host carrying either one. The compiler stampsdata-composition-fileand removesdata-composition-srcon every host it inlines, so on a bundled page anydata-composition-srcstill present is on a host nothing mounted. A composition file could wrap elements in such a host (for exampledata-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 themdata-hf-ids copied from the person's ownindex.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-filedrop for authored markup (#8812), which covered the other attribute.How
packages/core/src/runtime/editingElement.ts:readElementSourcereads onlydata-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 stampeddata-composition-filewith 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 callsreadElementSource.packages/studio/src/hooks/timelineAudioGroupVolume.ts:resolveGroupSourceFilereads onlydata-composition-file.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
New:
packages/core/src/runtime/editingElement.source.test.ts: under an empty authoreddata-composition-src, and under one namingindex.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 namingindex.html, authored-only markup) andcompositionLoader.fileMark.test.ts("stamps a host the runtime mounted from a fetched file with that file") fail with main'seditingElement.tsandcompositionLoader.ts. With the change, all pass 3 runs in a row.Also run: core
src(compositionLoader,editingHandlesand the rest ofruntime). In Studio, every test file that touches source files or composition hosts.