fix: do not reconcile children that are iterable functions (#13416)
* fix: do not reconcile children that are iterable functions * fix: remove fit * Refactor comparison to exclude anything that isnt an object * Remove redundant undefined check
Rauno Freiberg committed
Aug 16, 2018 at 18:38 UTC
77b7a660b93913bf1fafb34ddff692b383bdc052
2 files changed
+30
-1
packages/react-dom/src/__tests__/ReactChildReconciler-test.js
+29
@@ -41,6 +41,35 @@ describe('ReactChildReconciler', () => {
41
};
42
}
43
44
+ function makeIterableFunction(value) {
45
+ const fn = () => {};
46
+ fn['@@iterator'] = function iterator() {
47
+ let timesCalled = 0;
48
+ return {
49
+ next() {
50
+ const done = timesCalled++ > 0;
51
+ return {done, value: done ? undefined : value};
52
+ },
53
+ };
54
+ };
55
+ return fn;
56
+ }
57
+
58
+ it('does not treat functions as iterables', () => {
59
+ let node;
60
+ const iterableFunction = makeIterableFunction('foo');
61
+
62
+ expect(() => {
63
+ node = ReactTestUtils.renderIntoDocument(
64
+ <div>
65
+ <h1>{iterableFunction}</h1>
66
+ </div>,
67
+ );
68
+ }).toWarnDev('Functions are not valid as a React child');
69
+
70
+ expect(node.innerHTML).toContain(''); // h1
71
+ });
72
+
73
it('warns for duplicated array keys', () => {
74
class Component extends React.Component {
75
render() {
packages/shared/ReactSymbols.js
+1
-1
@@ -46,7 +46,7 @@ const MAYBE_ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
46
const FAUX_ITERATOR_SYMBOL = '@@iterator';
47
48
export function getIteratorFn(maybeIterable: ?any): ?() => ?Iterator<*> {
49
- if (maybeIterable === null || typeof maybeIterable === 'undefined') {
49
+ if (maybeIterable === null || typeof maybeIterable !== 'object') {
50
return null;
51
}
52
const maybeIterator =