(
returnFiber: Fiber,
currentFirstChild: Fiber | null,
newChildrenIterable: Iterable<mixed>,
lanes: Lanes,
)
| 1308 | } |
| 1309 | |
| 1310 | function reconcileChildrenIteratable( |
| 1311 | returnFiber: Fiber, |
| 1312 | currentFirstChild: Fiber | null, |
| 1313 | newChildrenIterable: Iterable<mixed>, |
| 1314 | lanes: Lanes, |
| 1315 | ): Fiber | null { |
| 1316 | // This is the same implementation as reconcileChildrenArray(), |
| 1317 | // but using the iterator instead. |
| 1318 | |
| 1319 | const iteratorFn = getIteratorFn(newChildrenIterable); |
| 1320 | |
| 1321 | if (typeof iteratorFn !== 'function') { |
| 1322 | throw new Error( |
| 1323 | 'An object is not an iterable. This error is likely caused by a bug in ' + |
| 1324 | 'React. Please file an issue.', |
| 1325 | ); |
| 1326 | } |
| 1327 | |
| 1328 | const newChildren = iteratorFn.call(newChildrenIterable); |
| 1329 | |
| 1330 | if (__DEV__) { |
| 1331 | if (newChildren === newChildrenIterable) { |
| 1332 | // We don't support rendering Generators as props because it's a mutation. |
| 1333 | // See https://github.com/facebook/react/issues/12995 |
| 1334 | // We do support generators if they were created by a GeneratorFunction component |
| 1335 | // as its direct child since we can recreate those by rerendering the component |
| 1336 | // as needed. |
| 1337 | const isGeneratorComponent = |
| 1338 | returnFiber.tag === FunctionComponent && |
| 1339 | // $FlowFixMe[method-unbinding] |
| 1340 | Object.prototype.toString.call(returnFiber.type) === |
| 1341 | '[object GeneratorFunction]' && |
| 1342 | // $FlowFixMe[method-unbinding] |
| 1343 | Object.prototype.toString.call(newChildren) === '[object Generator]'; |
| 1344 | if (!isGeneratorComponent) { |
| 1345 | if (!didWarnAboutGenerators) { |
| 1346 | console.error( |
| 1347 | 'Using Iterators as children is unsupported and will likely yield ' + |
| 1348 | 'unexpected results because enumerating a generator mutates it. ' + |
| 1349 | 'You may convert it to an array with `Array.from()` or the ' + |
| 1350 | '`[...spread]` operator before rendering. You can also use an ' + |
| 1351 | 'Iterable that can iterate multiple times over the same items.', |
| 1352 | ); |
| 1353 | } |
| 1354 | didWarnAboutGenerators = true; |
| 1355 | } |
| 1356 | } else if ((newChildrenIterable: any).entries === iteratorFn) { |
| 1357 | // Warn about using Maps as children |
| 1358 | if (!didWarnAboutMaps) { |
| 1359 | console.error( |
| 1360 | 'Using Maps as children is not supported. ' + |
| 1361 | 'Use an array of keyed ReactElements instead.', |
| 1362 | ); |
| 1363 | didWarnAboutMaps = true; |
| 1364 | } |
| 1365 | } |
| 1366 | } |
| 1367 |
no test coverage detected