-
Notifications
You must be signed in to change notification settings - Fork 45.9k
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
Synchronously restart when an error is thrown during async rendering #13041
Conversation
ReactDOM: size: 🔺+0.2%, gzip: 🔺+0.2% Details of bundled changes.Comparing: 9bda7b2...7cffa51 react-dom
react-art
react-test-renderer
react-reconciler
react-native-renderer
Generated by 🚫 dangerJS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make sure it gets reset if an update gets scheduled before it's done.
In a follow up we should see if we can only do the error replaying (invoke guarded callback) by reusing these two phases. The async phase only uses real try/catch. If it is a Promise, it'll catch it. If it is an error, it will always retry anyway. So the second one can only use invoke guarded callback. |
1a236b0
to
f372e3a
Compare
In async mode, events are interleaved with rendering. If one of those events mutates state that is later accessed during render, it can lead to inconsistencies/tearing. Restarting the render from the root is often sufficient to fix the inconsistency. We'll flush the restart synchronously to prevent yet another mutation from happening during an interleaved event. We'll only restart during an async render. Sync renders are already sync, so there's no benefit in restarting. (Unless a mutation happens during the render phase, but we don't support that.)
f372e3a
to
7cffa51
Compare
Since facebook#13041, we always replay the entire render phase before handling an error. We can wrap this in invokeGuardedCallback, instead of wrapping and replaying only the render phase of the failed fiber. Now we don't have to stash the work-in-progress fiber fields, which was quite fragile.
Since facebook#13041, we always replay the entire render phase before handling an error. We can wrap this in invokeGuardedCallback, instead of wrapping and replaying only the render phase of the failed fiber. Now we don't have to stash the work-in-progress fiber fields, which was quite fragile.
In async mode, events are interleaved with rendering. If one of those events mutates state that is later accessed during render, it can lead to inconsistencies/tearing.
Restarting the render from the root is often sufficient to fix the inconsistency. We'll flush the restart synchronously to prevent yet another mutation from happening during an interleaved event.
We'll only restart during an async render. Sync renders are already sync, so there's no benefit in restarting. (Unless a mutation happens during the render phase, but we don't support that.)