Skip to content

Commit

Permalink
Dedupe and DEV-only deprecation warning in server renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
bvaughn committed Jan 17, 2018
1 parent 1047182 commit 035c220
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ describe('ReactDOMServerLifecycles', () => {
'Warning: Component: componentWillMount() is deprecated and will be removed ' +
'in the next major version. Please use unsafe_componentWillMount() instead.',
);

// De-duped
ReactDOMServer.renderToString(<Component />);
});

it('should update instance.state with value returned from getDerivedStateFromProps', () => {
Expand Down
21 changes: 15 additions & 6 deletions packages/react-dom/src/server/ReactPartialRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ let didWarnDefaultTextareaValue = false;
let didWarnInvalidOptionChildren = false;
const didWarnAboutNoopUpdateForComponent = {};
const didWarnAboutBadClass = {};
const didWarnAboutDeprecatedWillMount = {};
const didWarnAboutUndefinedDerivedState = {};
const valuePropNames = ['value', 'defaultValue'];
const newlineEatingTags = {
Expand Down Expand Up @@ -487,12 +488,20 @@ function resolve(
}
if (inst.unsafe_componentWillMount || inst.componentWillMount) {
if (inst.componentWillMount) {
warning(
false,
'%s: componentWillMount() is deprecated and will be removed in the ' +
'next major version. Please use unsafe_componentWillMount() instead.',
getComponentName(Component) || 'Unknown',
);
if (__DEV__) {
const componentName = getComponentName(Component) || 'Unknown';

if (!didWarnAboutDeprecatedWillMount[componentName]) {
warning(
false,
'%s: componentWillMount() is deprecated and will be removed in the ' +
'next major version. Please use unsafe_componentWillMount() instead.',
componentName,
);
didWarnAboutDeprecatedWillMount[componentName] = true;
}
}

inst.componentWillMount();
} else {
inst.unsafe_componentWillMount();
Expand Down

0 comments on commit 035c220

Please sign in to comment.