Skip to content

fix(producer): preserve absent methods on early-stub timeline proxies - #8947

Merged
miguel-heygen merged 1 commit into
mainfrom
fix/early-stub-preserve-timeline-methods
Nov 27, 2026
Merged

miguel-heygen merged 1 commit into
mainfrom
fix/early-stub-preserve-timeline-methods

Conversation

@miguel-heygen

Copy link
Copy Markdown
Collaborator

Why

HF_EARLY_STUB wraps timelines returned by window.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, wrapTimeline unconditionally attached to, from, fromTo, set, add, pause, play, seek, totalTime, time, duration, getChildren, paused, timeScale, and kill onto the proxy object even when the underlying timeline did not implement them. Any composition supplying a minimal or custom window.gsap.timeline() without optional methods such as timeScale or kill passed the runtime's typeof guards and immediately threw TypeError: n.timeScale is not a function or TypeError: n.kill is not a function during render capture. Passing a non-object return from gsap.timeline() also crashed wrapTimeline.

What changed

  • packages/producer/stubs/hf-early-stub.ts: attach each batched, chained, accessor, getChildren, and kill wrapper on the timeline proxy only when the underlying timeline defines that method as a function (preserving this binding via .apply(real, args) / .call(real)), and return non-object values from gsap.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

  • fails without the fix: packages/producer/src/services/fileServer.test.ts — does not fabricate timeline methods absent from the underlying timeline and returns non-object timeline values untouched without crashing wrapTimeline both failed on main (exit 1, 88 pass, 2 fail) before the hf-early-stub.ts change.
  • After fix: bun test packages/producer/src/services/fileServer.test.ts passed 3 runs in a row (exit 0, 90 pass, 0 fail each run); sibling tests fileServer-seededRandom.test.ts and fileServer-virtualTimers.test.ts passed (exit 0, 16 pass, 0 fail).
  • bun run --cwd packages/producer typecheck, oxlint, oxfmt --check, and bun run --cwd packages/producer build all exited 0 with 0 warnings/errors.
  • Not exercised: a full end-to-end headless Chrome render of a custom-GSAP composition (covered by the injected stub unit harness above; full browser CI suite runs on the PR merge ref).

@github-actions

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 273 (base branch 271), smooth 93 of those

The gate passes.
Smoothness is reported in the artifact, not gated. A case fails only if it fails 2 of 3 runs.

Newly passing (2)

  • seqscaletwice-scale-px-r0-nested-z100
  • seqscaletwice-scale-px-r0-root-z100

Not banked yet, reported and not gated (bank a full-grid run's baseline.json) (2)

  • seqscaletwice-scale-px-r0-nested-z100
  • seqscaletwice-scale-px-r0-root-z100

Quarantined, measured but not gated (0)

@jrusso1020 jrusso1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 add now has no add on the proxy, and forwardRemainingMethods skips the batched names, so nothing fabricates it either. That is consistent with the rule; noting it only because add is 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

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 27, 2026
Merged via the queue into main with commit 82a208f Nov 27, 2026
97 checks passed
@miguel-heygen
miguel-heygen deleted the fix/early-stub-preserve-timeline-methods branch November 27, 2026 06:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants