Skip to content

fix(studio): a first animation in a sub-composition file runs from inside its template - #4806

Merged
miguel-heygen merged 1 commit into
mainfrom
fix/studio-first-animation-in-template
Oct 1, 2026
Merged

miguel-heygen merged 1 commit into
mainfrom
fix/studio-first-animation-in-template

Conversation

@miguel-heygen

@miguel-heygen miguel-heygen commented Sep 30, 2026 •

Copy link
Copy Markdown
Collaborator

What changes

The first GSAP edit on a GSAP-free sub-composition file now puts the GSAP script and timeline inside the file's <template>, where the composition loader runs them. Before, a file with no <body> (every sub-composition file is only its <template>) got the script appended after </template>. The loader never runs it, so that first edit was saved but never showed, in the preview or in a render.

Moves and nudges of GSAP-free elements stop writing GSAP at all in #4799. This covers the remaining ways in, such as the first animation added to a GSAP-free sub-composition.

How

prepareGsapMutationScript (studio-server routes/files.ts) still inserts before </body> when the file has one. Otherwise it inserts before the file's own outer </template>, through core's insertBeforeCloseTag (which now also takes "template"). Core walks the markup, skipping comments and script text, and counts template depth, so a template nested inside the sub-composition's template keeps its own close tag. Only when a file has neither does it fall back to appending at the end. A file with a <body> keeps the </body> placement even when its content sits in a <template> (<body><template>…</template></body>): a root composition can hold a <template> (slot or clone markup) whose scripts never run, so moving the script into it would break the root case. Studio writes sub-compositions as template-only files, and every registry file with the body-wrapped shape already has GSAP, so this first-animation path does not reach them. It is a string insertion, so no <head> or <body> is added to the file.

Test

htmlDocument.test.ts: "puts markup before the outer , past a nested one and a commented one". It fails with first-match lookup.

files.test.ts: "a first animation in a sub-composition file lands inside its template". Without the fix it fails, because the script sits after </template>. "a first animation in a file lands before , outside its template" pins the body-wrapped choice above.

Before

Main: a fixture project whose root includes a template-only sub-composition holding #card. Its first animation (x 0 to 800 over 2 s) is added through the same GSAP mutation route the test uses, and Studio is seeked to 2.0 s. The script was saved after </template>, so the card has not moved.

Before: the card is still at its start at 2.0 s

After

This PR, same fixture, same mutation, same seek. The script was saved inside the template, so the card is 800 px to the right at 2.0 s.

After: the card has moved 800 px at 2.0 s

Merged below the usual size floor: this PR was opened and reviewed before PRs started being batched per lane, and PRs already in review finish as they are.

@github-actions

github-actions Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Edit accuracy: 841 passing here, 841 on the base branch

The gate passes.
Smoothness is reported in the artifact, not gated. A case fails only if it fails 2 of 3 runs.

Quarantined, measured but not gated (7)

@miguel-heygen
miguel-heygen force-pushed the fix/studio-first-animation-in-template branch 9 times, most recently from ead4de8 to bf2692e Compare October 1, 2026 18:25
@miguel-heygen
miguel-heygen marked this pull request as ready for review October 1, 2026 19:09
@miguel-heygen
miguel-heygen force-pushed the fix/studio-first-animation-in-template branch from bf2692e to cd7ac03 Compare October 1, 2026 19:16
@miguel-heygen
miguel-heygen merged commit 30c5569 into main Oct 1, 2026
157 checks passed
@miguel-heygen
miguel-heygen deleted the fix/studio-first-animation-in-template branch October 1, 2026 20:40
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.

1 participant