Skip to content

Commit

Permalink
Fix MotionConfig does not propagate changes to transition
Browse files Browse the repository at this point in the history
  • Loading branch information
wurstbonbon committed Dec 22, 2021
1 parent 8ebef8c commit 97c714a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

Framer Motion adheres to [Semantic Versioning](http://semver.org/).

### Fixed

- `MotionConfig` propagates changes to transition.

## [5.5.5] 2021-12-17

### Fixed
Expand Down
30 changes: 30 additions & 0 deletions src/components/MotionConfig/__tests__/MotionConfig.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import * as React from "react"
import { render } from "@testing-library/react"
import { MotionConfig } from ".."
import { MotionConfigContext } from "../../../context/MotionConfigContext"

const consumerId = "consumer"

const Consumer = () => {
const value = React.useContext(MotionConfigContext)
return <div data-testid={consumerId}>{value.transition!.type}</div>
}

const App = ({ type }: { type: string }) => (
<MotionConfig transition={{ type }}>
<Consumer />
</MotionConfig>
)

it("Passes down transition", () => {
const { getByTestId } = render(<App type="spring" />)

expect(getByTestId(consumerId).textContent).toBe("spring")
})

it("Passes down transition changes", () => {
const { getByTestId, rerender } = render(<App type="spring" />)
rerender(<App type="tween" />)

expect(getByTestId(consumerId).textContent).toBe("tween")
})
13 changes: 4 additions & 9 deletions src/components/MotionConfig/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,10 @@ export function MotionConfig({ children, ...config }: MotionConfigProps) {
* Creating a new config context object will re-render every `motion` component
* every time it renders. So we only want to create a new one sparingly.
*/
const transitionDependency =
typeof config.transition === "object"
? config.transition.toString()
: ""

const context = useMemo(() => config, [
transitionDependency,
config.transformPagePoint,
])
const context = useMemo(
() => config,
[JSON.stringify(config.transition), config.transformPagePoint]
)

return (
<MotionConfigContext.Provider value={context as MotionConfigContext}>
Expand Down

0 comments on commit 97c714a

Please sign in to comment.