Suspending inside a constructor outside of strict mode#13200
Merged
acdlite merged 2 commits intofacebook:masterfrom Jul 13, 2018
Merged
Suspending inside a constructor outside of strict mode#13200acdlite merged 2 commits intofacebook:masterfrom
acdlite merged 2 commits intofacebook:masterfrom
Conversation
Outside of strict mode, suspended components commit in an incomplete state, then are synchronously deleted in a subsequent commit. If a component suspends inside the constructor, it mounts without an instance. This breaks at least one invariant: during deletion, we assume that every mounted component has an instance, and check the instance for the existence of `componentWillUnmount`. Rather than add a redundant check to the deletion of every class component, components that suspend inside their constructor and outside of strict mode are turned into empty functional components before they are mounted. This is a bit weird, but it's an edge case, and the empty component will be synchronously unmounted regardless.
Details of bundled changes.Comparing: 58f3b29...5714bb9 react-dom
react-art
react-test-renderer
react-reconciler
react-native-renderer
Generated by 🚫 dangerJS |
cyan33
approved these changes
Jul 12, 2018
Contributor
cyan33
left a comment
There was a problem hiding this comment.
Seems a bit hacky but glad it fixes the issue in non-strict mode.
sebmarkbage
suggested changes
Jul 13, 2018
|
|
||
| if ( | ||
| sourceFiber.tag === ClassComponent && | ||
| workInProgress.stateNode === null |
Contributor
There was a problem hiding this comment.
Let's use current === null because we don't want to fire componentWillUnmount unless we fired componentDidMount.
In non-strict mode, suspended components commit, but their lifecycles should not fire.
817cd42 to
5714bb9
Compare
sebmarkbage
approved these changes
Jul 13, 2018
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.
Outside of strict mode, suspended components commit in an incomplete state, then are synchronously deleted in a subsequent commit. If a component suspends inside the constructor, it mounts without an instance.
This breaks at least one invariant: during deletion, we assume that every mounted component has an instance, and check the instance for the existence of
componentWillUnmount.Rather than add a redundant check to the deletion of every class component, components that suspend inside their constructor and outside of strict mode are turned into empty functional components before they are mounted. This is a bit weird, but it's an edge case, and the empty component will be synchronously unmounted regardless.