Skip to content

Commit

Permalink
Follow up: make new warning less wordy (#12532)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Apr 3, 2018
1 parent 36c2939 commit a2cc3c3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,9 @@ describe('ReactComponentLifeCycle', () => {
ReactTestUtils.renderIntoDocument(<StatefulComponent />);
}).toWarnDev(
"Warning: Can't call setState on a component that is not yet mounted. " +
'This is a no-op, but it might indicate a bug in your application.\n\n' +
'To fix, assign the initial state in the StatefulComponent constructor. ' +
'If the state needs to reflect an external data source, ' +
'you may also add a componentDidMount lifecycle hook to StatefulComponent ' +
'and call setState there if the external data has changed.',
'This is a no-op, but it might indicate a bug in your application. ' +
'Instead, assign to `this.state` directly or define a `state = {};` ' +
'class property with the desired state in the StatefulComponent component.',
);

// Check deduplication; (no extra warnings should be logged).
Expand Down
16 changes: 6 additions & 10 deletions packages/react-dom/src/__tests__/ReactCompositeComponent-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,9 @@ describe('ReactCompositeComponent', () => {
const container = document.createElement('div');
expect(() => ReactDOM.render(<MyComponent />, container)).toWarnDev(
"Warning: Can't call forceUpdate on a component that is not yet mounted. " +
'This is a no-op, but it might indicate a bug in your application.\n\n' +
'To fix, assign the initial state in the MyComponent constructor. ' +
'If the state needs to reflect an external data source, ' +
'you may also add a componentDidMount lifecycle hook to MyComponent ' +
'and call setState there if the external data has changed.',
'This is a no-op, but it might indicate a bug in your application. ' +
'Instead, assign to `this.state` directly or define a `state = {};` ' +
'class property with the desired state in the MyComponent component.',
);

// No additional warning should be recorded
Expand All @@ -265,11 +263,9 @@ describe('ReactCompositeComponent', () => {
const container = document.createElement('div');
expect(() => ReactDOM.render(<MyComponent />, container)).toWarnDev(
"Warning: Can't call setState on a component that is not yet mounted. " +
'This is a no-op, but it might indicate a bug in your application.\n\n' +
'To fix, assign the initial state in the MyComponent constructor. ' +
'If the state needs to reflect an external data source, ' +
'you may also add a componentDidMount lifecycle hook to MyComponent ' +
'and call setState there if the external data has changed.',
'This is a no-op, but it might indicate a bug in your application. ' +
'Instead, assign to `this.state` directly or define a `state = {};` ' +
'class property with the desired state in the MyComponent component.',
);

// No additional warning should be recorded
Expand Down
9 changes: 3 additions & 6 deletions packages/react/src/ReactNoopUpdateQueue.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,11 @@ function warnNoop(publicInstance, callerName) {
warning(
false,
"Can't call %s on a component that is not yet mounted. " +
'This is a no-op, but it might indicate a bug in your application.\n\n' +
'To fix, assign the initial state in the %s constructor. ' +
'If the state needs to reflect an external data source, ' +
'you may also add a componentDidMount lifecycle hook to %s ' +
'and call setState there if the external data has changed.',
'This is a no-op, but it might indicate a bug in your application. ' +
'Instead, assign to `this.state` directly or define a `state = {};` ' +
'class property with the desired state in the %s component.',
callerName,
componentName,
componentName,
);
didWarnStateUpdateForUnmountedComponent[warningKey] = true;
}
Expand Down

0 comments on commit a2cc3c3

Please sign in to comment.