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] A motion element with the layout flag with an AnimatePresence sibling does not transition smoothly

See original GitHub issue

1. Read the FAQs 👇 👍

2. Describe the bug

A motion element with the layout flag with an AnimatePresence sibling does not transition smoothly when the AnimatePresence element is removed. It will animate nicely on enter but not exit.

I may be doing something wrong here, but I would expect this to work.

If I move the layout div inside the AnimatePresence then it does work as expected, but this is not always possible.

3. IMPORTANT: Provide a CodeSandbox reproduction of the bug

https://codesandbox.io/s/framer-motion-simple-animation-forked-6m9ej?file=/src/index.tsx

4. Steps to reproduce

Steps to reproduce the behavior:

    <div className="container">
      <Refresh onClick={toggle} />
      <AnimatePresence>
        {show && (
          <motion.div
            key="1"
            className="example-container"
            animate={{ opacity: 1 }}
            exit={{ opacity: 0 }}
            onClick={toggle}
          ></motion.div>
        )}
      </AnimatePresence>
      <motion.div
        onClick={toggle}
        key="2"
        className="example-container"
        layout
      ></motion.div>
    </div>

5. Expected behavior

The bottom motion div should animate smoothly when the top one is removed from the dom.

6. Video or screenshots

I think the codesandbox is easy enough to understand

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
rbourdoncommented, Nov 19, 2021

You can fix this by wrapping everything in a <LayoutGroup>

example

0reactions
mattgperrycommented, Nov 19, 2021

Ah yeah I see, thanks for clarifying

On Fri, 19 Nov 2021 at 19:28, rickyhopkins @.***> wrote:

The code does not work as expected, both squares fade out as expected but only one is removed from the dom as expected.

Here is the three items in the dom: [image: image] https://user-images.githubusercontent.com/4586254/142680268-f04e2f03-97ce-428e-92ba-730438a14171.png

And here is the dom after AnimatePresence should have run on 2 of them: [image: image] https://user-images.githubusercontent.com/4586254/142680341-d6f81060-fc30-4a64-afad-13fed82e419f.png

And I actually got it backwards in this example, the wrapped Item square is removed but the inline one does not.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/framer/motion/issues/1358#issuecomment-974350552, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB34WKQFZ5MGYLACUIATZSTUM2QODANCNFSM5IKNQ7XA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

Read more comments on GitHub >

github_iconTop Results From Across the Web

AnimatePresence | Framer for Developers
AnimatePresence works by detecting when direct children are removed from the React tree. Any motion components contained by the removed child that have...
Read more >
Animation Techniques for Adding and Removing Items From a ...
Applying CSS-only animations to a dynamic DOM event (adding brand new elements and fully removing elements) is extremely tricky work. We're ...
Read more >
Everything about Framer Motion layout animations
A complete guide to Framer Motion layout animations showcasing every concept, from the layout prop, shared layout animations and LayoutGroup ...
Read more >
Stagger Siblings in Framer Motion to perform Share Buttons ...
Stagger Children. Flexbox shouldn't prevent you from using staggerChildren . To use staggerChildren you add it to the transition property of ...
Read more >
Exit animation with `framer-motion` demystified
Unlike Svelte which has built-in animation and transition, React does not. If you have worked with... Tagged with tutorial, react, ...
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