Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hardware-accelerated opacity animations breaking stacking context #1837

Closed
justrealmilk opened this issue Dec 17, 2022 · 13 comments · Fixed by #1845
Closed

Hardware-accelerated opacity animations breaking stacking context #1837

justrealmilk opened this issue Dec 17, 2022 · 13 comments · Fixed by #1845
Labels
bug Something isn't working

Comments

@justrealmilk
Copy link

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.

@justrealmilk justrealmilk added the bug Something isn't working label Dec 17, 2022
@SamuelQuinones
Copy link

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

@Kawium
Copy link

Kawium commented Dec 20, 2022

I had same problem when I applied motion to my navbar, but I fixed it using z-index.

@mattgperry mattgperry changed the title 7.9.0 (Hardware-accelerated opacity animations) broke my stuff Hardware-accelerated opacity animations breaking stacking context Dec 20, 2022
@mattgperry
Copy link
Collaborator

I can look into this further with a sandbox reproduction.

Can someone try their working animation after applying style={{ x: 1 }}? Does it break in the same way?

screfy added a commit to screfy/screfy.com that referenced this issue Dec 20, 2022
framer-motion should not be updated to the latest version, see: framer/motion#1837
@manfromanotherland
Copy link

Similar issue here, after updating to latest any animations with opacity went crazy. For instance, using AnimatePresence would not animate the exit variant (opacity: 0), the only thing that kind of fixed for me was adding a duration to the exit prop (similar to what @SamuelQuinones did).

Downgraded for now because most of my animations were using opacity.

@enjidev
Copy link

enjidev commented Dec 20, 2022

I can look into this further with a sandbox reproduction.

Can someone try their working animation after applying style={{ x: 1 }}? Does it break in the same way?

Same issue here. I just tried to update to v7.10.2, but suddenly the opacity didn't animate.

https://github.com/enjidev/enji.dev/blob/main/src/components/shared/Header/PageHeader.tsx

@mattgperry
Copy link
Collaborator

Happy to take a look, please reopen with a sandbox.

@ruvkr
Copy link

ruvkr commented Dec 22, 2022

For me waapi opacity animation not working at all. Forked from official example https://codesandbox.io/s/framer-motion-transitionend-forked-nrt5n1. Downgrading to 7.8.1 or manually setting type: 'spring' fixes the issue.

@mattgperry
Copy link
Collaborator

Thanks @ruvkr!

@mattgperry
Copy link
Collaborator

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.

@ruvkr
Copy link

ruvkr commented Dec 23, 2022

Thank you @mattgperry. Working great now.

@AndreaEsposit
Copy link

I am still experiencing some problems with the stacking context. Is it only me?

@rmoedt
Copy link

rmoedt commented Jan 2, 2023

@AndreaEsposit No have the same issue still. But didn't take the time yet to create a sandbox example.

@hiddenest
Copy link

@mattgperry Hi, I've created another issue caused by hardware-accelerated opacity animations. Could you check this issue?
#1885

I've just attached some codesandbox and some codebases.
btw, I couldn't reopening this issue because i didn't opened this issue :-(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants