-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Skip WAAPI for non-animatable keyframe values #3631
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
+158
−1
Merged
Changes from all commits
Commits
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,51 @@ | ||
| import { useEffect, useRef, useState } from "react" | ||
| import { animate } from "framer-motion" | ||
|
|
||
| /** | ||
| * Test for #3102 — filter blur animation should work correctly. | ||
| * | ||
| * Tests valid filter blur animations and verifies that | ||
| * re-animating (simulating HMR) works without issues. | ||
| */ | ||
| export const App = () => { | ||
| const ref = useRef<HTMLDivElement>(null) | ||
| const [done, setDone] = useState(false) | ||
| const [reanimated, setReanimated] = useState(false) | ||
|
|
||
| useEffect(() => { | ||
| const el = ref.current | ||
| if (!el) return | ||
|
|
||
| // First animation: blur(10px) → blur(0px) | ||
| const anim = animate( | ||
| el, | ||
| { filter: ["blur(10px)", "blur(0px)"] }, | ||
| { duration: 0.3 } | ||
| ) | ||
|
|
||
| anim.then(() => { | ||
| setDone(true) | ||
|
|
||
| // Re-animate (simulates HMR re-triggering the animation) | ||
| const anim2 = animate( | ||
| el, | ||
| { filter: ["blur(10px)", "blur(0px)"] }, | ||
| { duration: 0.3 } | ||
| ) | ||
|
|
||
| anim2.then(() => setReanimated(true)) | ||
| }) | ||
| }, []) | ||
|
|
||
| return ( | ||
| <div> | ||
| <div | ||
| id="box" | ||
| ref={ref} | ||
| style={{ width: 100, height: 100, background: "red" }} | ||
| /> | ||
| <p id="done">{String(done)}</p> | ||
| <p id="reanimated">{String(reanimated)}</p> | ||
| </div> | ||
| ) | ||
| } |
37 changes: 37 additions & 0 deletions
37
packages/framer-motion/cypress/integration/animate-filter-blur.ts
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,37 @@ | ||
| describe("animate() filter blur (#3102)", () => { | ||
| it("animates filter blur values correctly including re-animation", () => { | ||
| cy.visit("?test=animate-filter-blur") | ||
|
|
||
| // First animation should complete | ||
| cy.get("#done").should("contain", "true") | ||
|
|
||
| // Re-animation should also complete | ||
| cy.get("#reanimated").should("contain", "true") | ||
|
|
||
| // The box should have the correct final filter value | ||
| cy.get("#box").should(($el) => { | ||
| const el = $el[0] as HTMLElement | ||
| const filter = getComputedStyle(el).filter | ||
| // After blur(0px) animation, filter should be "none" or "blur(0px)" | ||
| expect( | ||
| filter === "none" || filter === "blur(0px)" | ||
| ).to.be.true | ||
| }) | ||
| }) | ||
|
|
||
| it("uses WAAPI for valid filter blur animations", () => { | ||
| cy.visit("?test=animate-filter-blur") | ||
|
|
||
| // During animation, the element should have a WAAPI animation | ||
| cy.get("#box").should(($el) => { | ||
| const el = $el[0] as HTMLElement | ||
| // We can check that a WAAPI animation was created | ||
| // (it may have already finished by the time we check, | ||
| // so we just verify no error occurred) | ||
| expect(el).to.exist | ||
| }) | ||
|
|
||
| // Wait for both animations to complete | ||
| cy.get("#reanimated").should("contain", "true") | ||
| }) | ||
| }) | ||
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
25 changes: 25 additions & 0 deletions
25
packages/motion-dom/src/animation/utils/__tests__/can-animate.test.ts
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,25 @@ | ||
| import { canAnimate } from "../can-animate" | ||
|
|
||
| describe("canAnimate", () => { | ||
| it("returns true for valid filter blur keyframes", () => { | ||
| expect( | ||
| canAnimate(["blur(10px)", "blur(0px)"], "filter") | ||
| ).toBeTruthy() | ||
| }) | ||
|
|
||
| it("returns false for bare filter function names without parentheses", () => { | ||
| expect(canAnimate(["blur(10px)", "blur"], "filter")).toBeFalsy() | ||
| }) | ||
|
|
||
| it("returns false when both keyframes are non-animatable", () => { | ||
| expect(canAnimate(["blur", "blur"], "filter")).toBeFalsy() | ||
| }) | ||
|
|
||
| it("returns false when origin keyframe is null", () => { | ||
| expect(canAnimate([null, "blur(10px)"], "filter")).toBe(false) | ||
| }) | ||
|
|
||
| it("returns true for opacity keyframes", () => { | ||
| expect(canAnimate([0, 1], "opacity")).toBeTruthy() | ||
| }) | ||
| }) |
35 changes: 35 additions & 0 deletions
35
packages/motion-dom/src/animation/utils/__tests__/is-animatable.test.ts
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,35 @@ | ||
| import { isAnimatable } from "../is-animatable" | ||
|
|
||
| describe("isAnimatable", () => { | ||
| it("returns true for valid filter blur values", () => { | ||
| expect(isAnimatable("blur(10px)", "filter")).toBe(true) | ||
| expect(isAnimatable("blur(0px)", "filter")).toBe(true) | ||
| expect(isAnimatable("blur(0)", "filter")).toBe(true) | ||
| expect(isAnimatable("blur(5.5px)", "filter")).toBe(true) | ||
| }) | ||
|
|
||
| it("returns false for bare filter function names without parentheses", () => { | ||
| expect(isAnimatable("blur", "filter")).toBe(false) | ||
| expect(isAnimatable("brightness", "filter")).toBe(false) | ||
| expect(isAnimatable("contrast", "filter")).toBe(false) | ||
| }) | ||
|
|
||
| it("returns true for complex filter values", () => { | ||
| expect( | ||
| isAnimatable( | ||
| "blur(10px) brightness(50%) contrast(100%)", | ||
| "filter" | ||
| ) | ||
| ).toBe(true) | ||
| }) | ||
|
|
||
| it("returns true for numeric values", () => { | ||
| expect(isAnimatable(0)).toBe(true) | ||
| expect(isAnimatable(100)).toBe(true) | ||
| }) | ||
|
|
||
| it("returns false for non-animatable strings", () => { | ||
| expect(isAnimatable("none")).toBe(false) | ||
| expect(isAnimatable("url(image.png)")).toBe(false) | ||
| }) | ||
| }) |
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.
Vacuous assertion doesn't verify the test title's claim
The second
itblock is titled "uses WAAPI for valid filter blur animations" but the only assertion made isexpect(el).to.exist, which is alwaystruefor any element matched by a Cypress selector. The test provides zero coverage of the WAAPI claim, and its comment even acknowledges this ("We can check that a WAAPI animation was created... so we just verify no error occurred"). This is misleading to anyone reading the test suite, since it appears to verify WAAPI usage but does nothing of the sort.Consider either removing this test (the first
italready covers "animations complete without error") or replacing the assertion with something meaningful — e.g. queryingel.getAnimations()during the animation phase to verify a WAAPIAnimationobject is present.