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] Stagger animation does not occur when children has a "whileHover" animation

See original GitHub issue

1. Read the FAQs 👇 ✅ 👍 2. Describe the bug

Hey there 👋 I found this little bug after updating from framer-motion 2.6.13 to 3.1.1. The following component had both a “stagger children” animation (very similar to the one provided in your documentation as an example) and each child also had a whileHover animation (hovering a child in the list would add some marginRight to it). While this used to work in Framer Motion 2.6.13, upgrading to 3.1.1 showcased a weird behavior: the stagger animation does not happen if the child has a whileHover animation

 const list = {
    hidden: { opacity: 0 },
    visible: {
      opacity: 1,
      transition: {
        // delayChildren: 1.5,
        staggerChildren: 0.15
      }
    }
  };

  const item = {
    hidden: { opacity: 0 },
    visible: { opacity: 1 },
    hover: {
      marginRight: "5px",
      transition: { ease: "easeOut" }
    }
  };

  return (
    <>
      <motion.ul
        style={{
          display: "flex",
          flexWrap: "wrap",
          marginLeft: "0px",
          marginBottom: "8px",
          marginTop: "15px"
        }}
        initial="hidden"
        animate="visible"
        variants={list}
      >
        {replies.map((reply) => (
          <motion.li
            key={reply.id}
            data-testid={reply.id}
            variants={item}
            /** Uncomment this to see the issue, this used to work in framer-motion 2.6.13! */
            // whileHover="hover"
          >
            foo
          </motion.li>
        ))}
      </motion.ul>
    </>
  );
};

3. IMPORTANT: Provide a CodeSandbox reproduction of the bug

Here’s a full example showcasing this behavior on the latest version: https://codesandbox.io/s/practical-fermi-4f9k0?file=/src/App.js

4. Steps to reproduce

Steps to reproduce the behavior:

  1. Go to the codesandbox ☝️
  2. Notice the staggered animation occurs as expected 👍
  3. Uncomment the whileHover statement and refresh
  4. Notice that now, the whole list simply fades in, no staggered animation occurs

5. Expected behavior

I might be doing something wrong, and maybe my previous implementation simply worked out of sheer luck (totally possible), or maybe there’s something wrong, but this is the only weird behavior that I’ve noticed after upgrading and I’d like to understand why it happens if it’s not a bug.

Of course, this is not pressing at all, please enjoy your holidays first 🙏 consider this ticket as low priority

6. Video or screenshots

https://user-images.githubusercontent.com/2974412/103183308-7f605c00-487f-11eb-86c9-d11dd4fe1e92.mov

7. Environment details

Browser: Chrome OS: macOS Big Sur Framer Motion: 3.1.1

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
mattgperrycommented, Jan 5, 2021

An underlying problem here that might be a show-stopper is as I make this code more concurrent mode-safe one of the things I’ve had to do is make components in a given variant tree re-render whenever a parent does. If I made this work on a per-prop basis you’d essentially have the whole motion tree re-render whenever a variant changes.

2reactions
KirdesMFcommented, Dec 28, 2020

if you want a workaround, you can set the whileHover prop without variants, and remove the “hover” object from the item variants

 whileHover={{
              marginRight: "5px",
              transition: { ease: "easeOut" }
            }}

https://codesandbox.io/s/practical-dan-xcsrx?file=/src/App.js

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't stagger ngAnimate child animations - Stack Overflow
I was able to make this work by applying the animation delay to the parent element (even though it is the child that...
Read more >
How To Use Framer Motion With React, TypeScript and Styled ...
To prepare the animation we have to use the animate property. It should be added to the motion component (in this case it...
Read more >
How to Create React Animations With Framer Motion
In the below example, I have used whileHover prop. When a user hovers over the component, it will scale and set the opacity...
Read more >
Advanced animation patterns with Framer Motion
Framer Motion allows variants to "flow down" through every motion child component as long as these motion components do not have an animate...
Read more >
Transition | Framer for Developers
A transition defines how values animate from one state to another. ... When using variants, children animations will start after this duration (in...
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