Skip to content

fix(studio): a file's markup cannot choose which file an element's edits are written to - #8812

Merged
miguel-heygen merged 6 commits into
mainfrom
fix/authored-composition-file-marks
Nov 25, 2026
Merged

miguel-heygen merged 6 commits into
mainfrom
fix/authored-composition-file-marks

Conversation

@miguel-heygen

Copy link
Copy Markdown
Collaborator

What

A data-composition-file written 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-file names (resolveElementSourceFile takes 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 carry data-composition-file="index.html" on an element, or on its own root when opened on its own (tagRootCompositionFile left 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

  • dropAuthoredCompositionFiles in packages/core/src/compositionSource.ts removes every data-composition-file under a node, inside templates too.
  • It runs where a source file's markup is parsed for a preview, before anything is stamped: the bundler's entry document, each inlined sub-composition's content (inlineSubCompositions), a composition the runtime fetches (next to dropAuthoredSvgReferenceAliases), studio-server's single-composition page (buildSubCompositionHtml, before tagRootCompositionFile stamps the root), and the saved main page the preview falls back to when bundling returns nothing or throws (unbuiltMainHtml in routes/preview.ts, which reparses only a page that carries the mark).
  • It follows dropAuthoredSvgReferenceAliases, which already drops an authored SVG alias from a fetched composition the same way.
  • Studio's resolver is unchanged. Ignoring the mark there would send edits inside nested sub-compositions to the wrong file, since Studio's own map lists only 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

  • 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

fails without the fix: serves only the data-composition-file marks it stamps, never one a file authored in packages/core/src/compiler/htmlBundler.test.ts, mounts a fetched file without the data-composition-file marks it authored in packages/core/src/runtime/compositionLoader.test.ts, names the composition's own file on its root, whatever file its markup claims in packages/studio-server/src/helpers/subComposition.test.ts, and both cases of drops the file marks it authored when the build %s in packages/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.ts 227, compositionLoader.test.ts 84, init.test.ts 289, inlineSubCompositions.test.ts 56, inlineSubCompositions.reuse.test.ts 2, pageBuild.golden.test.ts 4, the eight other htmlBundler.* files and compositionAssembly.test.ts 56, subComposition.test.ts 37, subCompositionBuild.exit.test.ts 3, the 20 routes/preview* files 369, all passing with 0 skipped. Every new test passed three runs in a row. Core (both configs) and studio-server tsc, oxlint, oxfmt and fallow are clean.

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

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, extractFullDocumentParts copies the file's <html> and <body> attributes as strings, and buildSubCompositionHtml writes them back onto the page's <html>/<body>. The new dropAuthoredCompositionFiles(scriptsDoc) at :376 only sees the body content, so those copies of data-composition-file survive. 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 no data-composition-id element, tagRootCompositionFile does 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 ran buildSubCompositionHtml(dir, "compositions/scene.html", "/runtime.js") and parsed the result with linkedom. It gives body: "index.html", html: "index.html", #in → compositions/scene.html, #out → index.html. So Studio would write edits to #out into index.html.
    • Suggested fix: strip the attribute from htmlEl/doc.body in extractFullDocumentParts before extractElementAttrs, or filter it out of htmlAttrs/bodyAttrs. Then add a test case like the probe above.

Verified

  • packages/core/src/compositionSource.ts:15-21: the helper removes every data-composition-file, and it recurses into template.content.
  • htmlBundler.ts:1284: the drop runs on the entry document after compileHtml, CSS inlining and the root-script read, and before inlineSubCompositions. Nothing before that point stamps the attribute. The only build stamps are inlineSubCompositions.ts:781/816 and tagRootCompositionFile, and both run after the drop. That also holds for a template entry served through readMountedSceneShell.
  • inlineSubCompositions.ts:537: contentDoc is a fresh parseCopy for 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. resolveSubCompositionContent only 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 are data-composition-src hosts, 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 same ensureHfIds path 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 gate html.includes("data-composition-file") is case-sensitive, but attribute names in HTML are not. I authored DATA-COMPOSITION-FILE="scenes/other.html" in a copy of preview.unbuiltFileMarks.test.ts, and both cases (returns nothing / throws) still served the mark. A /data-composition-file/i test 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 in index.html would 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.ts 311/311, and subComposition.test.ts + routes/preview.unbuiltFileMarks.test.ts 39/39.
  • Red-first in core: with dropAuthoredCompositionFiles stubbed 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.ts and routes/preview.ts at the merge base, names the composition's own file on its root… and both drops 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.

@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

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

…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.
@miguel-heygen

Copy link
Copy Markdown
Collaborator Author

Addressed at 791fc1c0:

  • Blocker (full document <html> / <body>): extractFullDocumentParts now drops the marks on the whole parsed document before the <html> and <body> attributes are copied onto the page. New test drops a mark a full document wrote on its <html> or <body> in helpers/subComposition.test.ts is your probe: #in resolves to compositions/scene.html, #out to nothing. Red before the change.
  • Case: the gate in routes/preview.ts is now /data-composition-file/i. That alone was not enough. linkedom keeps the case a file wrote (getAttributeNames() gives DATA-Composition-File, and [data-composition-file] matches 0 elements), so a mixed-case mark also slipped past every DOM drop, while a browser still reads it. dropAuthoredCompositionFiles now compares each attribute name lowercased. The fallback route test runs lower and mixed case for both "returns nothing" and "throws", and the bundler test authors a mixed-case mark. Both were red with the selector-based helper.
  • Render entry: taken in this PR, not as a follow-up. The producer's inlineSubCompositions drops the entry document's marks right after parsing, so preview and render agree. New test renders without the data-composition-file marks the entry file authored in htmlCompiler.test.ts, red before.

The body predates this push. Coverage now: core 15 files / 718 tests, studio-server helpers/subComposition* + every routes/preview* 22 files / 412, producer htmlCompiler.test.ts 206, 0 skipped. New tests pass 3 runs in a row. Core, studio-server and producer tsc and the commit hooks (oxlint, oxfmt, fallow) are clean.

@miguel-heygen

Copy link
Copy Markdown
Collaborator Author

Build at e8f8d067 was red on the @hyperframes/inspector packed-size budget. 74809ac7 raises that budget from 933,584 to 945,000. Why:

  • What grew: inspector's dist/service.js bundles core's compiler, and with it the runtime script the compiler inlines. So dropAuthoredCompositionFiles ships twice: once in the bundler and inliner, once in the runtime's composition loader. inspection.js, live.js and server.js don't change.
  • By how much: packing inspector on the same machine with this PR's source and then with the base's source gives 938,446 and 938,196 bytes. This PR adds 250 bytes packed.
  • Why that trips the check: CI measured 943,109 here. Main at this PR's base therefore packs about 942,860, already within roughly 60 bytes of the 1% tolerance (942,920). Any change to core's compiler or runtime would cross it.
  • Why not shrink it: the helper is the one owner of the rule and has no comment left. Dropping bytes would mean dropping one of the places it runs.

945,000 is just above the measured size, so the budget still ratchets down from here.

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

Re-review at 74809ac7: APPROVE.

  • The change since e8f8d067 is one line: scripts/package-size-budgets.json raises the @hyperframes/inspector packed budget from 933,584 to 945,000. I reviewed the code at e8f8d067 last 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

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 25, 2026
Merged via the queue into main with commit 56ba601 Nov 25, 2026
106 checks passed
@miguel-heygen
miguel-heygen deleted the fix/authored-composition-file-marks branch November 25, 2026 09:48
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