Skip to content

Conversation

andrewiggins
Copy link
Member

Previously, we would synchronously flush nested renderCallbacks (i.e. setState and forceUpdate callbacks). This behavior meant that nested setState calls would flush before the state was properly applied in diff, meaning DOM, props, etc. wouldn't have been updated for that setState call when the callback was run (though the state would be correct due to a shortcut we took).

This PR fixes this behavior by only invoking the renderCallbacks for the current setState call synchronously. Nested setState callbacks are queued and executed when those setState calls are applied.

Also includes a small change to make setState and forceUpdate a little more similar which I assume helps gzip.

Previously, we would synchronously flush nested renderCallbacks. This behavior meant that nested setState calls would flush before there state was properly applied in diff, meaning DOM, props, etc. wouldn't have been updated for that setState call when the callback was run (though the state would be correct due to a shortcut we took).

This PR fixes this behavior by only invoking the renderCallbacks for the current setState call synchronously. Nested setState callbacks are queued and executed when those setState cals are applied.
@andrewiggins andrewiggins changed the title Properly flush nested setState callbacks (-5 B) Properly flush nested setState callbacks (-6 B) Oct 14, 2019
Copy link
Member

@JoviDeCroock JoviDeCroock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!

@JoviDeCroock JoviDeCroock merged commit b46885c into master Oct 14, 2019
@JoviDeCroock JoviDeCroock deleted the fix/nested-setState-callbacks branch October 14, 2019 21:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants