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

Function validateAsyncIterable

packages/react-server/src/ReactFizzServer.js:3230–3265  ·  view source on GitHub ↗
(
  task: Task,
  iterable: AsyncIterable<any>,
  childIndex: number,
  iterator: AsyncIterator<any>,
)

Source from the content-addressed store, hash-verified

3228}
3229
3230function validateAsyncIterable(
3231 task: Task,
3232 iterable: AsyncIterable<any>,
3233 childIndex: number,
3234 iterator: AsyncIterator<any>,
3235): void {
3236 if (__DEV__) {
3237 if (iterator === iterable) {
3238 // We don't support rendering Generators as props because it's a mutation.
3239 // See https://github.com/facebook/react/issues/12995
3240 // We do support generators if they were created by a GeneratorFunction component
3241 // as its direct child since we can recreate those by rerendering the component
3242 // as needed.
3243 const isGeneratorComponent =
3244 childIndex === -1 && // Only the root child is valid
3245 task.componentStack !== null &&
3246 typeof task.componentStack.type === 'function' && // FunctionComponent
3247 // $FlowFixMe[method-unbinding]
3248 Object.prototype.toString.call(task.componentStack.type) ===
3249 '[object AsyncGeneratorFunction]' &&
3250 // $FlowFixMe[method-unbinding]
3251 Object.prototype.toString.call(iterator) === '[object AsyncGenerator]';
3252 if (!isGeneratorComponent) {
3253 if (!didWarnAboutGenerators) {
3254 console.error(
3255 'Using AsyncIterators as children is unsupported and will likely yield ' +
3256 'unexpected results because enumerating a generator mutates it. ' +
3257 'You can use an AsyncIterable that can iterate multiple times over ' +
3258 'the same items.',
3259 );
3260 }
3261 didWarnAboutGenerators = true;
3262 }
3263 }
3264 }
3265}
3266
3267function warnOnFunctionType(invalidChild: Function) {
3268 if (__DEV__) {

Callers 2

renderSuspenseListFunction · 0.85
retryNodeFunction · 0.85

Calls 1

errorMethod · 0.65

Tested by

no test coverage detected