-
Notifications
You must be signed in to change notification settings - Fork 47.4k
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 bugs related to unmounting error boundaries #10403
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -761,7 +761,11 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>( | |
// The loop stops once the children have unmounted and error lifecycles are | ||
// called. Then we return to the regular flow. | ||
|
||
if (capturedErrors !== null && capturedErrors.size > 0) { | ||
if ( | ||
capturedErrors !== null && | ||
capturedErrors.size > 0 && | ||
nextPriorityLevel === TaskPriority | ||
) { | ||
while (nextUnitOfWork !== null) { | ||
if (hasCapturedError(nextUnitOfWork)) { | ||
// Use a forked version of performUnitOfWork | ||
|
@@ -780,19 +784,17 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>( | |
commitAllWork(pendingCommit); | ||
priorityContext = nextPriorityLevel; | ||
|
||
if (capturedErrors === null || capturedErrors.size === 0) { | ||
if ( | ||
capturedErrors === null || | ||
capturedErrors.size === 0 || | ||
nextPriorityLevel !== TaskPriority | ||
) { | ||
// There are no more unhandled errors. We can exit this special | ||
// work loop. If there's still additional work, we'll perform it | ||
// using one of the normal work loops. | ||
break; | ||
} | ||
// The commit phase produced additional errors. Continue working. | ||
invariant( | ||
nextPriorityLevel === TaskPriority, | ||
'Commit phase errors should be scheduled to recover with task ' + | ||
'priority. This error is likely caused by a bug in React. ' + | ||
'Please file an issue.', | ||
); | ||
} | ||
} | ||
} | ||
|
@@ -1129,7 +1131,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>( | |
willRetry = true; | ||
} | ||
} else if (node.tag === HostRoot) { | ||
// Treat the root like a no-op error boundary. | ||
// Treat the root like a no-op error boundary | ||
boundary = node; | ||
} | ||
|
||
|
@@ -1349,6 +1351,14 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>( | |
} | ||
|
||
function scheduleUpdate(fiber: Fiber, priorityLevel: PriorityLevel) { | ||
return scheduleUpdateImpl(fiber, priorityLevel, false); | ||
} | ||
|
||
function scheduleUpdateImpl( | ||
fiber: Fiber, | ||
priorityLevel: PriorityLevel, | ||
isErrorRecovery: boolean, | ||
) { | ||
if (__DEV__) { | ||
recordScheduleUpdate(); | ||
} | ||
|
@@ -1372,7 +1382,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>( | |
} | ||
|
||
if (__DEV__) { | ||
if (fiber.tag === ClassComponent) { | ||
if (!isErrorRecovery && fiber.tag === ClassComponent) { | ||
const instance = fiber.stateNode; | ||
warnAboutInvalidUpdates(instance); | ||
} | ||
|
@@ -1438,7 +1448,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>( | |
} | ||
} else { | ||
if (__DEV__) { | ||
if (fiber.tag === ClassComponent) { | ||
if (!isErrorRecovery && fiber.tag === ClassComponent) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can the warnAboutInvalidUpdates above cause an error? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good call, I'll add a guard there as well. |
||
warnAboutUpdateOnUnmounted(fiber.stateNode); | ||
} | ||
} | ||
|
@@ -1478,7 +1488,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>( | |
} | ||
|
||
function scheduleErrorRecovery(fiber: Fiber) { | ||
scheduleUpdate(fiber, TaskPriority); | ||
scheduleUpdateImpl(fiber, TaskPriority, true); | ||
} | ||
|
||
function performWithPriority(priorityLevel: PriorityLevel, fn: Function) { | ||
|
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
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.
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.
Why don't we want to throw here any more? My suggestion:
seemed clearer about intent to me.
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.
We decided that cleaning up
capturedErrors
when an error boundary's parent is unmounted (see test added in 894656c) wasn't worth it, and socapturedErrors !== null
is not a reliable indicator that there are unhandled errors.If you're referring to moving the check to a
while
loop, that's how it used to work, but we recently refactored the work loops to do as few checks as possible on each iteration, and only do certain checks (like whether the priority level is correct) right after committing, which is the only time they change. Requires a bit more duplicated code but fewer runtime checks.