Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Follow up: make new warning less wordy #12532

Merged
merged 1 commit into from
Apr 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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