fix(core): revert Function constructor back to inline IIFE for composition scripts

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 </script> in source) is
already handled by the compiler's script bundling path.

Closes #1074
This commit is contained in:
Miguel Ángel
2026-05-25 15:44:35 -04:00
parent 0ea8aa4ffa
commit ccee8df4e1
@@ -216,7 +216,6 @@ export function wrapScopedCompositionScript(
const authoredRootIdFormsLiteral = JSON.stringify( const authoredRootIdFormsLiteral = JSON.stringify(
getAuthoredRootIdSelectorForms(authoredRootId?.trim() || ""), getAuthoredRootIdSelectorForms(authoredRootId?.trim() || ""),
); );
const sourceLiteral = JSON.stringify(source);
return `(function(){ return `(function(){
var __hfCompId = ${compositionIdLiteral}; var __hfCompId = ${compositionIdLiteral};
var __hfTimelineCompId = ${timelineCompositionIdLiteral}; var __hfTimelineCompId = ${timelineCompositionIdLiteral};
@@ -486,8 +485,9 @@ export function wrapScopedCompositionScript(
}); });
var __hfRun = function() { var __hfRun = function() {
try { try {
var __hfScript = Function("document", "gsap", "window", "__hyperframes", ${sourceLiteral}); (function(document, gsap, window, __hyperframes) {
__hfScript.call(window, __hfScopedDocument, __hfScopedGsap, __hfScopedWindow, __hfScopedHyperframes); ${source}
}).call(window, __hfScopedDocument, __hfScopedGsap, __hfScopedWindow, __hfScopedHyperframes);
} catch (_err) { } catch (_err) {
console.error(__hfErrorLabel, __hfCompId, _err); console.error(__hfErrorLabel, __hfCompId, _err);
} }