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

[BUG] Framer Motion Animation doesn't work on reload without delay #2598

Open
KonerDev opened this issue Mar 26, 2024 · 6 comments
Open

[BUG] Framer Motion Animation doesn't work on reload without delay #2598

KonerDev opened this issue Mar 26, 2024 · 6 comments
Labels
bug Something isn't working

Comments

@KonerDev
Copy link

KonerDev commented Mar 26, 2024

1. Read the FAQs πŸ‘‡
βœ…

2. Describe the bug

If I have two components that should be animated as soon as they are visible, they will not be animated when I reload the page with CTRL + R. Only when I reload the page with CTRL + SHIFT + R the animation appears.

3. IMPORTANT: Provide a CodeSandbox reproduction of the bug

Unfortunately I couldn't reproduce the bug in CodeSandbox because the reload mechanism seems to work differently there, but the bug is also there in Stackblitz.
https://stackblitz.com/edit/vitejs-vite-cbkvjz?file=src%2FApp.jsx&terminal=dev

4. Steps to reproduce
Steps to reproduce the behavior:

  1. Open https://stackblitz.com/edit/vitejs-vite-cbkvjz?file=src%2FApp.jsx&terminal=dev
    and then https://vitejsvitecbkvjz-evfn--5173--d0228c83.local-credentialless.webcontainer.io (the second url is just the fullscreen version)
  2. In the second url click on connect project after a few seconds
  3. Press CTRL + R or click on the reload button of your browser
  4. The animation doesn't really work

If you press CTRL + SHIFT + R, the animation will work fine.

5. Expected behavior

When I reload the page the animation should run normally, even without shift.

6. Video or screenshots

---

7. Environment details
Windows 11 23H2; Chrome 123.0.6312.59

@KonerDev KonerDev added the bug Something isn't working label Mar 26, 2024
@mikirejf
Copy link

I'm observing something similar in our app. An animation plays if a route is freshly loaded, but sometimes won't play if I navigate between the route and some other route.

Will provide more information when I dig deeper. Sadly, I can't manage to reproduce it in a sandbox.

@KonerDev
Copy link
Author

It's very difficult to reproduce the problem, but I just use a delay of 0.25, which at least temporarily solves the problem

@mattgperry
Copy link
Collaborator

My suspicion is that this is a bug in Chrome - specifically this one https://issues.chromium.org/issues/40887505

If you put an onUpdate on the animations you'll see the frames do fire, Chrome doesn't paint them.

@mikirejf
Copy link

mikirejf commented Mar 27, 2024

For me it's also happening in FF and Safari.

These are my motion props:

initial={{ transform: 'scale(0)', opacity: 0.8 }}
animate={{ transform: 'scale(1)', opacity: [0.8, 1, 1, 0] }}
transition={{
  transform: { delay: 0.3, type: 'spring', stiffness: 300, damping: 15 },
  opacity: {
    delay: 0.3,
    duration: 2.2,
    times: [0, 0.13, 0.95, 1],
    ease: 'easeInOut',
  },
}}

Until 11.0.10, the element would at least appear in the DOM (without scale animating), and onUpdate was firing.

Starting with 11.0.11, onUpdate isn't firing at all.

@mattgperry
Copy link
Collaborator

Ahh ok thanks for the additional info - I'll take a look

@KonerDev
Copy link
Author

KonerDev commented Mar 28, 2024

My suspicion is that this is a bug in Chrome - specifically this one https://issues.chromium.org/issues/40887505

If you put an onUpdate on the animations you'll see the frames do fire, Chrome doesn't paint them.

Yes, that seems to be exactly my issue. Is there anything I can do to solve the problem temporarily other than a delay of 0.25 as it's not a nice solution to the problem. Is it possible to check whether the object has been painted and then start the animation?

EDIT: The error does not occur in Firefox

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

No branches or pull requests

3 participants