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] AnimationPresence exit only works on direct descendants

See original GitHub issue

2. Describe the bug

Exit animation doesn’t work unless motion component is a direct descendant of AnimationPresence

3. IMPORTANT: Provide a CodeSandbox reproduction of the bug

https://codesandbox.io/s/peaceful-margulis-lnc6b

4. Steps to reproduce

  • Click the +/- buttons and the animations should work as expected.
  • Then uncomment the lines 9 and 20
  • Click the +/- buttons, the animation on mount works but the exit animation no longer works

5. Expected behavior

Exit animation to still work even if it’s not a direct descendent

7. Environment details

OS: macOs Catalina Browser: Chrome 78.0.3904.70

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7

github_iconTop GitHub Comments

6reactions
deletemecommented, Jun 15, 2020

The documentation has an example that matches this use case, but it does not mention anything about the exit animation not working. The presence of the exit prop implies that it is possible to animate the exit transition of nested motion components.

https://www.framer.com/api/motion/animate-presence/#animating-custom-components

const Item = () => (
  <div>
    <motion.div
      initial={{ opacity: 0 }}
      animate={{ opacity: 1 }}
      exit={{ opacity: 0 }}
    />
  </div>
)

export const MyComponent = ({ items }) => (
  <AnimatePresence>
    {items.map(({ id }) => (
      <Item key={id} />
    ))}
  </AnimatePresence>
)
2reactions
mattgperrycommented, Dec 5, 2019

This is as per design. By uncommenting those lines you give AnimatePresence a single child which is never added or removed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

AnimatePresence | Framer for Developers
Exit animations. AnimatePresence works by detecting when direct children are removed from the React tree. Any motion components contained by the removed child ......
Read more >
javascript - Animate presence not working in next js for exit ...
I'm trying to set an exit animation to my components in next js but I'm only able to give an initial animation. Can...
Read more >
Advanced page transitions with Next.js and Framer Motion
One key point here is to make sure your animated elements are direct children of AnimatePresence so that it can take over and...
Read more >
Collapsible table rows with Framer Motion layout animations
This is an unscripted chat & exploration of some different approaches for animating table rows, which are harder to animate than normal div ......
Read more >
Updates
Animate Presence — Small update: exitBeforeEnter is now mode="wait" . ... for a bug; Animate Presence — Currently only partially works in overrides, ......
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