-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[BUG] AnimatePresence exit animations permanently stop working after its component suspends #2690
Copy link
Copy link
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
1. Read the FAQs 👇
2. Describe the bug
If a component that renders an AnimatePresence ever suspends, the exit animations don't work again. I'm not talking about animations that get interrupted by a suspense, but animations that happen at any point in time after the AnimatePresence was suspended and then resumed.
3. IMPORTANT: Provide a CodeSandbox reproduction of the bug
4. Steps to reproduce
Steps to reproduce the behavior:
Consider these components
function App() {
return (
<Suspense fallback={<p>Suspended</p>}>
<MyComponent />
</Suspense>
);
}
function MyComponent() {
const [items, setItems] = useState(() =>
['alice', 'bob', 'carol'].map(name => ({ id: crypto.randomUUID(), name })),
);
return (
<ul>
<AnimatePresence>
{items.map(item => (
<motion.li
key={item.id}
initial={{ x: 100 }}
animate={{ x: 0 }}
exit={{ x: -100 }}
>
{item.name}
<button onClick={() => setItems(items.filter(i => i !== item))}>
x
</button>
</motion.li>
))}
</AnimatePresence>
<button
onClick={() => {
/* do something that causes MyComponent to suspend */
}}
>
Suspend
</button>
</ul>
);
}- Remove an item, the exit animation works
- Cause the component to suspend
- Now try removing an item, the exit animation does not work
(The code sandbox is a better demonstration ☝️ )
5. Expected behavior
Exit animations continue to work after the component has resumed after a suspense
6. Video or screenshots
Screen.Recording.2024-05-30.at.4.47.01.PM.mov
7. Environment details
- Chrome 125.0.6422.78
- MacOS Sonoma 14.5
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working