Skip to content
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

Removing memoisation from context #1312

Merged
merged 2 commits into from
Oct 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion CHANGELOG.md
Expand Up @@ -2,7 +2,13 @@

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

## [5.0.0] 2021-10-25
## [5.0.1] 2021-10-29

### Fixed

- Removing context memoisation to ensure removed values are correctly animated to.

## [5.0.0] 2021-10-27

### Added

Expand Down
15 changes: 2 additions & 13 deletions src/context/MotionContext/create.ts
Expand Up @@ -3,26 +3,15 @@ import { MotionContext, MotionContextProps } from "."
import { MotionProps } from "../../motion/types"
import { getCurrentTreeVariants } from "./utils"

export function useCreateMotionContext(
props: MotionProps,
isStatic: boolean
): MotionContextProps {
export function useCreateMotionContext(props: MotionProps): MotionContextProps {
const { initial, animate } = getCurrentTreeVariants(
props,
useContext(MotionContext)
)

return useMemo(
() => ({ initial, animate }),
/**
* Only break memoisation in static mode
*/
isStatic
? [
variantLabelsAsDependency(initial),
variantLabelsAsDependency(animate),
]
: []
[variantLabelsAsDependency(initial), variantLabelsAsDependency(animate)]
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the useMemo needed at all if we break it?

And shall we add a comment as to why we intentionally break the memoization in some cases?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't feel like it's necessary. We only generate a new context object when its contents change, it feels like a relatively straightforward use of memoisation.

)
}

Expand Down