Skip to content

Commit 7397702

Browse files
Merge pull request #1060 from func25/f/preserve-static
fix(core): stop binding class values in composition scoped window
2 parents 90bf485 + d3127a7 commit 7397702

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

packages/core/src/compiler/compositionScoping.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,28 @@ body { margin: 0; }
146146
expect(variablesByComp["card-1"]).toEqual({ title: "Pro" });
147147
});
148148

149+
it("preserves static methods on classes exposed through window", () => {
150+
const { document } = parseHTML(`<div data-composition-id="scene"></div>`);
151+
class FakeTexts {
152+
static mountChars() {
153+
return "ok";
154+
}
155+
}
156+
const fakeWindow: Record<string, unknown> = {
157+
document,
158+
__timelines: {},
159+
Texts: FakeTexts,
160+
};
161+
const wrapped = wrapScopedCompositionScript(
162+
`window.__capturedMountCharsType = typeof window.Texts?.mountChars;`,
163+
"scene",
164+
);
165+
166+
new Function("window", wrapped)(fakeWindow);
167+
168+
expect(fakeWindow.__capturedMountCharsType).toBe("function");
169+
});
170+
149171
it("executes document and GSAP selectors inside the composition root", () => {
150172
const { document } = parseHTML(`
151173
<div data-composition-id="scene" data-start="intro"><h1 class="title">Scene</h1></div>

packages/core/src/compiler/compositionScoping.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,7 @@ export function wrapScopedCompositionScript(
383383
? new Proxy(window, {
384384
get: function(target, prop, receiver) {
385385
if (prop === "__timelines") return __hfGetTimelineRegistry();
386-
var value = Reflect.get(target, prop, target);
387-
return typeof value === "function" ? value.bind(target) : value;
386+
return Reflect.get(target, prop, target);
388387
},
389388
set: function(target, prop, value, receiver) {
390389
if (prop === "__timelines") {

0 commit comments

Comments
 (0)