motiondivision / motion

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

[BUG] Drag animation starts with component's initial styles when parent AnimatePresence has initial disabled #2831

Open TWaltze opened 1 month ago

TWaltze commented 1 month ago

1. Read the FAQs 👇

2. Describe the bug

Children of <AnimatePresence initial={false}> that have drag enabled start their drag animation with their initial animation styles rather than their animate styles.

3. IMPORTANT: Provide a CodeSandbox reproduction of the bug

This is a rough POC of a drawer component that can be dragged downwards.

https://codesandbox.io/p/sandbox/d3493p

4. Steps to reproduce

  1. Click and hold the blue drag handler
  2. Drag down

5. Expected behavior

The drag animation should start from the top of the page (set via its animate styles).

Instead, when the drag initiates the drawer jumps to its initial animation styles. This only happens on the first drag. If you drag a second time (which presumably animates it outside of initial={false}), it works as expected. Setting initial={true} also has the drag animation working as expected.

6. Video or screenshots

https://github.com/user-attachments/assets/afc081fc-c6fe-43ea-af7a-6e87d50cd07e

7. Environment details

Mac OS 14.6.1, Chrome 128