Skip to content

Commit

Permalink
generators are one-shot iterators
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed May 12, 2022
1 parent 5a2e2cf commit ec0709a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 32 deletions.
32 changes: 16 additions & 16 deletions packages/react-reconciler/src/ReactChildFiber.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,22 @@ function ChildReconciler(shouldTrackSideEffects) {
);
}
didWarnAboutGenerators = true;
} else {
// Warn about using one-shot iterators as children
const isOneShotIterator =
iteratorFn.call(newChildrenIterable) === newChildrenIterable;
if (isOneShotIterator) {
if (!didWarnAboutOneShotIterators) {
console.error(
'Using a TOOD-understandable-term as children is unsupported and will likely yield ' +
'unexpected results because enumerating a TOOD-understandable-term mutates it. ' +
'You may convert it to an array with `Array.from()` or the ' +
'`[...spread]` operator before rendering. Keep in mind ' +
'you might need to polyfill these features for older browsers.',
);
}
didWarnAboutOneShotIterators = true;
}
}

// Warn about using Maps as children
Expand All @@ -950,22 +966,6 @@ function ChildReconciler(shouldTrackSideEffects) {
didWarnAboutMaps = true;
}

// Warn about using one-shot iterators as children
const isOneShotIterator =
iteratorFn.call(newChildrenIterable) === newChildrenIterable;
if (isOneShotIterator) {
if (!didWarnAboutOneShotIterators) {
console.error(
'Using a TOOD-understandable-term as children is unsupported and will likely yield ' +
'unexpected results because enumerating a TOOD-understandable-term mutates it. ' +
'You may convert it to an array with `Array.from()` or the ' +
'`[...spread]` operator before rendering. Keep in mind ' +
'you might need to polyfill these features for older browsers.',
);
}
didWarnAboutOneShotIterators = true;
}

// First, validate keys.
// We'll get a different iterator later for the main pass.
const newChildren = iteratorFn.call(newChildrenIterable);
Expand Down
32 changes: 16 additions & 16 deletions packages/react-reconciler/src/ReactChildFiber.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,22 @@ function ChildReconciler(shouldTrackSideEffects) {
);
}
didWarnAboutGenerators = true;
} else {
// Warn about using one-shot iterators as children
const isOneShotIterator =
iteratorFn.call(newChildrenIterable) === newChildrenIterable;
if (isOneShotIterator) {
if (!didWarnAboutOneShotIterators) {
console.error(
'Using a TOOD-understandable-term as children is unsupported and will likely yield ' +
'unexpected results because enumerating a TOOD-understandable-term mutates it. ' +
'You may convert it to an array with `Array.from()` or the ' +
'`[...spread]` operator before rendering. Keep in mind ' +
'you might need to polyfill these features for older browsers.',
);
}
didWarnAboutOneShotIterators = true;
}
}

// Warn about using Maps as children
Expand All @@ -950,22 +966,6 @@ function ChildReconciler(shouldTrackSideEffects) {
didWarnAboutMaps = true;
}

// Warn about using one-shot iterators as children
const isOneShotIterator =
iteratorFn.call(newChildrenIterable) === newChildrenIterable;
if (isOneShotIterator) {
if (!didWarnAboutOneShotIterators) {
console.error(
'Using a TOOD-understandable-term as children is unsupported and will likely yield ' +
'unexpected results because enumerating a TOOD-understandable-term mutates it. ' +
'You may convert it to an array with `Array.from()` or the ' +
'`[...spread]` operator before rendering. Keep in mind ' +
'you might need to polyfill these features for older browsers.',
);
}
didWarnAboutOneShotIterators = true;
}

// First, validate keys.
// We'll get a different iterator later for the main pass.
const newChildren = iteratorFn.call(newChildrenIterable);
Expand Down

0 comments on commit ec0709a

Please sign in to comment.