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] AnimatePresence gets stuck when state changes quickly #2554

Open
tommhuth opened this issue Mar 13, 2024 · 32 comments
Open

[BUG] AnimatePresence gets stuck when state changes quickly #2554

tommhuth opened this issue Mar 13, 2024 · 32 comments
Labels
bug Something isn't working

Comments

@tommhuth
Copy link

tommhuth commented Mar 13, 2024

2. Describe the bug
Framer Motion v11.0.12: When state changes very quickly AnimatePresence gets stuck and out of sync and no longer removes the element but instead always animates it in. Reverting to version v10.12.2 (based of other bug report concerning a similar/same issue) does not exhibit the same problem

3. IMPORTANT: Provide a CodeSandbox reproduction of the bug
https://codesandbox.io/p/sandbox/serene-brattain-qwd278

4. Steps to reproduce

  1. Conditionally render an element inside AnimatePresence with an exit animation
  2. Trigger condition change quickly
  3. Animating component gets stuck as rendered, and any changes to the condition will just trigger an reset from initial => animate. The component is no stuck as visible and will never leave the DOM.

5. Expected behavior

The component should not get stuck as mounted

6. Video or screenshots

If applicable, add a video or screenshots to help explain the bug.

7. Environment details

Chrome 122, Mac Sonoma

@tommhuth tommhuth added the bug Something isn't working label Mar 13, 2024
@justrealmilk
Copy link

Your code sandbox is broken

@Roon311
Copy link

Roon311 commented Mar 14, 2024

I am encountering the same issue
When the state changes quickly resolved changes to undefined.

3fcf8351-a7be-482b-8864-c3eb0dc729f1

@mattgperry
Copy link
Collaborator

Thanks for the sandbox - are you able to set it to public so I can take a look?

@Roon311
Copy link

Roon311 commented Mar 14, 2024

@mattgperry When you use the right arrown to navigate through the animating images, the error shows up

@notmedia
Copy link

notmedia commented Mar 14, 2024

@Roon311 your link is also unavailable

Unable to access this workspace
It is likely that you are not a member of the team that this project belongs to. To be able to access the web editor of this repository and edit the code, you need to be invited to the team.

@justrealmilk
Copy link

justrealmilk commented Mar 14, 2024

Okay now that I know why it breaks I can actually trigger the problem https://codesandbox.io/p/sandbox/modern-wood-h35hc6

Click page/back until it breaks I guess

@Roon311
Copy link

Roon311 commented Mar 14, 2024

@notmedia It should be working now.
if you keep pressing the right arrow you will get the error.

@OlegWock
Copy link

OlegWock commented Mar 17, 2024

Here is another reproduction. Double click the button to see it

https://stackblitz.com/edit/framer-motion-animate-presence-bug?file=src%2FHoldToConfirm.tsx

I can confirm that framer motion 11.0.8 works correctly with same code

@tommhuth
Copy link
Author

sorry about that, https://codesandbox.io/p/sandbox/serene-brattain-qwd278 is now public

@eryilmazyasin
Copy link

eryilmazyasin commented Mar 20, 2024

I have the same problem and still could not find the solution. It happened after version 11.0.8. Here is my example and code below.

      <AnimatePresence>
                    {open && (
                        <motion.div
                            key="contentMarkContainer"
                            initial={{ opacity: 0, position: 'absolute', bottom: 0, left: 0, right: 0 }}
                            animate={{ opacity: 1 }}
                            exit={{ opacity: 0, transition: { ease: 'easeOut', duration: 0.75 } }}
                        >
                            {My codes here...}
                         </motion.div>
                         )}
        </AnimatePresence>
Screen.Recording.2024-03-20.at.13.53.11.mov

@iravid
Copy link

iravid commented Mar 26, 2024

This appears to have been broken in 11.0.11. Last version that doesn't suffer from this issue is 11.0.10.

@ConsoleTVs
Copy link

This appears to have been broken in 11.0.11. Last version that doesn't suffer from this issue is 11.0.10.

Correct. Just checked!

@federicocappellotto97
Copy link

Same here, using "framer-motion": "^11.0.25"

@HHogg
Copy link

HHogg commented Apr 11, 2024

Just linking for reference as I was linked to Issue #2023 first. We're also seeing this on 11.0.24.

@pklada
Copy link

pklada commented Apr 11, 2024

Does anyone have a workaround for this? It breaks for us too

@ConsoleTVs
Copy link

Does anyone have a workaround for this? It breaks for us too

