Skip to content

Commit d36d989

Browse files
fix: generator emits sentinel, mutation stamps the actual GSAP script
Generator (hyperframes.ts) now emits data-position-mode='relative' on the GSAP script tag. Mutation engine uses block.scriptElement (the actual GSAP script found by extractGsapScriptBlock) instead of querySelector('script:not([src])') which could match a non-GSAP data-setup script on blocks with multiple inline scripts. Co-authored-by: Miguel Ángel <miguel07alm@protonmail.com>
1 parent 2805fc3 commit d36d989

2 files changed

Lines changed: 5 additions & 6 deletions

File tree

packages/core/src/generators/hyperframes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ export function generateHyperframesHtml(
354354
const gsapCdnTag = includeScripts ? ` <script src="${GSAP_CDN}"></script>` : "";
355355

356356
const gsapScriptTag = includeScripts
357-
? ` <script>
357+
? ` <script data-position-mode="relative">
358358
${gsapScript}
359359
</script>`
360360
: "";

packages/core/src/studio-api/routes/files.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ function updateReferences(projectDir: string, oldPath: string, newPath: string):
230230
*/
231231
function extractGsapScriptBlock(html: string): {
232232
scriptText: string;
233+
scriptElement: Element;
233234
document: Document;
234235
replaceScript: (newText: string) => string;
235236
} | null {
@@ -249,6 +250,7 @@ function extractGsapScriptBlock(html: string): {
249250
) {
250251
return {
251252
scriptText: content,
253+
scriptElement: script,
252254
document,
253255
replaceScript(newText: string): string {
254256
script.textContent = newText;
@@ -1176,11 +1178,8 @@ export function registerFileRoutes(api: Hono, adapter: StudioApiAdapter): void {
11761178

11771179
const newScript = typeof result === "string" ? result : result.script;
11781180
const changed = newScript !== block.scriptText;
1179-
if (changed) {
1180-
const gsapScript = block.document.querySelector("script:not([src])");
1181-
if (gsapScript && !gsapScript.hasAttribute("data-position-mode")) {
1182-
gsapScript.setAttribute("data-position-mode", "relative");
1183-
}
1181+
if (changed && !block.scriptElement.hasAttribute("data-position-mode")) {
1182+
block.scriptElement.setAttribute("data-position-mode", "relative");
11841183
}
11851184
const newHtml = changed ? block.replaceScript(newScript) : html;
11861185
let backupPath: string | null = null;

0 commit comments

Comments
 (0)