Repository navigation
fix(producer): preserve absent methods on early-stub timeline proxies - #8947
Conversation
Edit accuracy: accurate 273 (base branch 271), smooth 93 of thoseThe gate passes. Newly passing (2)
Not banked yet, reported and not gated (bank a full-grid run's baseline.json) (2)
Quarantined, measured but not gated (0) |
jrusso1020
left a comment
There was a problem hiding this comment.
Reviewed at 02a33c8. Read whole: packages/producer/stubs/hf-early-stub.ts. Read as hunks: the three new tests in fileServer.test.ts. The generated hf-early-stub-inline.ts was not read line by line; I only checked that it carries the new method lists. Nothing was run.
No blocker. The proxy now gets each wrapper (to/from/fromTo/set/add, pause/play/seek, the five accessors, getChildren, kill) only when the underlying timeline has that method, so a typeof tl.x === "function" check on the proxy now tells the truth about the timeline behind it. A timeline with the full set behaves as before: same flush before each forwarded call, same chaining result, same getChildren fallback to []. A gsap.timeline() that returns a non-object is passed through instead of being wrapped.
The "fails without the fix:" line names two tests, and both read as failing against the old unconditional object (typeof tl.timeScale was "function"; wrapTimeline(null) threw in the prototype walk). The third test keeps the full-surface path honest, including this binding on a class timeline.
Notes, not blocking:
- The comment that explained why this is a plain object and not a
Proxy(headless navigation hangs when traps are exposed) was dropped with the old body. It is the reason someone would not "simplify" this later; worth keeping one line of it. - A timeline without
addnow has noaddon the proxy, andforwardRemainingMethodsskips the batched names, so nothing fabricates it either. That is consistent with the rule; noting it only becauseaddis the one batched method the unwrapping of nested proxies depends on. - The tests run the generated inline stub, so a stale regenerate would show there.
Need: yes · Size: fits (net smaller source) · Reuse: n/a · Simpler: the loops replace 15 hand-written methods · Structure: fine
Risk: low; behaviour for standard timelines is unchanged.
— Rames
Why
HF_EARLY_STUBwraps timelines returned bywindow.gsap.timeline()so tween construction can be batched across frames, while the HyperFrames runtime uses feature checks (typeof tl.timeScale === "function",tl.kill?.(), etc.) before calling optional GSAP methods.Previously,
wrapTimelineunconditionally attachedto,from,fromTo,set,add,pause,play,seek,totalTime,time,duration,getChildren,paused,timeScale, andkillonto the proxy object even when the underlying timeline did not implement them. Any composition supplying a minimal or customwindow.gsap.timeline()without optional methods such astimeScaleorkillpassed the runtime'stypeofguards and immediately threwTypeError: n.timeScale is not a functionorTypeError: n.kill is not a functionduring render capture. Passing a non-object return fromgsap.timeline()also crashedwrapTimeline.What changed
packages/producer/stubs/hf-early-stub.ts: attach each batched, chained, accessor,getChildren, andkillwrapper on the timeline proxy only when the underlying timeline defines that method as a function (preservingthisbinding via.apply(real, args)/.call(real)), and return non-object values fromgsap.timeline()untouched.packages/producer/src/generated/hf-early-stub-inline.ts: regenerated IIFE output (bun run --cwd packages/producer build:hf-early-stub).packages/producer/src/services/fileServer.test.ts: regression tests covering minimal custom timelines omitting optional methods, non-object timeline returns, and full class-based timelines with prototype methods.Verification
packages/producer/src/services/fileServer.test.ts—does not fabricate timeline methods absent from the underlying timelineandreturns non-object timeline values untouched without crashing wrapTimelineboth failed onmain(exit 1, 88 pass, 2 fail) before thehf-early-stub.tschange.bun test packages/producer/src/services/fileServer.test.tspassed 3 runs in a row (exit 0, 90 pass, 0 fail each run); sibling testsfileServer-seededRandom.test.tsandfileServer-virtualTimers.test.tspassed (exit 0, 16 pass, 0 fail).bun run --cwd packages/producer typecheck,oxlint,oxfmt --check, andbun run --cwd packages/producer buildall exited 0 with 0 warnings/errors.