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

Loading multiple copies of framer-motion breaks in subtle ways #477

Closed
jscheel opened this issue Mar 10, 2020 · 3 comments · Fixed by #1565
Closed

Loading multiple copies of framer-motion breaks in subtle ways #477

jscheel opened this issue Mar 10, 2020 · 3 comments · Fixed by #1565
Labels
bug Something isn't working

Comments

@jscheel
Copy link

jscheel commented Mar 10, 2020

I have a situation where I use framer-motion in a ui library package and in a project that installs that package as a dependency.

With react, if you try to use hooks in both places, it will throw an error because the hooks will be overwritten. Here's an issue about that: facebook/react#14257 (comment).

Basically, for local development, the preferred method is to make react a peerDependency, and then npm|yarn link it so that you only ever have one copy. Here's a great article on that: https://yvonnickfrin.dev/handling-peer-dependencies.

For framer-motion, I discovered a subtle bug. If I provide a motionValue from my library, and then try to use it in my project, it works, but not exactly right. The motion value is updated, and any transforms I create with it are updated as well. But any motion components that I pass the transform into (via the style prop) do not get updated. I'm not 100% certain why this is, but using only a single yarn linked version of the framer-motion makes everything happy again.

I'm guessing it would be best for framer-motion to detect if it has been included multiple times and then throw an error or warning, just like react does.

@jscheel jscheel added the bug Something isn't working label Mar 10, 2020
@bercos
Copy link

bercos commented Oct 30, 2020

I'm having a similar but less subtle bug. If I bundle a react component with a framer-motion styled component (tested using parcel and rollup) and then use that component in a separate react application (served using parcel) I get an invalid hook call error (attached below).

Screen Shot 2020-10-30 at 12 39 31 PM

@nikoferro
Copy link

Leaving a +1 here. Spent a couple of hours today debugging in the shadows while getting the invalid hook error on a NextJS + Internal library case, where both use framer-motion. I think having a message warning about the different versions would be great.

In the meantime, i got to solve it following @jscheel recommendation

but using only a single yarn linked version of the framer-motion makes everything happy again.

@morecommits
Copy link

morecommits commented Feb 1, 2021

@bercos I am facing the same error atm when using electron-webpack. Did you ever find a solution?

@mattgperry mattgperry added wontfix This will not be worked on and removed wontfix This will not be worked on labels Jun 1, 2022
@mergetron mergetron bot closed this as completed in #1565 Jun 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants