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

Fix render scheduling #2485

Merged
merged 12 commits into from
Jan 23, 2024
Merged

Fix render scheduling #2485

merged 12 commits into from
Jan 23, 2024

Conversation

mattgperry
Copy link
Collaborator

@mattgperry mattgperry commented Jan 10, 2024

Fixes #2476

Layout animations were moved to trigger behind queueMicrotasks as this allowed us to remove querySelectors and, if states were set synchronously in a useLayoutEffect (common within Framer sites) we could skip a bunch of needless animations by deferring layout animations until the end of the event queue.

Although still "synchronous" in terms of still blocking render, it is asynchronous in the sense that other things can now happen before it. One of these "things" was the .render() call in useVisualElement which synchronously renders any changes within motion values after a render. This meant a render was inserted before layout animation measurements that led to surprising transform values being rendered when we came to measure elements.

This PR moves that also to a queueMicrotasks, which will fixes this class of bugs but also allow us to skip a bunch of needless renders.

As a result of .render() now being technically asynchronous this PR also updates a bunch of tests to wait the end of the event queue before measuring the DOM.

Perhaps this needs to be a major bump? As it might affect the tests people have written for components.

@mattgperry mattgperry added the automerge Land this PR label Jan 23, 2024
@mergetron mergetron bot merged commit 93931a0 into main Jan 23, 2024
1 check passed
@mergetron mergetron bot deleted the fix/queue-microtasks branch January 23, 2024 11:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Land this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] queueMicrotasks layout animations
2 participants