Repository navigation
fix(core): blur quiets discrete callbacks instead of undoing what they wrote #7271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
76d64f9
fix(core): blur quiets discrete callbacks instead of undoing what the…
vanceingalls c7e6eaa
test(producer): drop the once-guard-label block-start guard that pins…
vanceingalls a50f454
test(engine): split the callbacks matrix in three and share one blur-…
vanceingalls File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| // @vitest-environment happy-dom | ||
| import gsap from "gsap"; | ||
| import { describe, expect, it, vi } from "vitest"; | ||
| import { muteDiscreteCallbacks } from "./gsap"; | ||
| import type { RuntimeTimelineLike } from "../types"; | ||
|
|
||
| const asRuntime = (tl: gsap.core.Timeline): RuntimeTimelineLike => | ||
| tl as unknown as RuntimeTimelineLike; | ||
|
|
||
| function sweep(tl: gsap.core.Timeline, ...times: number[]): void { | ||
| for (const t of times) tl.seek(t, false); | ||
| } | ||
|
|
||
| describe("muteDiscreteCallbacks", () => { | ||
| it("quiets onStart, onComplete, onReverseComplete and onRepeat, and leaves onUpdate firing", () => { | ||
| const fired = { start: 0, complete: 0, reverse: 0, repeat: 0, update: 0 }; | ||
| const tl = gsap.timeline({ paused: true }); | ||
| tl.to( | ||
| { v: 0 }, | ||
| { | ||
| v: 1, | ||
| duration: 0.2, | ||
| repeat: 1, | ||
| onStart: () => void fired.start++, | ||
| onComplete: () => void fired.complete++, | ||
| onReverseComplete: () => void fired.reverse++, | ||
| onRepeat: () => void fired.repeat++, | ||
| onUpdate: () => void fired.update++, | ||
| }, | ||
| 0.1, | ||
| ); | ||
|
|
||
| const restore = muteDiscreteCallbacks([asRuntime(tl)]); | ||
| sweep(tl, 0, 0.2, 0.6, 0); | ||
| expect(fired.start + fired.complete + fired.reverse + fired.repeat).toBe(0); | ||
| expect(fired.update).toBeGreaterThan(0); | ||
|
|
||
| restore(); | ||
| sweep(tl, 0.2, 0.6, 0); | ||
| expect(fired.start).toBeGreaterThan(0); | ||
| expect(fired.complete).toBeGreaterThan(0); | ||
| expect(fired.reverse).toBeGreaterThan(0); | ||
| expect(fired.repeat).toBeGreaterThan(0); | ||
| }); | ||
|
|
||
| it("reaches a stagger's and a keyframes tween's own tweens", () => { | ||
| const staggered = vi.fn(); | ||
| const keyed = vi.fn(); | ||
| const tl = gsap.timeline({ paused: true }); | ||
| tl.to( | ||
| [{ v: 0 }, { v: 0 }], | ||
| { | ||
| v: 1, | ||
| duration: 0.05, | ||
| stagger: { each: 0.05, onComplete: staggered }, | ||
| }, | ||
| 0.1, | ||
| ); | ||
| tl.to( | ||
| { v: 0 }, | ||
| { | ||
| keyframes: [ | ||
| { v: 0.5, duration: 0.05 }, | ||
| { v: 1, duration: 0.05, onComplete: keyed }, | ||
| ], | ||
| }, | ||
| 0.4, | ||
| ); | ||
|
|
||
| const restore = muteDiscreteCallbacks([asRuntime(tl)]); | ||
| sweep(tl, 0, 1); | ||
| expect(staggered).not.toHaveBeenCalled(); | ||
| expect(keyed).not.toHaveBeenCalled(); | ||
|
|
||
| restore(); | ||
| sweep(tl, 0, 1); | ||
| expect(staggered).toHaveBeenCalled(); | ||
| expect(keyed).toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("restores a callback reached through two timelines", () => { | ||
| const fn = vi.fn(); | ||
| const root = gsap.timeline({ paused: true }); | ||
| const scene = gsap.timeline(); | ||
| scene.call(fn, [], 0.5); | ||
| root.add(scene, 0); | ||
|
|
||
| const restore = muteDiscreteCallbacks([asRuntime(scene), asRuntime(root)]); | ||
| sweep(root, 0, 1); | ||
| expect(fn).not.toHaveBeenCalled(); | ||
|
|
||
| restore(); | ||
| sweep(root, 0, 1); | ||
| expect(fn).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| it("restores the outer mute's callbacks when mutes nest", () => { | ||
| const fn = vi.fn(); | ||
| const tl = gsap.timeline({ paused: true }); | ||
| tl.call(fn, [], 0.5); | ||
|
|
||
| const outer = muteDiscreteCallbacks([asRuntime(tl)]); | ||
| const inner = muteDiscreteCallbacks([asRuntime(tl)]); | ||
| inner(); | ||
| sweep(tl, 0, 1); | ||
| expect(fn).not.toHaveBeenCalled(); | ||
|
|
||
| outer(); | ||
| sweep(tl, 0, 1); | ||
| expect(fn).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| it("keeps a replaced function's params and scope", () => { | ||
| const scope = { name: "scope" }; | ||
| const seen: Array<{ args: unknown[]; scope: unknown }> = []; | ||
| const fn = function (this: unknown, ...args: unknown[]): void { | ||
| seen.push({ args, scope: this }); | ||
| }; | ||
| const tl = gsap.timeline({ paused: true }); | ||
| tl.call(fn, ["x"], 0.5); | ||
| const call = tl.getChildren(false, true, false)[0] as gsap.core.Tween; | ||
| call.vars.callbackScope = scope; | ||
|
|
||
| const restore = muteDiscreteCallbacks([asRuntime(tl)]); | ||
| sweep(tl, 0, 1); | ||
| expect(seen).toEqual([]); | ||
|
|
||
| restore(); | ||
| sweep(tl, 0, 1); | ||
| expect(seen).toHaveLength(1); | ||
| expect(seen[0]?.args).toEqual(["x"]); | ||
| expect(seen[0]?.scope).toBe(scope); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
important — If the walk throws partway, the callbacks it has already muted stay no-ops for the rest of the session, and the next mute/restore can't bring them back. On the next pass those no-ops look like an outer mute's, so the skip on L500 passes over them and they never go into
held. I reproduced it:muteDiscreteCallbacks([a, objWhoseGetChildrenThrows])throws, after whicha'stl.callfires 0 times, including after a later full mute → restore →seek(0)/seek(1)cycle.whileCallbacksMutedcallsmuteCallbacks()before itstry, and the paint swallows the error (runtime.captureMotionBlur.paint), so the film just loses its calls without any visible failure. The trigger is anywindow.__timelinesentry that isn't a GSAP timeline and whosegetChildrenthrows (or nests deeply enough to overflow the recursion).The fix is small. The same guard on restore also covers your second limit, a callback reassigned while muted. I ran it with both cases as tests, plus
gsap.mute.test.tsandcaptureMotionBlur/: 220/220 pass.