Fix AnimatePresence keeping exiting children during rapid updates with dynamic variants#3542
Conversation
…tes with dynamic variants When rapidly switching children inside AnimatePresence with dynamic custom variants (where animated properties differ between items), exiting children could get stuck in the DOM. This happened because animateChanges() re-resolved exit variants on every re-render with the latest custom value, starting new value animations that interrupted the originals. Since JSAnimation.stop() doesn't resolve its finished promise, the exit completion chain would hang forever, preventing onExitComplete from firing and leaving elements in the DOM. Fix: skip re-processing the exit animation type in animateChanges() when it's already active and wasn't just explicitly toggled, preserving the running exit animation's promise chain. Fixes #3541 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Code ReviewSummaryThis PR addresses a critical bug where exiting children get stuck in the DOM during rapid AnimatePresence updates with dynamic custom variants. The fix is well-designed, minimal, and correctly targets the root cause. Code Quality ✅Strengths:
Implementation details: The condition is precise:
This prevents re-processing while allowing intentional re-triggering. Test Coverage ✅Excellent test design:
Strengths:
Minor suggestion: Potential Issues
|
Summary
AnimatePresencechildren with dynamic custom variants (where animated properties differ between items)animateChanges()re-resolved exit variants on every re-render with the latestcustomvalue, starting new value animations that interrupted the originals. SinceJSAnimation.stop()doesn't resolve itsfinishedpromise, the exit completion chain hung forever.animateChanges()when it's already active and wasn't just explicitly toggled, preserving the running exit animation's promise chainFixes #3541
Test plan
onExitCompletefires reliably during rapid key switches with dynamic custom variants🤖 Generated with Claude Code