From ccee8df4e13559ab9a87af1af14cdbc2db5f62e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel?= Date: Mon, 25 May 2026 19:31:57 +0000 Subject: [PATCH] fix(core): revert Function constructor back to inline IIFE for composition scripts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Function constructor (3bb0d1ef) breaks sub-composition scripts that call document.getElementById() — the constructor creates functions with global scope, losing access to the composition-scoped DOM proxy. Native method calls on proxy-returned elements throw "Illegal invocation". Reverts to the inline IIFE that preserves the closure over __hfScoped* variables. The original motivation (handling in source) is already handled by the compiler's script bundling path. Closes #1074 --- packages/core/src/compiler/compositionScoping.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/core/src/compiler/compositionScoping.ts b/packages/core/src/compiler/compositionScoping.ts index 72e9cbbf8..ba9412f30 100644 --- a/packages/core/src/compiler/compositionScoping.ts +++ b/packages/core/src/compiler/compositionScoping.ts @@ -216,7 +216,6 @@ export function wrapScopedCompositionScript( const authoredRootIdFormsLiteral = JSON.stringify( getAuthoredRootIdSelectorForms(authoredRootId?.trim() || ""), ); - const sourceLiteral = JSON.stringify(source); return `(function(){ var __hfCompId = ${compositionIdLiteral}; var __hfTimelineCompId = ${timelineCompositionIdLiteral}; @@ -486,8 +485,9 @@ export function wrapScopedCompositionScript( }); var __hfRun = function() { try { - var __hfScript = Function("document", "gsap", "window", "__hyperframes", ${sourceLiteral}); - __hfScript.call(window, __hfScopedDocument, __hfScopedGsap, __hfScopedWindow, __hfScopedHyperframes); + (function(document, gsap, window, __hyperframes) { +${source} + }).call(window, __hfScopedDocument, __hfScopedGsap, __hfScopedWindow, __hfScopedHyperframes); } catch (_err) { console.error(__hfErrorLabel, __hfCompId, _err); }