Skip to content

Commit

Permalink
Remove auto will-change (#2824)
Browse files Browse the repository at this point in the history
* Applying animating value names to will-change

* Reverting will-change

* Fixing tests
  • Loading branch information
mattgperry authored Oct 15, 2024
1 parent 7ce568a commit a2b81ac
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 264 deletions.
46 changes: 26 additions & 20 deletions packages/framer-motion/src/gestures/drag/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { useState } from "react"
import { pointerDown, render } from "../../../../jest.setup"
import { BoundingBox, motion, motionValue, MotionValue } from "../../../"
import {
BoundingBox,
motion,
motionValue,
MotionValue,
useWillChange,
} from "../../../"
import { MockDrag, drag, deferred, dragFrame, Point, sleep } from "./utils"
import { nextFrame } from "../../__tests__/utils"
import { WillChangeMotionValue } from "../../../value/use-will-change/WillChangeMotionValue"
Expand Down Expand Up @@ -57,21 +63,25 @@ describe("dragging", () => {
})

test("willChange is applied correctly when other values are animating", async () => {
const Component = () => (
<MockDrag>
<motion.div
data-testid="draggable"
drag="y"
dragTransition={{
bounceStiffness: 100000,
bounceDamping: 100000,
}}
initial={{ x: 0 }}
animate={{ x: 100 }}
transition={{ duration: 5 }}
/>
</MockDrag>
)
const Component = () => {
const willChange = useWillChange()
return (
<MockDrag>
<motion.div
data-testid="draggable"
drag="y"
dragTransition={{
bounceStiffness: 100000,
bounceDamping: 100000,
}}
initial={{ x: 0 }}
animate={{ x: 100 }}
transition={{ duration: 5 }}
style={{ willChange }}
/>
</MockDrag>
)
}

const { container, getByTestId, rerender } = render(<Component />)
rerender(<Component />)
Expand Down Expand Up @@ -322,10 +332,6 @@ describe("dragging", () => {

const endValue = await new Promise<number>((resolve) => {
setTimeout(() => {
expect(container.firstChild).toHaveStyle(
"will-change: transform;"
)

resolve(x.get())
}, 40)
})
Expand Down
17 changes: 11 additions & 6 deletions packages/framer-motion/src/motion/utils/use-visual-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ function makeLatestValues(
scrapeMotionValues: ScrapeMotionValuesFromProps
) {
const values: ResolvedValues = {}
let applyWillChange =
const willChange = new Set()
const applyWillChange =
shouldApplyWillChange && props.style?.willChange === undefined

const motionValues = scrapeMotionValues(props, {})
Expand Down Expand Up @@ -171,15 +172,19 @@ function makeLatestValues(
if (applyWillChange) {
if (animate && initial !== false && !isAnimationControls(animate)) {
forEachDefinition(props, animate, (target) => {
for (const key in target) {
const willChangeName = getWillChangeName(key)
if (willChangeName) {
values.willChange = "transform"
return
for (const name in target) {
const memberName = getWillChangeName(name)

if (memberName) {
willChange.add(memberName)
}
}
})
}

if (willChange.size) {
values.willChange = Array.from(willChange).join(",")
}
}

return values
Expand Down

This file was deleted.

Loading

0 comments on commit a2b81ac

Please sign in to comment.