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.

Hardware-accelerated opacity animations breaking stacking context

See original GitHub issue

I build a companion app for the video game Destiny 2 called Bray.tech. I blindly updated my packages a few days ago because I enjoy gambling. I’ve spent hours fiddling with CSS before giving up and going through my packages one by one version by version to find the culprit. I found no issues up until 7.9.0.

So, the issue: wherever I use a motion component which animates opacity, stacking contexts everywhere go wild causing very unwanted and possibly unnecessary behaviours on neighbours and children, as well the browser skipping steps like the backdrop-filter property for the acrylic look.

Here’s a drop-down menu lookin’ nice:

not-before

Here’s the same drop-down but its parent and its parent’s neighbours animated on opacity.

before

Here’s some code - commenting out opacity properties fixes it but opacity is like key to transitional animations so:

export const VariantDrop: Variants = {
  initial: (options: CustomOptions = {}) => ({
    opacity: 0,
    y: options?.reverse ? -16 : 16,
  }),
  animate: (options: CustomOptions = { transition: {} }) => ({
    opacity: 1,
    y: 0,
    transition: {
      duration: 0.5,
      ease: [0.33, 1, 0.68, 1],
      ...options.transition,
    },
  }),
  exit: (options: CustomOptions = { transition: {} }) => ({
    opacity: 0,
    y: options?.reverse ? -16 : 16,
    transition: {
      duration: 0.5,
      ease: [0.33, 1, 0.68, 1],
      ...options.transition,
    },
  }),
};

export function Div({ children, variant = 'drop', options, ...props }: Props & Pick<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, CommonProperties>) {
  return (
    <motion.div custom={options} variants={Variant[variant]} initial={undefined} {...props}>
      {children}
    </motion.div>
  );
}

As frustrated as I’ve found this experience, I’m very happy that I can now reproduce the bug consistently. Video available on request.

Issue Analytics

  • State:closed
  • Created 9 months ago
  • Reactions:1
  • Comments:10

github_iconTop GitHub Comments

1reaction
mattgperrycommented, Dec 23, 2022

This has been closed thanks to a fix about to go out in 8.0.2 for @ruvkr’s example, however I suspect there is a separate issue still here with stacking context. Please reopen with a sandbox example if this is still a problem.

1reaction
SamuelQuinonescommented, Dec 19, 2022

I also encountered this when bumping deps and had to roll back ultimately. Adding a duration to the transition involving opacity kind of worked but only for very simple transitions, I thought i was going nuts so I am glad to see that someone else has the same issue and came to the same conclusion I did - that it had to do with the hardware acceleration

Read more comments on GitHub >

github_iconTop Results From Across the Web

While animating opacity, z-index not respected - Stack Overflow
I'm on my first SVG "montage" animation and I have this little problem. 3 elements positioned "absolute" with corresponding z-index.
Read more >
1223658 - Compositor animations with delay arrive at the ...
Bug 1223658 - Part 7: Reftests for checking stacking context when changing keyframe and target directly in delay phase. 7 years ago. Hiroyuki...
Read more >
Let's Play With Hardware-Accelerated CSS
Build, ship, and host full-stack apps in hours. Learn more. To animate the slides to snap into view, we'll define an extra class,...
Read more >
What No One Told You About Z-Index (2013) - Hacker News
Stacking contexts aren't about hardware acceleration. They're needed for things like opacity to work at all. (Think about the alpha blending ...
Read more >
An Interactive Guide to CSS Transitions - Josh W Comeau
The main ingredient we need to create an animation is some CSS that changes. ... transition: transform 250ms, opacity 400ms;. } .btn:hover {....
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