You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains 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
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.
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.