motiondivision / motion

A modern animation library for React and JavaScript
https://motion.dev
MIT License
25.85k stars 849 forks source link

Fix AnimatePresence #2695

Closed wonkyum-kim closed 4 months ago

wonkyum-kim commented 5 months ago

2554

This PR fixes an AnimatePresence bug.

A problem seems to occur if we add a component with the same key while the existing exit animation is not finished.

So I tried a few things to fix it.

I think it worked out well and passed all the tests.

The example below is taken from #2554. (https://codesandbox.io/p/devbox/great-brattain-hc9kgz)

before

https://github.com/framer/motion/assets/67191801/c88ff93c-d61b-45ff-92a4-27bb4262dae1

after

https://github.com/framer/motion/assets/67191801/08e847a6-9463-4056-a3f1-a63353757297

mattgperry commented 4 months ago

Thanks for the PR! Though closing this out as I think this is actually related to interrupting a WAAPI animation so I'm gonna make an E2E test covering this and then publish a fix.