-
Notifications
You must be signed in to change notification settings - Fork 49.8k
[Fiber] New error boundary semantics #8304
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
7967679
New error boundary semantics
acdlite 88be836
Fix broken setState callback test
acdlite 69796b3
Exit early in scheduleUpdate if a node's priority matches
acdlite 614cd4b
Add test for "unwinding" context when an error interrupts rendering
acdlite 4f126f5
Switch over primary effect types only
acdlite a61de42
Only continue the work loop if the error was successfully captured
acdlite fad5cb5
Add try/catch/finally blocks around commit phase passes
acdlite ece9f7b
NoopBoundary -> RethrowBoundary
acdlite 226ee8f
Only throw uncaught error once there is no more work to perform
acdlite 7386e82
Add more tests for incremental error handling
gaearon d27cada
Verify batched updates get scheduled despite errors
gaearon cc60f25
Remove outdated comment
gaearon 778183e
Record tests
gaearon 54978e9
Always reset nextUnitOfWork on error
gaearon c1f2eb2
Add a passing test for unmounting behavior on crashed tree
gaearon 46581a3
Top-level errors
acdlite b32c86e
Remove outdated comment
gaearon 7bc10c0
Separate Rethrow and Noop scenarios in boundary tests
gaearon cf20dfa
Move try block outside the commit loops
acdlite 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
Prev
Previous commit
Move try block outside the commit loops
- Loading branch information
commit cf20dfa99841fcaee0baaf4ae30a550b0e70df5b
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -165,48 +165,54 @@ module.exports = function<T, P, I, TI, C>(config : HostConfig<T, P, I, TI, C>) { | |
| // First, we'll perform all the host insertions, updates, deletions and | ||
| // ref unmounts. | ||
| let effectfulFiber = finishedWork.firstEffect; | ||
| while (effectfulFiber) { | ||
| pass1: while (true) { | ||
| try { | ||
| // The following switch statement is only concerned about placement, | ||
| // updates, and deletions. To avoid needing to add a case for every | ||
| // possible bitmap value, we remove the secondary effects from the | ||
| // effect tag and switch on that value. | ||
| let primaryEffectTag = effectfulFiber.effectTag & ~(Callback | Err); | ||
| switch (primaryEffectTag) { | ||
| case Placement: { | ||
| commitPlacement(effectfulFiber); | ||
| // Clear the "placement" from effect tag so that we know that this is inserted, before | ||
| // any life-cycles like componentDidMount gets called. | ||
| effectfulFiber.effectTag &= ~Placement; | ||
| break; | ||
| } | ||
| case PlacementAndUpdate: { | ||
| // Placement | ||
| commitPlacement(effectfulFiber); | ||
| // Clear the "placement" from effect tag so that we know that this is inserted, before | ||
| // any life-cycles like componentDidMount gets called. | ||
| effectfulFiber.effectTag &= ~Placement; | ||
|
|
||
| // Update | ||
| const current = effectfulFiber.alternate; | ||
| commitWork(current, effectfulFiber); | ||
| break; | ||
| } | ||
| case Update: { | ||
| const current = effectfulFiber.alternate; | ||
| commitWork(current, effectfulFiber); | ||
| break; | ||
| } | ||
| case Deletion: { | ||
| commitDeletion(effectfulFiber); | ||
| break; | ||
| while (effectfulFiber) { | ||
| // The following switch statement is only concerned about placement, | ||
| // updates, and deletions. To avoid needing to add a case for every | ||
| // possible bitmap value, we remove the secondary effects from the | ||
| // effect tag and switch on that value. | ||
| let primaryEffectTag = effectfulFiber.effectTag & ~(Callback | Err); | ||
| switch (primaryEffectTag) { | ||
| case Placement: { | ||
| commitPlacement(effectfulFiber); | ||
| // Clear the "placement" from effect tag so that we know that this is inserted, before | ||
| // any life-cycles like componentDidMount gets called. | ||
| effectfulFiber.effectTag &= ~Placement; | ||
| break; | ||
| } | ||
| case PlacementAndUpdate: { | ||
| // Placement | ||
| commitPlacement(effectfulFiber); | ||
| // Clear the "placement" from effect tag so that we know that this is inserted, before | ||
| // any life-cycles like componentDidMount gets called. | ||
| effectfulFiber.effectTag &= ~Placement; | ||
|
|
||
| // Update | ||
| const current = effectfulFiber.alternate; | ||
| commitWork(current, effectfulFiber); | ||
| break; | ||
| } | ||
| case Update: { | ||
| const current = effectfulFiber.alternate; | ||
| commitWork(current, effectfulFiber); | ||
| break; | ||
| } | ||
| case Deletion: { | ||
| commitDeletion(effectfulFiber); | ||
| break; | ||
| } | ||
| } | ||
| effectfulFiber = effectfulFiber.nextEffect; | ||
| } | ||
| } catch (error) { | ||
| captureError(effectfulFiber, error, false); | ||
| } finally { | ||
| effectfulFiber = effectfulFiber.nextEffect; | ||
| if (effectfulFiber) { | ||
| captureError(effectfulFiber, error, false); | ||
| effectfulFiber = effectfulFiber.nextEffect; | ||
| continue pass1; | ||
| } | ||
| } | ||
| break; | ||
| } | ||
|
|
||
| // Finally if the root itself had an effect, we perform that since it is | ||
|
|
@@ -222,35 +228,42 @@ module.exports = function<T, P, I, TI, C>(config : HostConfig<T, P, I, TI, C>) { | |
| // happens as a separate pass so that all effects in the entire tree have | ||
| // already been invoked. | ||
| effectfulFiber = finishedWork.firstEffect; | ||
| while (effectfulFiber) { | ||
| const previousPriorityContext = priorityContext; | ||
| priorityContext = TaskPriority; | ||
| const previousPriorityContext = priorityContext; | ||
| priorityContext = TaskPriority; | ||
| pass2: while (true) { | ||
|
Collaborator
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. Removing this try/finally block seems responsible for some of the test failures. --- a/scripts/fiber/tests-passing.txt
+++ b/scripts/fiber/tests-passing.txt
@@ -470,7 +470,6 @@ src/renderers/dom/__tests__/ReactDOMProduction-test.js
* should use prod React
* should handle a simple flow
* should call lifecycle methods
-* should throw with an error code in production
src/renderers/dom/fiber/__tests__/ReactDOMFiber-test.js
* should render strings as children
@@ -1021,8 +1020,12 @@ src/renderers/shared/shared/event/eventPlugins/__tests__/ResponderEventPlugin-te
src/renderers/shared/stack/reconciler/__tests__/ReactComponent-test.js
* should throw when supplying a ref outside of render method
-* should support refs on owned components
+* should warn when children are mutated during update
* should not have refs on unmounted components
+* should support new-style refs
+* should support new-style refs with mixed-up owners
+* should call refs at the correct time
+* fires the callback after a component is rendered
src/renderers/shared/stack/reconciler/__tests__/ReactComponentLifeCycle-test.js
* should not reuse an instance when it has been unmounted
@@ -1185,8 +1188,9 @@ src/renderers/shared/stack/reconciler/__tests__/ReactStatelessComponent-test.js
* should update stateless component
* should unmount stateless component
* should pass context thru stateless component
-* should provide a null ref
+* should use correct name in key warning
* should support default props and prop types
+* should receive context
* should work with arrow functions
* should allow simple functions to return null
* should allow simple functions to return false |
||
| try { | ||
| const current = effectfulFiber.alternate; | ||
| // Use Task priority for lifecycle updates | ||
| if (effectfulFiber.effectTag & (Update | Callback)) { | ||
| commitLifeCycles(current, effectfulFiber); | ||
| } | ||
| while (effectfulFiber) { | ||
| const current = effectfulFiber.alternate; | ||
| // Use Task priority for lifecycle updates | ||
| if (effectfulFiber.effectTag & (Update | Callback)) { | ||
| commitLifeCycles(current, effectfulFiber); | ||
| } | ||
|
|
||
| if (effectfulFiber.effectTag & Err) { | ||
| commitErrorHandling(effectfulFiber); | ||
| if (effectfulFiber.effectTag & Err) { | ||
| commitErrorHandling(effectfulFiber); | ||
| } | ||
|
|
||
| const next = effectfulFiber.nextEffect; | ||
| // Ensure that we clean these up so that we don't accidentally keep them. | ||
| // I'm not actually sure this matters because we can't reset firstEffect | ||
| // and lastEffect since they're on every node, not just the effectful | ||
| // ones. So we have to clean everything as we reuse nodes anyway. | ||
| effectfulFiber.nextEffect = null; | ||
| // Ensure that we reset the effectTag here so that we can rely on effect | ||
| // tags to reason about the current life-cycle. | ||
| effectfulFiber = next; | ||
| } | ||
| } catch (error) { | ||
| captureError(effectfulFiber, error, false); | ||
| } finally { | ||
| // Clean-up | ||
| priorityContext = previousPriorityContext; | ||
|
|
||
| const next = effectfulFiber.nextEffect; | ||
| // Ensure that we clean these up so that we don't accidentally keep them. | ||
| // I'm not actually sure this matters because we can't reset firstEffect | ||
| // and lastEffect since they're on every node, not just the effectful | ||
| // ones. So we have to clean everything as we reuse nodes anyway. | ||
| effectfulFiber.nextEffect = null; | ||
| // Ensure that we reset the effectTag here so that we can rely on effect | ||
| // tags to reason about the current life-cycle. | ||
| effectfulFiber = next; | ||
| if (effectfulFiber) { | ||
| captureError(effectfulFiber, error, false); | ||
| const next = effectfulFiber.nextEffect; | ||
| effectfulFiber.nextEffect = null; | ||
| effectfulFiber = next; | ||
| continue pass2; | ||
| } | ||
| } | ||
| priorityContext = previousPriorityContext; | ||
| break; | ||
| } | ||
|
|
||
| // Lifecycles on the root itself | ||
|
|
||
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.
These try blocks should be outside the while loop. That way we can hoist them out of this function and avoid going in and out of an deopt path for each iteration.
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.
Is my latest commit okay? Had to add another loop outside so that we can continue after an error