[BUG] AnimatePresence initial={false} is applied to all components below it in the render tree
See original GitHub issue2. Describe the bug
<AnimatePresence initial={false}>
suppresses initial state for all motion components below it in the render tree, not just descendants with exit
props.
The result is that at any arbitrary depth below an <AnimatePresence initial={false}>
, initial
motion state is suppressed.
In my case, I was trying to use initial
to set initial state for animation controls. After struggling for a long time to figure out why this initial state was not rendering, I finally figured out it was due to an AnimatePresence
way, way higher up in the render tree, responsible for animating route transitions.
3. IMPORTANT: Provide a CodeSandbox reproduction of the bug
Please see https://codesandbox.io/s/animatepresence-initialfalse-037n8?file=/src/App.js:1159-1180. Notice how the variant on line 18 is not applied on first render.
4. Steps to reproduce
Please see CodeSandbox above.
5. Expected behavior
initial={false}
from AnimatePresence
should apply only up to the depth of the first descendants that are encountered with an exit prop. After that, initial effects should still work, at least for motion components controlled by Animation Controls, where settings initial state seems to be required for animating later anyway. Or maybe something like how
These changes in variant will flow down until a child component defines its own animate property.
(which, however, does not work with controls, so maybe that’s an issue here too).
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (4 by maintainers)
Top GitHub Comments
Treating this as a
wontfix
for now. Adding anAnimatePresence
barrier here is totally supported. The problem is, anyexit
animations within the tree are counted towards the removal of it. This works whether there are multiple top-levelmotion
components within a tree, or the top-level components don’t have anexit
prop but other children do.As a result it is intentional that
initial
would also apply equally to the same children, bearing in mind that this component is used for controlling presence animations, not just exit animations.Makes sense. Thank you @InventingWithMonster, @blasterpistol