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] State updates still interrupting layout animations #1085

Open
rijk opened this issue Apr 2, 2021 · 8 comments
Open

[BUG] State updates still interrupting layout animations #1085

rijk opened this issue Apr 2, 2021 · 8 comments
Labels
bug Something isn't working

Comments

@rijk
Copy link

rijk commented Apr 2, 2021

Describe the bug

This was reported in #732 and fixed in #1018 (v3.10.1), but it seems there still is an issue.

CodeSandbox reproduction of the bug

https://codesandbox.io/s/9eh9p?file=/src/Modal.tsx

Steps to reproduce

Steps to reproduce the behavior:

  1. Click on a blue square
  2. ☑️ Open animation no longer interrupted by state updates
  3. Close modal
  4. ❌ Close animation is interrupted by state update, comment icon seems to start new animation with default transition, border radius does not return to 10:
Screen.Recording.2021-04-02.at.10.48.02.mov

Expected behavior

Comment out the useEffect in Modal.tsx to see the expected behaviour:

Screen.Recording.2021-04-02.at.10.47.17.mov
@rijk rijk added the bug Something isn't working label Apr 2, 2021
@rijk
Copy link
Author

rijk commented Jun 8, 2021

Update: while debugging I found out that this only happens when the element that is animating out (the modal in my example) does not have an exit prop. So it can be fixed for now by adding something like exit={{ opacity: 1 }} to the element. Not sure if this is by design (@mattgperry?), but I'll submit a PR to change this because I think it's very unintuitive in either case.

@rijk
Copy link
Author

rijk commented Jun 8, 2021

What actually happens is on the state update of the child that is being exited, the transition switches to that of the following child. In this example you see the transition actually becoming slower instead of faster: https://codesandbox.io/s/framer-motion-state-update-during-layout-transition-issue-9eh9p?file=/src/Test.tsx

@rijk
Copy link
Author

rijk commented Aug 30, 2021

Fixed in 4.1.18-rc.26 (Sandbox), but broken again on 5.0.0-beta.22 (Sandbox):

Screen.Recording.2021-08-30.at.11.56.35.mov

Edit: still happens on rc.1: https://codesandbox.io/s/framer-motion-state-update-during-layout-transition-issue-on-v5-0-0-rc-1-kqf50?file=/package.json

@rijk rijk mentioned this issue Aug 30, 2021
15 tasks
@rijk
Copy link
Author

rijk commented Sep 6, 2021

Here's another issue: https://codesandbox.io/s/framer-motion-v5-5-0-layout-animation-reset-on-state-update-76l4n

Screen.Recording.2021-09-06.at.14.38.58.mov

Note that the lead element is reset to its starting position on a React state update.

@rijk
Copy link
Author

rijk commented Oct 23, 2021

On 5.0.0-rc.1 we are getting even funkier behaviour:

Screen.Recording.2021-10-23.at.18.31.34.mov

@rijk
Copy link
Author

rijk commented Oct 24, 2021

Here is a more minimal reproduction without Portal: https://codesandbox.io/s/framer-motion-v5-0-0-layout-transition-funkiness-lbfff?file=/src/App.tsx

To see the working as intended behaviour, comment out the useEffect in Modal.tsx to disable the internal state updates.


Also the original issue still happens on rc.1: https://codesandbox.io/s/framer-motion-state-update-during-layout-transition-issue-on-v5-0-0-rc-1-kqf50?file=/package.json

@trurl-master
Copy link

trurl-master commented Nov 25, 2021

I stumbled upon a similar problem, here's another (a little bit smaller) reproduction that may be relevant - https://codesandbox.io/s/framer-rerender-issue-1cmcf

5.3.3 - the non-memoized version of the component is very jittery
4.1.18-rc.26 - works perfectly
4.1.18-rc.25 and down (including 4.1.17) - not jittery, but onLayoutAnimationCallback fires on every render

Screen.Recording.2021-11-25.at.23.22.50.mov

@mattgperry
Copy link
Collaborator

It's also preferable to add layoutDependency to these elements as they will skip being measured entirely.

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