MCPcopy
hub / github.com/facebook/react / renderSuspenseList

Function renderSuspenseList

packages/react-server/src/ReactFizzServer.js:2091–2222  ·  view source on GitHub ↗
(
  request: Request,
  task: Task,
  keyPath: KeyNode,
  props: SuspenseListProps,
)

Source from the content-addressed store, hash-verified

2089}
2090
2091function renderSuspenseList(
2092 request: Request,
2093 task: Task,
2094 keyPath: KeyNode,
2095 props: SuspenseListProps,
2096): void {
2097 const children: any = props.children;
2098 const revealOrder: SuspenseListRevealOrder = props.revealOrder;
2099 // TODO: Support tail hidden/collapsed modes.
2100 // const tailMode: SuspenseListTailMode = props.tail;
2101 if (
2102 revealOrder === 'forwards' ||
2103 revealOrder === 'backwards' ||
2104 revealOrder === 'unstable_legacy-backwards'
2105 ) {
2106 // For ordered reveal, we need to produce rows from the children.
2107 if (isArray(children)) {
2108 renderSuspenseListRows(request, task, keyPath, children, revealOrder);
2109 return;
2110 }
2111 const iteratorFn = getIteratorFn(children);
2112 if (iteratorFn) {
2113 const iterator = iteratorFn.call(children);
2114 if (iterator) {
2115 if (__DEV__) {
2116 validateIterable(task, children, -1, iterator, iteratorFn);
2117 }
2118 // TODO: We currently use the same id algorithm as regular nodes
2119 // but we need a new algorithm for SuspenseList that doesn't require
2120 // a full set to be loaded up front to support Async Iterable.
2121 // When we have that, we shouldn't buffer anymore.
2122 let step = iterator.next();
2123 if (!step.done) {
2124 const rows = [];
2125 do {
2126 rows.push(step.value);
2127 step = iterator.next();
2128 } while (!step.done);
2129 renderSuspenseListRows(request, task, keyPath, children, revealOrder);
2130 }
2131 return;
2132 }
2133 }
2134 if (
2135 enableAsyncIterableChildren &&
2136 typeof (children: any)[ASYNC_ITERATOR] === 'function'
2137 ) {
2138 const iterator: AsyncIterator<ReactNodeList> = (children: any)[
2139 ASYNC_ITERATOR
2140 ]();
2141 if (iterator) {
2142 if (__DEV__) {
2143 validateAsyncIterable(task, (children: any), -1, iterator);
2144 }
2145 // TODO: Update the task.children to be the iterator to avoid asking
2146 // for new iterators, but we currently warn for rendering these
2147 // so needs some refactoring to deal with the warning.
2148

Callers 1

renderElementFunction · 0.85

Calls 13

unwrapThenableFunction · 0.90
isArrayFunction · 0.85
renderSuspenseListRowsFunction · 0.85
validateIterableFunction · 0.85
validateAsyncIterableFunction · 0.85
createSuspenseListRowFunction · 0.85
renderNodeDestructiveFunction · 0.85
finishSuspenseListRowFunction · 0.85
nextMethod · 0.80
pushMethod · 0.65

Tested by

no test coverage detected