From 28f50c8a78cffc0b0e9d60e4a7c77cc14a8e80c7 Mon Sep 17 00:00:00 2001 From: Ben Moss Date: Mon, 26 Jan 2015 14:14:27 -0500 Subject: [PATCH 1/2] Add displayName to nested render warnings [#1726] --- src/browser/ui/ReactMount.js | 16 +++++++++------- .../__tests__/ReactCompositeComponent-test.js | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/browser/ui/ReactMount.js b/src/browser/ui/ReactMount.js index a71b2311d4..237c9528fb 100644 --- a/src/browser/ui/ReactMount.js +++ b/src/browser/ui/ReactMount.js @@ -353,10 +353,11 @@ var ReactMount = { // verify that that's the case. warning( ReactCurrentOwner.current == null, - '_renderNewRootComponent(): Render methods should be a pure function ' + - 'of props and state; triggering nested component updates from ' + + '%s._renderNewRootComponent(): Render methods should be a pure ' + + 'function of props and state; triggering nested component updates from ' + 'render is not allowed. If necessary, trigger nested updates in ' + - 'componentDidUpdate.' + 'componentDidUpdate.', + this.constructor.displayName || 'ReactCompositeComponent' ); var componentInstance = instantiateReactComponent(nextComponent, null); @@ -518,10 +519,11 @@ var ReactMount = { // render but we still don't expect to be in a render call here.) warning( ReactCurrentOwner.current == null, - 'unmountComponentAtNode(): Render methods should be a pure function of ' + - 'props and state; triggering nested component updates from render is ' + - 'not allowed. If necessary, trigger nested updates in ' + - 'componentDidUpdate.' + '%s.unmountComponentAtNode(): Render methods should be a pure function ' + + 'of props and state; triggering nested component updates from render ' + + 'is not allowed. If necessary, trigger nested updates in ' + + 'componentDidUpdate.', + this.constructor.displayName || 'ReactCompositeComponent' ); invariant( diff --git a/src/core/__tests__/ReactCompositeComponent-test.js b/src/core/__tests__/ReactCompositeComponent-test.js index ee705d4e2f..c3b040c0b7 100644 --- a/src/core/__tests__/ReactCompositeComponent-test.js +++ b/src/core/__tests__/ReactCompositeComponent-test.js @@ -826,7 +826,7 @@ describe('ReactCompositeComponent', function() { ReactTestUtils.renderIntoDocument(); expect(console.warn.argsForCall.length).toBe(1); expect(console.warn.argsForCall[0][0]).toBe( - 'Warning: _renderNewRootComponent(): Render methods should ' + + 'Warning: ReactCompositeComponent._renderNewRootComponent(): Render methods should ' + 'be a pure function of props and state; triggering nested component ' + 'updates from render is not allowed. If necessary, trigger nested ' + 'updates in componentDidUpdate.' From ba55716a2d8a73fef2f0bfdcf191eb3858166380 Mon Sep 17 00:00:00 2001 From: Ben Moss Date: Mon, 2 Feb 2015 18:00:48 -0500 Subject: [PATCH 2/2] Fix warning messages wording and access of displayName --- src/browser/ui/ReactMount.js | 16 +++++++++------- .../__tests__/ReactCompositeComponent-test.js | 4 ++-- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/browser/ui/ReactMount.js b/src/browser/ui/ReactMount.js index 237c9528fb..1ed572ff5c 100644 --- a/src/browser/ui/ReactMount.js +++ b/src/browser/ui/ReactMount.js @@ -353,11 +353,12 @@ var ReactMount = { // verify that that's the case. warning( ReactCurrentOwner.current == null, - '%s._renderNewRootComponent(): Render methods should be a pure ' + - 'function of props and state; triggering nested component updates from ' + + '_renderNewRootComponent(): Render methods should be a pure function ' + + 'of props and state; triggering nested component updates from ' + 'render is not allowed. If necessary, trigger nested updates in ' + - 'componentDidUpdate.', - this.constructor.displayName || 'ReactCompositeComponent' + 'componentDidUpdate. Check the render method of %s.', + ReactCurrentOwner.current && ReactCurrentOwner.current.getName() || + 'ReactCompositeComponent' ); var componentInstance = instantiateReactComponent(nextComponent, null); @@ -519,11 +520,12 @@ var ReactMount = { // render but we still don't expect to be in a render call here.) warning( ReactCurrentOwner.current == null, - '%s.unmountComponentAtNode(): Render methods should be a pure function ' + + 'unmountComponentAtNode(): Render methods should be a pure function ' + 'of props and state; triggering nested component updates from render ' + 'is not allowed. If necessary, trigger nested updates in ' + - 'componentDidUpdate.', - this.constructor.displayName || 'ReactCompositeComponent' + 'componentDidUpdate. Check the render method of %s.', + ReactCurrentOwner.current && ReactCurrentOwner.current.getName() || + 'ReactCompositeComponent' ); invariant( diff --git a/src/core/__tests__/ReactCompositeComponent-test.js b/src/core/__tests__/ReactCompositeComponent-test.js index c3b040c0b7..b259f94f57 100644 --- a/src/core/__tests__/ReactCompositeComponent-test.js +++ b/src/core/__tests__/ReactCompositeComponent-test.js @@ -826,10 +826,10 @@ describe('ReactCompositeComponent', function() { ReactTestUtils.renderIntoDocument(); expect(console.warn.argsForCall.length).toBe(1); expect(console.warn.argsForCall[0][0]).toBe( - 'Warning: ReactCompositeComponent._renderNewRootComponent(): Render methods should ' + + 'Warning: _renderNewRootComponent(): Render methods should ' + 'be a pure function of props and state; triggering nested component ' + 'updates from render is not allowed. If necessary, trigger nested ' + - 'updates in componentDidUpdate.' + 'updates in componentDidUpdate. Check the render method of Outer.' ); });