( task: Task, iterable: AsyncIterable<any>, childIndex: number, iterator: AsyncIterator<any>, )
| 3228 | } |
| 3229 | |
| 3230 | function 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 | |
| 3267 | function warnOnFunctionType(invalidChild: Function) { |
| 3268 | if (__DEV__) { |
no test coverage detected