question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] AnimatePresence initial={false} is applied to all components below it in the render tree

See original GitHub issue

2. 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:closed
  • Created 3 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
mattgperrycommented, Aug 25, 2020

Treating this as a wontfix for now. Adding an AnimatePresence barrier here is totally supported. The problem is, any exit animations within the tree are counted towards the removal of it. This works whether there are multiple top-level motion components within a tree, or the top-level components don’t have an exit 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.

0reactions
dminkovskycommented, Aug 25, 2020

Makes sense. Thank you @InventingWithMonster, @blasterpistol

Read more comments on GitHub >

github_iconTop Results From Across the Web

AnimatePresence | Framer for Developers
AnimatePresence allows components to animate out when they're removed from the React tree. It's required to enable exit animations because React lacks a ......
Read more >
javascript - Animate presence not working in next js for exit ...
<AnimatePresence> needs to wrap the component that's being conditionally rendered. It can't be inside it.
Read more >
Page Transitions with React Router and Framer Motion
Whats up everyone ! Hope you all are doing well. In this episode we create a really cool page transition using framer motion...
Read more >
Animation with Framer-Motion - #6 AnimatePresence - YouTube
Get the starter project to follow along here: https://github.com/koss-lebedev/nordic-pixelsCheatsheet explaining the differences between ...
Read more >
Filtering Item Animation in React with Framer Motion
We wrap the mapping image components with <AnimatePresence /> AnimatePresence ... to animate out when they're removed from the React tree.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found