motion icon indicating copy to clipboard operation
motion copied to clipboard

[BUG] AnimatePresence gets stuck when state changes quickly

Open tommhuth opened this issue 1 year ago • 31 comments
trafficstars

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 avatar Mar 13 '24 16:03 tommhuth

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

3fcf8351-a7be-482b-8864-c3eb0dc729f1

Roon311 avatar Mar 14 '24 11:03 Roon311

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

mattgperry avatar Mar 14 '24 12:03 mattgperry

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

Roon311 avatar Mar 14 '24 13:03 Roon311

@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.

notmedia avatar Mar 14 '24 14:03 notmedia

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

justrealmilk avatar Mar 14 '24 14:03 justrealmilk

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

Roon311 avatar Mar 14 '24 14:03 Roon311

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

OlegWock avatar Mar 17 '24 20:03 OlegWock

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

tommhuth avatar Mar 18 '24 09:03 tommhuth

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>

https://github.com/framer/motion/assets/40694757/2d020827-8537-466c-a1eb-6bd3414be27f

eryilmazyasin avatar Mar 20 '24 10:03 eryilmazyasin

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

iravid avatar Mar 26 '24 15:03 iravid

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!

ConsoleTVs avatar Mar 27 '24 22:03 ConsoleTVs

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

federicocappellotto97 avatar Apr 10 '24 13:04 federicocappellotto97

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

HHogg avatar Apr 11 '24 13:04 HHogg

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

pklada avatar Apr 11 '24 18:04 pklada

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

Fix it to 11.0.10

ConsoleTVs avatar Apr 11 '24 20:04 ConsoleTVs

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

Roon311 avatar Apr 11 '24 22:04 Roon311

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

10.12.2 does not work for me, 11.0.10 does

6thpath avatar Apr 12 '24 05:04 6thpath

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 avatar Apr 12 '24 23:04 pklada

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

pklada avatar Apr 12 '24 23:04 pklada

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

luluxia avatar Apr 18 '24 01:04 luluxia

Same here. (v11.1.3) https://stackblitz.com/edit/vitejs-vite-6vewix?file=src%2FApp.tsx

kangju2000 avatar Apr 18 '24 08:04 kangju2000

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.

VrTech avatar Apr 18 '24 08:04 VrTech

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

Thanaen avatar Apr 18 '24 09:04 Thanaen

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.

luluxia avatar Apr 18 '24 09:04 luluxia

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

Thanaen avatar Apr 18 '24 13:04 Thanaen

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

VrTech avatar Apr 19 '24 08:04 VrTech

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

RareSecond avatar Apr 19 '24 12:04 RareSecond

@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

Thanaen avatar Apr 19 '24 13:04 Thanaen

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: https://github.com/framer/motion/issues/2618#issuecomment-2085488130

beefchimi avatar Apr 30 '24 14:04 beefchimi

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

quentinlagache avatar May 10 '24 13:05 quentinlagache