motiondivision / motion

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

[BUG] popLayout does not work with custom components #2798

Closed srph closed 2 months ago

srph commented 2 months ago

1. Read the FAQs 👇

2. Describe the bug

AnimatePresence seems to work as if mode is sync if its direct children are custom components.

You'll see that the other items do not fill the gap of the removed item until its exit animation completes.

3. IMPORTANT: Provide a CodeSandbox reproduction of the bug

https://codesandbox.io/p/sandbox/framer-motion-animatepresence-poplayout-bug-for-indirect-motion-children-5st2vg

4. Steps to reproduce

Steps to reproduce the behavior:

  1. Enable popLayout
  2. Add a number of items
  3. Click any item on the middle
  4. The list does not animate until the exit animation completes

5. Expected behavior

popLayout should work as intended; the list should animate when the exit animation completes

6. Video or screenshots

https://github.com/user-attachments/assets/03fa3bdc-0bcf-42a4-a730-944708eb78d8

7. Environment details

Arc Browser 1.16.3, Windows 11

srph commented 2 months ago

Silly me, I just needed to wrap my component in a forwardRef: https://codesandbox.io/p/sandbox/framer-motion-animatepresence-poplayout-bug-for-indirect-motion-children-forked-pyysgj?workspaceId=6539d639-d3b5-4138-9b69-1355b7069ee6

Sorry folks.