From 9813b639b0fae23b78ad8ba631e5ab25ce6eb298 Mon Sep 17 00:00:00 2001 From: Ethan Arrowood Date: Fri, 5 Jan 2018 23:53:08 -0500 Subject: [PATCH 01/12] Attempt add getCurrentFiberStackAddendum --- packages/react-reconciler/src/ReactFiber.js | 6 +++++- .../__tests__/ReactIncrementalErrorHandling-test.js | 12 ++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/packages/react-reconciler/src/ReactFiber.js b/packages/react-reconciler/src/ReactFiber.js index 9d7c305d6fcfb..fab95b11c25e3 100644 --- a/packages/react-reconciler/src/ReactFiber.js +++ b/packages/react-reconciler/src/ReactFiber.js @@ -13,6 +13,9 @@ import type {TypeOfInternalContext} from './ReactTypeOfInternalContext'; import type {TypeOfSideEffect} from 'shared/ReactTypeOfSideEffect'; import type {ExpirationTime} from './ReactFiberExpirationTime'; import type {UpdateQueue} from './ReactFiberUpdateQueue'; +import ReactDebugCurrentFiber from './ReactDebugCurrentFiber'; + +const {getCurrentFiberStackAddendum} = ReactDebugCurrentFiber; import invariant from 'fbjs/lib/invariant'; import {NoEffect} from 'shared/ReactTypeOfSideEffect'; @@ -390,9 +393,10 @@ export function createFiberFromElement( false, 'Element type is invalid: expected a string (for built-in ' + 'components) or a class/function (for composite components) ' + - 'but got: %s.%s', + 'but got: %s.%s %s', type == null ? type : typeof type, info, + getCurrentFiberStackAddendum() ); } } diff --git a/packages/react-reconciler/src/__tests__/ReactIncrementalErrorHandling-test.js b/packages/react-reconciler/src/__tests__/ReactIncrementalErrorHandling-test.js index ae3bf926ae3a3..647463ce41988 100644 --- a/packages/react-reconciler/src/__tests__/ReactIncrementalErrorHandling-test.js +++ b/packages/react-reconciler/src/__tests__/ReactIncrementalErrorHandling-test.js @@ -13,6 +13,8 @@ let PropTypes; let React; let ReactNoop; +let ReactDebugCurrentFiber = require('./../ReactDebugCurrentFiber'); +let getCurrentFiberStackAddendum; describe('ReactIncrementalErrorHandling', () => { beforeEach(() => { @@ -20,6 +22,7 @@ describe('ReactIncrementalErrorHandling', () => { PropTypes = require('prop-types'); React = require('react'); ReactNoop = require('react-noop-renderer'); + getCurrentFiberStackAddendum = ReactDebugCurrentFiber.getCurrentFiberStackAddendum; }); function div(...children) { @@ -752,7 +755,8 @@ describe('ReactIncrementalErrorHandling', () => { (__DEV__ ? " You likely forgot to export your component from the file it's " + 'defined in, or you might have mixed up default and named imports.' + - '\n\nCheck the render method of `BrokenRender`.' + '\n\nCheck the render method of `BrokenRender`.' + + getCurrentFiberStackAddendum() : ''), ), ]); @@ -813,10 +817,10 @@ describe('ReactIncrementalErrorHandling', () => { expect(ReactNoop.flush).toThrowError( 'Element type is invalid: expected a string (for built-in components) or ' + 'a class/function (for composite components) but got: undefined.' + - (__DEV__ + (__DEV__ ? " You likely forgot to export your component from the file it's " + - 'defined in, or you might have mixed up default and named imports.' - : ''), + 'defined in, or you might have mixed up default and named imports.' + : ''), ); ReactNoop.render(); From 8825ba200c881f80d6289e9d9a62244bd4152068 Mon Sep 17 00:00:00 2001 From: Ethan Arrowood Date: Sat, 6 Jan 2018 00:34:11 -0500 Subject: [PATCH 02/12] add toErrorWithStack --- packages/react-reconciler/src/ReactFiber.js | 2 +- .../ReactIncrementalErrorHandling-test.js | 8 ++--- scripts/jest/matchers/toErrorWithStack.js | 30 +++++++++++++++++++ 3 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 scripts/jest/matchers/toErrorWithStack.js diff --git a/packages/react-reconciler/src/ReactFiber.js b/packages/react-reconciler/src/ReactFiber.js index fab95b11c25e3..505a49788c71a 100644 --- a/packages/react-reconciler/src/ReactFiber.js +++ b/packages/react-reconciler/src/ReactFiber.js @@ -393,7 +393,7 @@ export function createFiberFromElement( false, 'Element type is invalid: expected a string (for built-in ' + 'components) or a class/function (for composite components) ' + - 'but got: %s.%s %s', + 'but got: %s.%s%s', type == null ? type : typeof type, info, getCurrentFiberStackAddendum() diff --git a/packages/react-reconciler/src/__tests__/ReactIncrementalErrorHandling-test.js b/packages/react-reconciler/src/__tests__/ReactIncrementalErrorHandling-test.js index 647463ce41988..7c16571837cc1 100644 --- a/packages/react-reconciler/src/__tests__/ReactIncrementalErrorHandling-test.js +++ b/packages/react-reconciler/src/__tests__/ReactIncrementalErrorHandling-test.js @@ -13,8 +13,6 @@ let PropTypes; let React; let ReactNoop; -let ReactDebugCurrentFiber = require('./../ReactDebugCurrentFiber'); -let getCurrentFiberStackAddendum; describe('ReactIncrementalErrorHandling', () => { beforeEach(() => { @@ -22,7 +20,6 @@ describe('ReactIncrementalErrorHandling', () => { PropTypes = require('prop-types'); React = require('react'); ReactNoop = require('react-noop-renderer'); - getCurrentFiberStackAddendum = ReactDebugCurrentFiber.getCurrentFiberStackAddendum; }); function div(...children) { @@ -748,7 +745,7 @@ describe('ReactIncrementalErrorHandling', () => { expect(ReactNoop.flush).toWarnDev( 'Warning: React.createElement: type is invalid -- expected a string', ); - expect(ReactNoop.getChildren()).toEqual([ + expect(ReactNoop.getChildren()).toErrorWithStack([ span( 'Element type is invalid: expected a string (for built-in components) or ' + 'a class/function (for composite components) but got: undefined.' + @@ -756,7 +753,8 @@ describe('ReactIncrementalErrorHandling', () => { ? " You likely forgot to export your component from the file it's " + 'defined in, or you might have mixed up default and named imports.' + '\n\nCheck the render method of `BrokenRender`.' + - getCurrentFiberStackAddendum() + '\n in BrokenRender (at **)' + + '\n in ErrorBoundary (at **)' : ''), ), ]); diff --git a/scripts/jest/matchers/toErrorWithStack.js b/scripts/jest/matchers/toErrorWithStack.js new file mode 100644 index 0000000000000..fe7a1f6727238 --- /dev/null +++ b/scripts/jest/matchers/toErrorWithStack.js @@ -0,0 +1,30 @@ +'use strict'; +const diff = require('jest-diff'); + +function normalizeCodeLocInfo(str) { + return str && str.replace(/at .+?:\d+/g, 'at **'); +} + +const toErrorWithStack = (received, expected) => { + const normalizedMessage = normalizeCodeLocInfo(received[0].prop); + received[0].prop = normalizedMessage; + + const pass = this.equals(received, expected); + const diffString = diff(expected, received, { + expand: this.expand, + }); + const message = + this.utils.matcherHint('.toErrorWithStack') + + '\n\n' + + `Expected value to equal:\n` + + ` ${this.utils.printExpected(expected)}\n` + + `Received:\n` + + ` ${this.utils.printReceived(received)}` + + (diffString ? `\n\nDifference:\n\n${diffString}` : ''); + + return {actual: received, message, pass }; +}; + +module.exports = { + toErrorWithStack, +}; From c4b1655d38bd343d8c686db452370bf30faa715e Mon Sep 17 00:00:00 2001 From: Ethan Arrowood Date: Sat, 6 Jan 2018 00:45:01 -0500 Subject: [PATCH 03/12] Fixed custom matcher --- .../src/__tests__/ReactIncrementalErrorHandling-test.js | 6 ++++-- scripts/jest/matchers/toErrorWithStack.js | 4 ++-- scripts/jest/setupTests.js | 1 + scripts/jest/spec-equivalence-reporter/setupTests.js | 1 + 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/react-reconciler/src/__tests__/ReactIncrementalErrorHandling-test.js b/packages/react-reconciler/src/__tests__/ReactIncrementalErrorHandling-test.js index 7c16571837cc1..7aa655d8f79a2 100644 --- a/packages/react-reconciler/src/__tests__/ReactIncrementalErrorHandling-test.js +++ b/packages/react-reconciler/src/__tests__/ReactIncrementalErrorHandling-test.js @@ -794,14 +794,16 @@ describe('ReactIncrementalErrorHandling', () => { expect(ReactNoop.flush).toWarnDev( 'Warning: React.createElement: type is invalid -- expected a string', ); - expect(ReactNoop.getChildren()).toEqual([ + expect(ReactNoop.getChildren()).toErrorWithStack([ span( 'Element type is invalid: expected a string (for built-in components) or ' + 'a class/function (for composite components) but got: undefined.' + (__DEV__ ? " You likely forgot to export your component from the file it's " + 'defined in, or you might have mixed up default and named imports.' + - '\n\nCheck the render method of `BrokenRender`.' + '\n\nCheck the render method of `BrokenRender`.' + + '\n in BrokenRender (at **)' + + '\n in ErrorBoundary (at **)' : ''), ), ]); diff --git a/scripts/jest/matchers/toErrorWithStack.js b/scripts/jest/matchers/toErrorWithStack.js index fe7a1f6727238..afb21e436ba38 100644 --- a/scripts/jest/matchers/toErrorWithStack.js +++ b/scripts/jest/matchers/toErrorWithStack.js @@ -5,7 +5,7 @@ function normalizeCodeLocInfo(str) { return str && str.replace(/at .+?:\d+/g, 'at **'); } -const toErrorWithStack = (received, expected) => { +function toErrorWithStack(received, expected) { const normalizedMessage = normalizeCodeLocInfo(received[0].prop); received[0].prop = normalizedMessage; @@ -23,7 +23,7 @@ const toErrorWithStack = (received, expected) => { (diffString ? `\n\nDifference:\n\n${diffString}` : ''); return {actual: received, message, pass }; -}; +} module.exports = { toErrorWithStack, diff --git a/scripts/jest/setupTests.js b/scripts/jest/setupTests.js index 40ccf4c8f5685..8ff0600054586 100644 --- a/scripts/jest/setupTests.js +++ b/scripts/jest/setupTests.js @@ -43,6 +43,7 @@ if (process.env.REACT_CLASS_EQUIVALENCE_TEST) { expect.extend({ ...require('./matchers/toWarnDev'), + ...require('./matchers/toErrorWithStack'), }); // We have a Babel transform that inserts guards against infinite loops. diff --git a/scripts/jest/spec-equivalence-reporter/setupTests.js b/scripts/jest/spec-equivalence-reporter/setupTests.js index e91d34b1b11bf..adbbb4c5088d8 100644 --- a/scripts/jest/spec-equivalence-reporter/setupTests.js +++ b/scripts/jest/spec-equivalence-reporter/setupTests.js @@ -47,6 +47,7 @@ global.spyOnProd = function(...args) { expect.extend({ ...require('../matchers/toWarnDev'), + ...require('../matchers/toErrorWithStack'), }); beforeEach(() => (numExpectations = 0)); From 39117641edd7396b6b2cc3fbca1aff5968231d17 Mon Sep 17 00:00:00 2001 From: Ethan Arrowood Date: Mon, 8 Jan 2018 12:58:59 -0500 Subject: [PATCH 04/12] change toContent --- .../ReactIncrementalErrorHandling-test.js | 12 ++++------- .../{toErrorWithStack.js => toContent.js} | 21 ++++++++++++------- scripts/jest/setupTests.js | 2 +- .../spec-equivalence-reporter/setupTests.js | 2 +- 4 files changed, 19 insertions(+), 18 deletions(-) rename scripts/jest/matchers/{toErrorWithStack.js => toContent.js} (57%) diff --git a/packages/react-reconciler/src/__tests__/ReactIncrementalErrorHandling-test.js b/packages/react-reconciler/src/__tests__/ReactIncrementalErrorHandling-test.js index 7aa655d8f79a2..08b269af35820 100644 --- a/packages/react-reconciler/src/__tests__/ReactIncrementalErrorHandling-test.js +++ b/packages/react-reconciler/src/__tests__/ReactIncrementalErrorHandling-test.js @@ -745,16 +745,14 @@ describe('ReactIncrementalErrorHandling', () => { expect(ReactNoop.flush).toWarnDev( 'Warning: React.createElement: type is invalid -- expected a string', ); - expect(ReactNoop.getChildren()).toErrorWithStack([ + expect(ReactNoop.getChildren()).toContent([ span( 'Element type is invalid: expected a string (for built-in components) or ' + 'a class/function (for composite components) but got: undefined.' + (__DEV__ ? " You likely forgot to export your component from the file it's " + 'defined in, or you might have mixed up default and named imports.' + - '\n\nCheck the render method of `BrokenRender`.' + - '\n in BrokenRender (at **)' + - '\n in ErrorBoundary (at **)' + '\n\nCheck the render method of `BrokenRender`.' : ''), ), ]); @@ -794,16 +792,14 @@ describe('ReactIncrementalErrorHandling', () => { expect(ReactNoop.flush).toWarnDev( 'Warning: React.createElement: type is invalid -- expected a string', ); - expect(ReactNoop.getChildren()).toErrorWithStack([ + expect(ReactNoop.getChildren()).toContent([ span( 'Element type is invalid: expected a string (for built-in components) or ' + 'a class/function (for composite components) but got: undefined.' + (__DEV__ ? " You likely forgot to export your component from the file it's " + 'defined in, or you might have mixed up default and named imports.' + - '\n\nCheck the render method of `BrokenRender`.' + - '\n in BrokenRender (at **)' + - '\n in ErrorBoundary (at **)' + '\n\nCheck the render method of `BrokenRender`.' : ''), ), ]); diff --git a/scripts/jest/matchers/toErrorWithStack.js b/scripts/jest/matchers/toContent.js similarity index 57% rename from scripts/jest/matchers/toErrorWithStack.js rename to scripts/jest/matchers/toContent.js index afb21e436ba38..53021e67e9cb3 100644 --- a/scripts/jest/matchers/toErrorWithStack.js +++ b/scripts/jest/matchers/toContent.js @@ -1,20 +1,25 @@ 'use strict'; const diff = require('jest-diff'); -function normalizeCodeLocInfo(str) { - return str && str.replace(/at .+?:\d+/g, 'at **'); +function removeStack(str) { + return str && str.replace(/in .+? \(at .+?:\d+\)/g, '').trim(); } -function toErrorWithStack(received, expected) { - const normalizedMessage = normalizeCodeLocInfo(received[0].prop); - received[0].prop = normalizedMessage; +function toContent(received, expected) { + const rm = removeStack(received[0].prop); + received[0].prop = rm; + + const em = removeStack(expected[0].prop); + expected[0].prop = em; const pass = this.equals(received, expected); + const diffString = diff(expected, received, { expand: this.expand, }); - const message = - this.utils.matcherHint('.toErrorWithStack') + + + const message = () => + this.utils.matcherHint('.toContent') + '\n\n' + `Expected value to equal:\n` + ` ${this.utils.printExpected(expected)}\n` + @@ -26,5 +31,5 @@ function toErrorWithStack(received, expected) { } module.exports = { - toErrorWithStack, + toContent, }; diff --git a/scripts/jest/setupTests.js b/scripts/jest/setupTests.js index 8ff0600054586..063088c1a3d7d 100644 --- a/scripts/jest/setupTests.js +++ b/scripts/jest/setupTests.js @@ -43,7 +43,7 @@ if (process.env.REACT_CLASS_EQUIVALENCE_TEST) { expect.extend({ ...require('./matchers/toWarnDev'), - ...require('./matchers/toErrorWithStack'), + ...require('./matchers/toContent'), }); // We have a Babel transform that inserts guards against infinite loops. diff --git a/scripts/jest/spec-equivalence-reporter/setupTests.js b/scripts/jest/spec-equivalence-reporter/setupTests.js index adbbb4c5088d8..c8bcf8e57e282 100644 --- a/scripts/jest/spec-equivalence-reporter/setupTests.js +++ b/scripts/jest/spec-equivalence-reporter/setupTests.js @@ -47,7 +47,7 @@ global.spyOnProd = function(...args) { expect.extend({ ...require('../matchers/toWarnDev'), - ...require('../matchers/toErrorWithStack'), + ...require('../matchers/toContent'), }); beforeEach(() => (numExpectations = 0)); From d117d9c0de4ac6503e616430b6154a2c8b8703c2 Mon Sep 17 00:00:00 2001 From: Ethan Arrowood Date: Mon, 8 Jan 2018 13:38:06 -0500 Subject: [PATCH 05/12] prettify and lint --- packages/react-reconciler/src/ReactFiber.js | 2 +- .../src/__tests__/ReactIncrementalErrorHandling-test.js | 6 +++--- scripts/jest/matchers/toContent.js | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/react-reconciler/src/ReactFiber.js b/packages/react-reconciler/src/ReactFiber.js index 505a49788c71a..182438a5602da 100644 --- a/packages/react-reconciler/src/ReactFiber.js +++ b/packages/react-reconciler/src/ReactFiber.js @@ -396,7 +396,7 @@ export function createFiberFromElement( 'but got: %s.%s%s', type == null ? type : typeof type, info, - getCurrentFiberStackAddendum() + getCurrentFiberStackAddendum(), ); } } diff --git a/packages/react-reconciler/src/__tests__/ReactIncrementalErrorHandling-test.js b/packages/react-reconciler/src/__tests__/ReactIncrementalErrorHandling-test.js index 08b269af35820..7384a8492c9d0 100644 --- a/packages/react-reconciler/src/__tests__/ReactIncrementalErrorHandling-test.js +++ b/packages/react-reconciler/src/__tests__/ReactIncrementalErrorHandling-test.js @@ -813,10 +813,10 @@ describe('ReactIncrementalErrorHandling', () => { expect(ReactNoop.flush).toThrowError( 'Element type is invalid: expected a string (for built-in components) or ' + 'a class/function (for composite components) but got: undefined.' + - (__DEV__ + (__DEV__ ? " You likely forgot to export your component from the file it's " + - 'defined in, or you might have mixed up default and named imports.' - : ''), + 'defined in, or you might have mixed up default and named imports.' + : ''), ); ReactNoop.render(); diff --git a/scripts/jest/matchers/toContent.js b/scripts/jest/matchers/toContent.js index 53021e67e9cb3..60f450605aceb 100644 --- a/scripts/jest/matchers/toContent.js +++ b/scripts/jest/matchers/toContent.js @@ -17,7 +17,7 @@ function toContent(received, expected) { const diffString = diff(expected, received, { expand: this.expand, }); - + const message = () => this.utils.matcherHint('.toContent') + '\n\n' + @@ -27,7 +27,7 @@ function toContent(received, expected) { ` ${this.utils.printReceived(received)}` + (diffString ? `\n\nDifference:\n\n${diffString}` : ''); - return {actual: received, message, pass }; + return {actual: received, message, pass}; } module.exports = { From ffbae2f368e4219701103b5769456fbfdde231c6 Mon Sep 17 00:00:00 2001 From: Ethan Arrowood Date: Tue, 9 Jan 2018 11:17:06 -0500 Subject: [PATCH 06/12] add stripStackTrace --- .../__tests__/ReactIncrementalErrorHandling-test.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/react-reconciler/src/__tests__/ReactIncrementalErrorHandling-test.js b/packages/react-reconciler/src/__tests__/ReactIncrementalErrorHandling-test.js index 7384a8492c9d0..ab629409cea84 100644 --- a/packages/react-reconciler/src/__tests__/ReactIncrementalErrorHandling-test.js +++ b/packages/react-reconciler/src/__tests__/ReactIncrementalErrorHandling-test.js @@ -31,6 +31,15 @@ describe('ReactIncrementalErrorHandling', () => { return {type: 'span', children: [], prop}; } + function removeStack(str) { + return str && str.replace(/in .+? \(at .+?:\d+\)/g, '').trim(); + } + + function stripStackTrace(obj) { + obj[0].prop = removeStack(obj[0].prop); + return obj; + } + it('catches render error in a boundary during full deferred mounting', () => { class ErrorBoundary extends React.Component { state = {error: null}; @@ -745,7 +754,7 @@ describe('ReactIncrementalErrorHandling', () => { expect(ReactNoop.flush).toWarnDev( 'Warning: React.createElement: type is invalid -- expected a string', ); - expect(ReactNoop.getChildren()).toContent([ + expect(stripStackTrace(ReactNoop.getChildren())).toEqual([ span( 'Element type is invalid: expected a string (for built-in components) or ' + 'a class/function (for composite components) but got: undefined.' + @@ -792,7 +801,7 @@ describe('ReactIncrementalErrorHandling', () => { expect(ReactNoop.flush).toWarnDev( 'Warning: React.createElement: type is invalid -- expected a string', ); - expect(ReactNoop.getChildren()).toContent([ + expect(stripStackTrace(ReactNoop.getChildren())).toEqual([ span( 'Element type is invalid: expected a string (for built-in components) or ' + 'a class/function (for composite components) but got: undefined.' + From 257ef7e3b7c89af082fb0560280da318954052fa Mon Sep 17 00:00:00 2001 From: Ethan Arrowood Date: Tue, 9 Jan 2018 13:42:22 -0500 Subject: [PATCH 07/12] remove toContent. add childFiber --- .../react-reconciler/src/ReactChildFiber.js | 21 ++++++----- scripts/jest/matchers/toContent.js | 35 ------------------- scripts/jest/setupTests.js | 1 - .../spec-equivalence-reporter/setupTests.js | 1 - 4 files changed, 13 insertions(+), 45 deletions(-) delete mode 100644 scripts/jest/matchers/toContent.js diff --git a/packages/react-reconciler/src/ReactChildFiber.js b/packages/react-reconciler/src/ReactChildFiber.js index 1722bf81263df..175483aa43c86 100644 --- a/packages/react-reconciler/src/ReactChildFiber.js +++ b/packages/react-reconciler/src/ReactChildFiber.js @@ -66,7 +66,8 @@ if (__DEV__) { invariant( typeof child._store === 'object', 'React Component in warnForMissingKey should have a _store. ' + - 'This error is likely caused by a bug in React. Please file an issue.', + 'This error is likely caused by a bug in React. Please file an issue.%s', + getCurrentFiberStackAddendum(), ); child._store.validated = true; @@ -109,8 +110,9 @@ function coerceRef(current: Fiber | null, element: ReactElement) { invariant( inst, 'Missing owner for string ref %s. This error is likely caused by a ' + - 'bug in React. Please file an issue.', + 'bug in React. Please file an issue.%s', mixedRef, + getCurrentFiberStackAddendum() ); const stringRef = '' + mixedRef; // Check if previous string ref matches new string ref @@ -134,7 +136,8 @@ function coerceRef(current: Fiber | null, element: ReactElement) { } else { invariant( typeof mixedRef === 'string', - 'Expected ref to be a function or a string.', + 'Expected ref to be a function or a string.%s', + getCurrentFiberStackAddendum() ); invariant( element._owner, @@ -143,8 +146,9 @@ function coerceRef(current: Fiber | null, element: ReactElement) { '1. You may be adding a ref to a functional component\n' + "2. You may be adding a ref to a component that was not created inside a component's render method\n" + '3. You have multiple copies of React loaded\n' + - 'See https://fb.me/react-refs-must-have-owner for more information.', + 'See https://fb.me/react-refs-must-have-owner for more information.%s', mixedRef, + getCurrentFiberStackAddendum() ); } } @@ -157,16 +161,16 @@ function throwOnInvalidObjectType(returnFiber: Fiber, newChild: Object) { if (__DEV__) { addendum = ' If you meant to render a collection of children, use an array ' + - 'instead.' + - (getCurrentFiberStackAddendum() || ''); + 'instead.'; } invariant( false, - 'Objects are not valid as a React child (found: %s).%s', + 'Objects are not valid as a React child (found: %s).%s%s', Object.prototype.toString.call(newChild) === '[object Object]' ? 'object with keys {' + Object.keys(newChild).join(', ') + '}' : newChild, addendum, + (getCurrentFiberStackAddendum() || ''), ); } } @@ -862,7 +866,8 @@ function ChildReconciler(shouldTrackSideEffects) { invariant( typeof iteratorFn === 'function', 'An object is not an iterable. This error is likely caused by a bug in ' + - 'React. Please file an issue.', + 'React. Please file an issue.%s', + getCurrentFiberStackAddendum() || '', ); if (__DEV__) { diff --git a/scripts/jest/matchers/toContent.js b/scripts/jest/matchers/toContent.js deleted file mode 100644 index 60f450605aceb..0000000000000 --- a/scripts/jest/matchers/toContent.js +++ /dev/null @@ -1,35 +0,0 @@ -'use strict'; -const diff = require('jest-diff'); - -function removeStack(str) { - return str && str.replace(/in .+? \(at .+?:\d+\)/g, '').trim(); -} - -function toContent(received, expected) { - const rm = removeStack(received[0].prop); - received[0].prop = rm; - - const em = removeStack(expected[0].prop); - expected[0].prop = em; - - const pass = this.equals(received, expected); - - const diffString = diff(expected, received, { - expand: this.expand, - }); - - const message = () => - this.utils.matcherHint('.toContent') + - '\n\n' + - `Expected value to equal:\n` + - ` ${this.utils.printExpected(expected)}\n` + - `Received:\n` + - ` ${this.utils.printReceived(received)}` + - (diffString ? `\n\nDifference:\n\n${diffString}` : ''); - - return {actual: received, message, pass}; -} - -module.exports = { - toContent, -}; diff --git a/scripts/jest/setupTests.js b/scripts/jest/setupTests.js index 063088c1a3d7d..40ccf4c8f5685 100644 --- a/scripts/jest/setupTests.js +++ b/scripts/jest/setupTests.js @@ -43,7 +43,6 @@ if (process.env.REACT_CLASS_EQUIVALENCE_TEST) { expect.extend({ ...require('./matchers/toWarnDev'), - ...require('./matchers/toContent'), }); // We have a Babel transform that inserts guards against infinite loops. diff --git a/scripts/jest/spec-equivalence-reporter/setupTests.js b/scripts/jest/spec-equivalence-reporter/setupTests.js index c8bcf8e57e282..e91d34b1b11bf 100644 --- a/scripts/jest/spec-equivalence-reporter/setupTests.js +++ b/scripts/jest/spec-equivalence-reporter/setupTests.js @@ -47,7 +47,6 @@ global.spyOnProd = function(...args) { expect.extend({ ...require('../matchers/toWarnDev'), - ...require('../matchers/toContent'), }); beforeEach(() => (numExpectations = 0)); From f87e8c9348ca586a348d5d292c8294a0d7140470 Mon Sep 17 00:00:00 2001 From: Ethan Arrowood Date: Tue, 9 Jan 2018 13:56:03 -0500 Subject: [PATCH 08/12] Add stack to child, input, textarea --- packages/react-dom/src/client/ReactDOMFiberInput.js | 3 ++- .../react-dom/src/client/ReactDOMFiberTextarea.js | 3 ++- packages/react-reconciler/src/ReactChildFiber.js | 13 ++++++------- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/react-dom/src/client/ReactDOMFiberInput.js b/packages/react-dom/src/client/ReactDOMFiberInput.js index fd5a574fec377..000f1310af593 100644 --- a/packages/react-dom/src/client/ReactDOMFiberInput.js +++ b/packages/react-dom/src/client/ReactDOMFiberInput.js @@ -276,7 +276,8 @@ function updateNamedCousins(rootNode, props) { invariant( otherProps, 'ReactDOMInput: Mixing React and non-React radio inputs with the ' + - 'same `name` is not supported.', + 'same `name` is not supported.%s', + getCurrentFiberStackAddendum() || '', ); // We need update the tracked value on the named cousin since the value diff --git a/packages/react-dom/src/client/ReactDOMFiberTextarea.js b/packages/react-dom/src/client/ReactDOMFiberTextarea.js index d167161435282..c9062faf82641 100644 --- a/packages/react-dom/src/client/ReactDOMFiberTextarea.js +++ b/packages/react-dom/src/client/ReactDOMFiberTextarea.js @@ -43,7 +43,8 @@ export function getHostProps(element: Element, props: Object) { const node = ((element: any): TextAreaWithWrapperState); invariant( props.dangerouslySetInnerHTML == null, - '`dangerouslySetInnerHTML` does not make sense on