Repository navigation
fix(studio): a file's markup cannot choose which file an element's edits are written to - #8812
Conversation
…its are written to The preview build, the runtime loader and the single-composition page now remove every data-composition-file a file authored before the build stamps its own, so the mark Studio reads always names the file the element was served from.
…hored file marks The preview falls back to the saved main file when bundling returns nothing or throws; that page skips the build, so it now drops authored data-composition-file marks itself.
jrusso1020
left a comment
There was a problem hiding this comment.
Verdict: REQUEST_CHANGES at 0424ee486cedbcc576f79f53aada6b91219c31f7. One path the PR says it covers still lets a file's markup pick the file: the single-composition page keeps a mark written on a full document's <html> or <body>.
Blocker
packages/studio-server/src/helpers/subComposition.ts:151-152→:421-422: in full-document mode,extractFullDocumentPartscopies the file's<html>and<body>attributes as strings, andbuildSubCompositionHtmlwrites them back onto the page's<html>/<body>. The newdropAuthoredCompositionFiles(scriptsDoc)at:376only sees the body content, so those copies ofdata-composition-filesurvive.readElementSource(packages/core/src/runtime/editingElement.ts:211) walks all the way up to<html>, so any element outside the[data-composition-id]root resolves to the authored file. If the file has nodata-composition-idelement,tagRootCompositionFiledoes nothing and every element resolves to it.- Probe:
compositions/scene.html=<!doctype html><html data-composition-file="index.html"><head></head><body data-composition-file="index.html"><div data-composition-id="scene"><p id="in">a</p></div><p id="out">b</p></body></html>. I ranbuildSubCompositionHtml(dir, "compositions/scene.html", "/runtime.js")and parsed the result with linkedom. It givesbody: "index.html",html: "index.html",#in → compositions/scene.html,#out → index.html. So Studio would write edits to#outintoindex.html. - Suggested fix: strip the attribute from
htmlEl/doc.bodyinextractFullDocumentPartsbeforeextractElementAttrs, or filter it out ofhtmlAttrs/bodyAttrs. Then add a test case like the probe above.
- Probe:
Verified
packages/core/src/compositionSource.ts:15-21: the helper removes everydata-composition-file, and it recurses intotemplate.content.htmlBundler.ts:1284: the drop runs on the entry document aftercompileHtml, CSS inlining and the root-script read, and beforeinlineSubCompositions. Nothing before that point stamps the attribute. The only build stamps areinlineSubCompositions.ts:781/816andtagRootCompositionFile, and both run after the drop. That also holds for a template entry served throughreadMountedSceneShell.inlineSubCompositions.ts:537:contentDocis a freshparseCopyfor each host, so the drop never touches a stamp already placed in the main document. Nested hosts inside it get stamped later in the queue, after their own content's drop.resolveSubCompositionContentonly takes the body or template inner HTML, so<body>attributes of an inlined file never reach the page.compositionLoader.ts:836: the fetched document is raw source, so the build has stamped nothing in it. Nested hosts in it aredata-composition-srchosts, which the resolver reads as a fallback, so no legitimate mark is lost.routes/preview.ts:142-147: the reparse only happens when the page contains the mark. Otherwise the page goes through the sameensureHfIdspath as before.- No source writer emits
data-composition-file. The only writers are the build stampers above and the paste refusal list (htmlAttrSafety.ts). Nothing relies on an authored mark.
Non-blocking
routes/preview.ts:143: the gatehtml.includes("data-composition-file")is case-sensitive, but attribute names in HTML are not. I authoredDATA-COMPOSITION-FILE="scenes/other.html"in a copy ofpreview.unbuiltFileMarks.test.ts, and both cases (returns nothing / throws) still served the mark. A/data-composition-file/itest closes it. The DOM-based drops elsewhere are unaffected, because the parser lowercases names.- The render compile (
packages/producer/src/services/htmlCompiler.ts) goes through the shared inliner, so marks inside sub-compositions are dropped there. The entry document's own marks are not. The render-time manual-edits and motion scripts (manualEditsRenderScript.ts:426,studioMotionRenderScript.ts:106) resolve the file through the same attribute. An element under an authored mark inindex.htmlwould therefore resolve to one file in preview and another in render. It's an edge case, but worth a follow-up so the two agree.
Checked:
- At the head:
htmlBundler.test.ts+compositionLoader.test.ts311/311, andsubComposition.test.ts+routes/preview.unbuiltFileMarks.test.ts39/39. - Red-first in core: with
dropAuthoredCompositionFilesstubbed to a no-op, both new core tests failed (serves only the data-composition-file marks it stamps…,mounts a fetched file without the data-composition-file marks it authored), 2 failed / 309 passed. - Red-first in studio-server: with
subComposition.tsandroutes/preview.tsat the merge base,names the composition's own file on its root…and bothdrops the file marks it authored when the build …cases failed, 3 failed / 36 passed. The tree was restored to the head afterwards and the probe files removed.
Need ✅ · Size ✅ · Reuse ✅ (follows dropAuthoredSvgReferenceAliases) · Simpler ✅ · Structure ❌ (the full-document <html>/<body> attribute path is not covered)
Risk: low. The change only removes attributes the build would never have stamped. The remaining gap is limited to full-document compositions opened on their own.
Edit accuracy: accurate 273 (base branch 271), smooth 56 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) |
…y, in any case, and in render A full document opened on its own kept a mark written on its <html> or <body>; linkedom keeps the case a file wrote, so a mixed-case mark slipped past every drop; and the render compile kept the entry file's own marks. The helper now matches names in any case and runs on all three.
|
Addressed at
The body predates this push. Coverage now: core 15 files / 718 tests, studio-server |
|
Build at
945,000 is just above the measured size, so the budget still ratchets down from here. |
jrusso1020
left a comment
There was a problem hiding this comment.
Re-review at 74809ac7: APPROVE.
- The change since
e8f8d067is one line:scripts/package-size-budgets.jsonraises the@hyperframes/inspectorpacked budget from 933,584 to 945,000. I reviewed the code ate8f8d067last round with no blocker left: marks are dropped case-insensitively across the whole document, in both the preview path and the producer, and the red-first tests fail without the fix. - The reason for the raise holds up. The new helper ships in core's compiler and again in the runtime script the compiler inlines, and both land in inspector's
service.js. The measured growth is about 250 B packed. CI measured 943,109 at the old head, so main at the base already sat within about 60 B of the 1% tolerance. Trimming this PR would not keep the next core change under it. - Nit, not blocking: 945,000 leaves about 1.9 KB over today's CI size. That is fine, but the next budget trip should come with the same kind of measurement.
Need · Size · Reuse · Simpler · Structure: needed for green Build · 1 line · n/a · nothing simpler without dropping the runtime copy · fine.
Risk: low. Budget-only change; no code change since my last pass.
— Rames
What
A
data-composition-filewritten in a file's own markup no longer reaches the page Studio previews. The preview build, the runtime's loader for a fetched composition, the single-composition preview page and the saved page served when the build fails remove every authored copy before the build stamps its own. The mark Studio reads to choose the file for an element's edits then always names the file the element was served from.Why
Studio writes an element's move, restyle, retime, delete, timing and GSAP edits to the file its nearest
data-composition-filenames (resolveElementSourceFiletakes that mark ahead of its own composition map). The build stamps that mark on every sub-composition host it inlines, nested ones included, but it kept any copy a file authored. A received composition could carrydata-composition-file="index.html"on an element, or on its own root when opened on its own (tagRootCompositionFileleft an existing mark alone). The person's later edits to that element were then written to another file of the project.Related work
Follows #8730, which made a paste from another file refuse these marks. This covers the marks that reach a page other than by paste: a received file, an agent's edit, a nested composition.
How
dropAuthoredCompositionFilesinpackages/core/src/compositionSource.tsremoves everydata-composition-fileunder a node, inside templates too.inlineSubCompositions), a composition the runtime fetches (next todropAuthoredSvgReferenceAliases), studio-server's single-composition page (buildSubCompositionHtml, beforetagRootCompositionFilestamps the root), and the saved main page the preview falls back to when bundling returns nothing or throws (unbuiltMainHtmlinroutes/preview.ts, which reparses only a page that carries the mark).dropAuthoredSvgReferenceAliases, which already drops an authored SVG alias from a fetched composition the same way.index.html's direct clips.No visible change
Previews and edits of every composition the build inlines are unchanged; only marks a file wrote itself are gone.
Test plan
fails without the fix:
serves only the data-composition-file marks it stamps, never one a file authoredinpackages/core/src/compiler/htmlBundler.test.ts,mounts a fetched file without the data-composition-file marks it authoredinpackages/core/src/runtime/compositionLoader.test.ts,names the composition's own file on its root, whatever file its markup claimsinpackages/studio-server/src/helpers/subComposition.test.ts, and both cases ofdrops the file marks it authored when the build %sinpackages/studio-server/src/routes/preview.unbuiltFileMarks.test.ts. On main all of them fail (the authored mark survives). Removing only the bundler's entry call, or only the inline call, fails the bundler test; making the helper a no-op fails both core tests.With the fix:
htmlBundler.test.ts227,compositionLoader.test.ts84,init.test.ts289,inlineSubCompositions.test.ts56,inlineSubCompositions.reuse.test.ts2,pageBuild.golden.test.ts4, the eight otherhtmlBundler.*files andcompositionAssembly.test.ts56,subComposition.test.ts37,subCompositionBuild.exit.test.ts3, the 20routes/preview*files 369, all passing with 0 skipped. Every new test passed three runs in a row. Core (both configs) and studio-servertsc, oxlint, oxfmt and fallow are clean.