-
Notifications
You must be signed in to change notification settings - Fork 50k
[Synchronous Suspense] Suspending a class outside concurrent mode #13926
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 all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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 |
|---|---|---|
|
|
@@ -33,6 +33,7 @@ import { | |
| MemoComponent, | ||
| SimpleMemoComponent, | ||
| LazyComponent, | ||
| IncompleteClassComponent, | ||
| } from 'shared/ReactWorkTags'; | ||
| import { | ||
| NoEffect, | ||
|
|
@@ -762,7 +763,7 @@ function mountLazyComponent( | |
| renderExpirationTime, | ||
| ) { | ||
| if (_current !== null) { | ||
| // An indeterminate component only mounts if it suspended inside a non- | ||
| // An lazy component only mounts if it suspended inside a non- | ||
| // concurrent tree, in an inconsistent state. We want to tree it like | ||
| // a new mount, even though an empty version of it already committed. | ||
| // Disconnect the alternate pointers. | ||
|
|
@@ -840,6 +841,64 @@ function mountLazyComponent( | |
| return child; | ||
| } | ||
|
|
||
| function mountIncompleteClassComponent( | ||
| _current, | ||
| workInProgress, | ||
| Component, | ||
| nextProps, | ||
| renderExpirationTime, | ||
| ) { | ||
| if (_current !== null) { | ||
| // An incomplete component only mounts if it suspended inside a non- | ||
| // concurrent tree, in an inconsistent state. We want to tree it like | ||
|
Contributor
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.
treat it? |
||
| // a new mount, even though an empty version of it already committed. | ||
| // Disconnect the alternate pointers. | ||
| _current.alternate = null; | ||
| workInProgress.alternate = null; | ||
| // Since this is conceptually a new fiber, schedule a Placement effect | ||
| workInProgress.effectTag |= Placement; | ||
| } | ||
|
|
||
| // Promote the fiber to a class and try rendering again. | ||
| workInProgress.tag = ClassComponent; | ||
|
|
||
| // The rest of this function is a fork of `updateClassComponent` | ||
|
|
||
| // Push context providers early to prevent context stack mismatches. | ||
| // During mounting we don't know the child context yet as the instance doesn't exist. | ||
| // We will invalidate the child context in finishClassComponent() right after rendering. | ||
| let hasContext; | ||
| if (isLegacyContextProvider(Component)) { | ||
| hasContext = true; | ||
| pushLegacyContextProvider(workInProgress); | ||
| } else { | ||
| hasContext = false; | ||
| } | ||
| prepareToReadContext(workInProgress, renderExpirationTime); | ||
|
|
||
| constructClassInstance( | ||
| workInProgress, | ||
| Component, | ||
| nextProps, | ||
| renderExpirationTime, | ||
| ); | ||
| mountClassInstance( | ||
| workInProgress, | ||
| Component, | ||
| nextProps, | ||
| renderExpirationTime, | ||
| ); | ||
|
|
||
| return finishClassComponent( | ||
| null, | ||
| workInProgress, | ||
| Component, | ||
| true, | ||
| hasContext, | ||
| renderExpirationTime, | ||
| ); | ||
| } | ||
|
|
||
| function mountIndeterminateComponent( | ||
| _current, | ||
| workInProgress, | ||
|
|
@@ -1654,6 +1713,21 @@ function beginWork( | |
| renderExpirationTime, | ||
| ); | ||
| } | ||
| case IncompleteClassComponent: { | ||
| const Component = workInProgress.type; | ||
| const unresolvedProps = workInProgress.pendingProps; | ||
| const resolvedProps = | ||
| workInProgress.elementType === Component | ||
| ? unresolvedProps | ||
| : resolveDefaultProps(Component, unresolvedProps); | ||
| return mountIncompleteClassComponent( | ||
| current, | ||
| workInProgress, | ||
| Component, | ||
| resolvedProps, | ||
| renderExpirationTime, | ||
| ); | ||
| } | ||
| default: | ||
| invariant( | ||
| false, | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -32,6 +32,7 @@ import { | |
| HostPortal, | ||
| Profiler, | ||
| SuspenseComponent, | ||
| IncompleteClassComponent, | ||
| } from 'shared/ReactWorkTags'; | ||
| import { | ||
| invokeGuardedCallback, | ||
|
|
@@ -221,6 +222,7 @@ function commitBeforeMutationLifeCycles( | |
| case HostComponent: | ||
| case HostText: | ||
| case HostPortal: | ||
| case IncompleteClassComponent: | ||
| // Nothing to do for these component types | ||
| return; | ||
| default: { | ||
|
|
@@ -392,6 +394,8 @@ function commitLifeCycles( | |
| } | ||
| return; | ||
| } | ||
| case IncompleteClassComponent: | ||
| break; | ||
| default: { | ||
| invariant( | ||
| false, | ||
|
|
@@ -495,7 +499,13 @@ function commitUnmount(current: Fiber): void { | |
| case ClassComponent: { | ||
| safelyDetachRef(current); | ||
| const instance = current.stateNode; | ||
| if (typeof instance.componentWillUnmount === 'function') { | ||
| if ( | ||
| // Typically, a component that mounted will have an instance. However, | ||
| // outside of concurrent mode, a suspended component may commit without | ||
| // an instance, so we need to check whether it exists. | ||
| instance !== null && | ||
|
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. So why do we still need this check? I thought the separate tag is supposed to address it. |
||
| typeof instance.componentWillUnmount === 'function' | ||
| ) { | ||
| safelyCallComponentWillUnmount(current, instance); | ||
| } | ||
| return; | ||
|
|
@@ -924,6 +934,9 @@ function commitWork(current: Fiber | null, finishedWork: Fiber): void { | |
| case SuspenseComponent: { | ||
| return; | ||
| } | ||
| case IncompleteClassComponent: { | ||
| return; | ||
| } | ||
| default: { | ||
| invariant( | ||
| false, | ||
|
|
||
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
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
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
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
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
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.
A* lazy