Don't "schedule" discrete work if we're scheduling sync work#18797
Merged
sebmarkbage merged 1 commit intofacebook:masterfrom May 1, 2020
Merged
Don't "schedule" discrete work if we're scheduling sync work#18797sebmarkbage merged 1 commit intofacebook:masterfrom
sebmarkbage merged 1 commit intofacebook:masterfrom
Conversation
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 486b52e:
|
Details of bundled changes.Comparing: ac533fd...486b52e react-dom
react-native-renderer
react-art
react-test-renderer
react-reconciler
react
ReactDOM: size: 0.0%, gzip: 0.0% React: size: 0.0%, gzip: 0.0% Size changes (stable) |
Details of bundled changes.Comparing: ac533fd...486b52e react-dom
react-art
react-test-renderer
react-reconciler
react-cache
react-native-renderer
ReactDOM: size: 0.0%, gzip: 0.0% Size changes (experimental) |
Contributor
|
I created a www sync with this PR: D21348348 (to see if we run into any other issues from this change). |
bvaughn
approved these changes
May 1, 2020
Contributor
bvaughn
left a comment
There was a problem hiding this comment.
Nice find, Seb. This is a better solution than my PR 😄
trueadm
approved these changes
May 1, 2020
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is an alternative fix to #18792. This is a convoluted bug. Settle in.
The problem is that we're adding discrete work during an unmount:
https://github.com/facebook/react/blob/master/packages/react-reconciler/src/ReactFiberWorkLoop.old.js#L463-L480
Normally this is fine because once we complete the unmount we'll clear it here:
https://github.com/facebook/react/blob/master/packages/react-reconciler/src/ReactFiberWorkLoop.old.js#L1879-L1887
That ensures that we never have any work scheduled on a root after it unmounts.
However in non-batched legacy mode the work that completes and clears it can be done synchronously here:
https://github.com/facebook/react/blob/master/packages/react-reconciler/src/ReactFiberWorkLoop.old.js#L445
That's before we add it. So once it's done, we end up adding the discrete work after we've already unmounted. Leaving work remaining that later flushes and clears the container again.
So one bug is that we should be doing this before we run the sync work. Sync work or scheduling should always come at the end of a function to avoid bugs like this.
However, the other bug is that we're scheduling this for Sync work at all. We don't need to. So I moved it to only schedule discrete for non-Sync work.
That revealed another bug. We currently flush discrete work before controlled components which is before the batched updates wrapper in events. That also flushes sync work implicitly. However, it only does that if there's discrete work scheduled. We relied on this to actually make controlled components work. So when we no longer schedule discrete work, this no longer implicitly flushes.
So I make flushing discrete always flush sync too.