-
Notifications
You must be signed in to change notification settings - Fork 48.5k
[Fiber] Support AsyncIterable children in SuspenseList #33299
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
sebmarkbage
merged 2 commits into
facebook:main
from
sebmarkbage:suspenselistasynciterator
May 20, 2025
+306
−77
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
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 |
---|---|---|
|
@@ -123,7 +123,6 @@ import { | |
enableViewTransition, | ||
enableFragmentRefs, | ||
} from 'shared/ReactFeatureFlags'; | ||
import isArray from 'shared/isArray'; | ||
import shallowEqual from 'shared/shallowEqual'; | ||
import getComponentNameFromFiber from 'react-reconciler/src/getComponentNameFromFiber'; | ||
import getComponentNameFromType from 'shared/getComponentNameFromType'; | ||
|
@@ -132,7 +131,6 @@ import { | |
REACT_LAZY_TYPE, | ||
REACT_FORWARD_REF_TYPE, | ||
REACT_MEMO_TYPE, | ||
getIteratorFn, | ||
} from 'shared/ReactSymbols'; | ||
import {setCurrentFiber} from './ReactCurrentFiber'; | ||
import { | ||
|
@@ -145,6 +143,7 @@ import { | |
mountChildFibers, | ||
reconcileChildFibers, | ||
cloneChildFibers, | ||
validateSuspenseListChildren, | ||
} from './ReactChildFiber'; | ||
import { | ||
processUpdateQueue, | ||
|
@@ -3302,73 +3301,6 @@ function validateTailOptions( | |
} | ||
} | ||
|
||
function validateSuspenseListNestedChild(childSlot: mixed, index: number) { | ||
if (__DEV__) { | ||
const isAnArray = isArray(childSlot); | ||
const isIterable = | ||
!isAnArray && typeof getIteratorFn(childSlot) === 'function'; | ||
if (isAnArray || isIterable) { | ||
const type = isAnArray ? 'array' : 'iterable'; | ||
console.error( | ||
'A nested %s was passed to row #%s in <SuspenseList />. Wrap it in ' + | ||
'an additional SuspenseList to configure its revealOrder: ' + | ||
'<SuspenseList revealOrder=...> ... ' + | ||
'<SuspenseList revealOrder=...>{%s}</SuspenseList> ... ' + | ||
'</SuspenseList>', | ||
type, | ||
index, | ||
type, | ||
); | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
function validateSuspenseListChildren( | ||
children: mixed, | ||
revealOrder: SuspenseListRevealOrder, | ||
) { | ||
if (__DEV__) { | ||
if ( | ||
(revealOrder === 'forwards' || revealOrder === 'backwards') && | ||
children !== undefined && | ||
children !== null && | ||
children !== false | ||
) { | ||
if (isArray(children)) { | ||
for (let i = 0; i < children.length; i++) { | ||
if (!validateSuspenseListNestedChild(children[i], i)) { | ||
return; | ||
} | ||
} | ||
} else { | ||
const iteratorFn = getIteratorFn(children); | ||
if (typeof iteratorFn === 'function') { | ||
const childrenIterator = iteratorFn.call(children); | ||
if (childrenIterator) { | ||
let step = childrenIterator.next(); | ||
let i = 0; | ||
for (; !step.done; step = childrenIterator.next()) { | ||
if (!validateSuspenseListNestedChild(step.value, i)) { | ||
return; | ||
} | ||
i++; | ||
} | ||
} | ||
} else { | ||
console.error( | ||
'A single row was passed to a <SuspenseList revealOrder="%s" />. ' + | ||
'This is not useful since it needs multiple rows. ' + | ||
'Did you mean to pass multiple children or an array?', | ||
revealOrder, | ||
); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
function initSuspenseListRenderState( | ||
workInProgress: Fiber, | ||
isBackwards: boolean, | ||
|
@@ -3415,12 +3347,6 @@ function updateSuspenseListComponent( | |
const tailMode: SuspenseListTailMode = nextProps.tail; | ||
const newChildren = nextProps.children; | ||
|
||
validateRevealOrder(revealOrder); | ||
validateTailOptions(tailMode, revealOrder); | ||
validateSuspenseListChildren(newChildren, revealOrder); | ||
|
||
reconcileChildren(current, workInProgress, newChildren, renderLanes); | ||
|
||
let suspenseContext: SuspenseContext = suspenseStackCursor.current; | ||
|
||
const shouldForceFallback = hasSuspenseListContext( | ||
|
@@ -3434,6 +3360,17 @@ function updateSuspenseListComponent( | |
); | ||
workInProgress.flags |= DidCapture; | ||
} else { | ||
suspenseContext = setDefaultShallowSuspenseListContext(suspenseContext); | ||
} | ||
pushSuspenseListContext(workInProgress, suspenseContext); | ||
|
||
validateRevealOrder(revealOrder); | ||
validateTailOptions(tailMode, revealOrder); | ||
validateSuspenseListChildren(newChildren, revealOrder); | ||
|
||
reconcileChildren(current, workInProgress, newChildren, renderLanes); | ||
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.
|
||
|
||
if (!shouldForceFallback) { | ||
const didSuspendBefore = | ||
current !== null && (current.flags & DidCapture) !== NoFlags; | ||
if (didSuspendBefore) { | ||
|
@@ -3446,9 +3383,7 @@ function updateSuspenseListComponent( | |
renderLanes, | ||
); | ||
} | ||
suspenseContext = setDefaultShallowSuspenseListContext(suspenseContext); | ||
} | ||
pushSuspenseListContext(workInProgress, suspenseContext); | ||
|
||
if (!disableLegacyMode && (workInProgress.mode & ConcurrentMode) === NoMode) { | ||
// In legacy mode, SuspenseList doesn't work so we just | ||
|
Oops, something went wrong.
Oops, something went wrong.
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.
It can be costly to iterate this twice so we avoid it.
Ideally, we'd probably move the
validateSuspenseListChildren
warning to be integrated with the rest ChildFiber instead so that it can be done in a single pass. Even for sync iterators.