Fix it to 11.0.10

@Roon311
Copy link

Roon311 commented Apr 11, 2024

@pklada
Reverting to version v10.12.2 worked for me.

@6thpath
Copy link

6thpath commented Apr 12, 2024

@pklada Reverting to version v10.12.2 solved worked for me.

10.12.2 does not work for me, 11.0.10 does

@pklada
Copy link

pklada commented Apr 12, 2024

I'd prefer not to revert if possible as we're relying on some more recent fixes. Would be nice if there was some update on this specific issue as it seems like it is affecting a number of others

@pklada
Copy link

pklada commented Apr 12, 2024

@mattgperry do you have any thoughts or should i just downgrade for now?

@luluxia
Copy link

luluxia commented Apr 18, 2024

I have the same issue.
https://codesandbox.io/p/devbox/great-brattain-hc9kgz
but i found using non-repeating key can solve it.

@kangju2000
Copy link

@VrTech
Copy link

VrTech commented Apr 18, 2024

I have the same issue. https://codesandbox.io/p/devbox/great-brattain-hc9kgz but i found using non-repeating key can solve it.

Good find!
Using count as key can hot fix this for now
const [count, setCount] = useState(0);
or reverting to 11.0.10 works as well.

@Thanaen
Copy link

Thanaen commented Apr 18, 2024

I have the same issue. https://codesandbox.io/p/devbox/great-brattain-hc9kgz but i found using non-repeating key can solve it.

I can reproduce the bug in this codesandbox, just click quickly enough
framer-bug

@luluxia
Copy link

luluxia commented Apr 18, 2024

I have the same issue. https://codesandbox.io/p/devbox/great-brattain-hc9kgz but i found using non-repeating key can solve it.

I can reproduce the bug in this codesandbox, just click quickly enough

change the key attribute in line 21 will fix it. I wrote a comment there.

@Thanaen
Copy link

Thanaen commented Apr 18, 2024

@luluxia Ouuups, I thought the sandbox applied the fix, sorry! 😄

@VrTech
Copy link

VrTech commented Apr 19, 2024

@luluxia However, I found out the solution is not working with staggering children. :(

@RareSecond
Copy link

Am experiencing the exact same issue, but in a different setup. There seem to be cases where exit is never called, and the potential for it not being called seems to be indeed tied to opacity. If I remove the opacity on my exit, it will always get called.

Here's an example. If you slowly hover over the dots on the right, it works as expected. However, once you start going faster, it sometimes bugs and multiple divs remain visible

image

Important part is that, if you remove opacity from the exit animation, it will work perfectly fine

@Thanaen
Copy link

Thanaen commented Apr 19, 2024

@RareSecond
This seems to solve the problem of "deleting" the object, but there's still something wrong with it
With opacity:
framer-presence-issue

Without opacity:
framer-bug-bis

@beefchimi
Copy link

Just chiming in to say - I am running into the same issue, and have found that avoiding opacity can get around the problem. A little more context here: #2618 (comment)

psychedelicious added a commit to invoke-ai/InvokeAI that referenced this issue May 6, 2024
There are a number of bugs with `framer-motion` that can result in sync issues with AnimatePresence and the conditionally rendered component.

You can see this if you rapidly click an accordion, occasionally it gets out of sync and is closed when it should be open.

This is a bigger problem with the viewer where the user may hold down the `z` key. It's trivial to get it to lock up.

For now, just remove the animation entirely.

Upstream issues for reference:
framer/motion#2023
framer/motion#2618
framer/motion#2554
hipsterusername pushed a commit to invoke-ai/InvokeAI that referenced this issue May 6, 2024
There are a number of bugs with `framer-motion` that can result in sync issues with AnimatePresence and the conditionally rendered component.

You can see this if you rapidly click an accordion, occasionally it gets out of sync and is closed when it should be open.

This is a bigger problem with the viewer where the user may hold down the `z` key. It's trivial to get it to lock up.

For now, just remove the animation entirely.

Upstream issues for reference:
framer/motion#2023
framer/motion#2618
framer/motion#2554
@quentinlagache
Copy link

quentinlagache commented May 10, 2024

This appears to have been broken in 11.0.11. Last version that doesn't suffer from this issue is 11.0.10.

Let's compare these versions v11.0.10 ➡️ v11.0.11

@pklada
Copy link

pklada commented May 14, 2024

Curious if there is an update here - feels like adding and removing an element quickly with animate presence is quite common and should be supported without any hacks.

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