Skip to content

Commit

Permalink
Downgrade the warning level to console.warn()
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Aug 1, 2017
1 parent 4096c75 commit 4fc2346
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 22 deletions.
12 changes: 6 additions & 6 deletions src/renderers/__tests__/ReactCompositeComponent-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,31 +118,31 @@ describe('ReactCompositeComponent', () => {
}
}

spyOn(console, 'error');
spyOn(console, 'warn');
var markup = ReactDOMServer.renderToString(<Parent />);

// Old API based on heuristic
var container = document.createElement('div');
container.innerHTML = markup;
ReactDOM.render(<Parent />, container);
if (ReactDOMFeatureFlags.useFiber) {
expectDev(console.error.calls.count()).toBe(1);
expectDev(console.error.calls.argsFor(0)[0]).toContain(
expectDev(console.warn.calls.count()).toBe(1);
expectDev(console.warn.calls.argsFor(0)[0]).toContain(
'render(): Calling ReactDOM.render() to hydrate server-rendered markup ' +
'will stop working in React v17. Replace the ReactDOM.render() call ' +
'with ReactDOM.hydrate() if you want React to attach to the server HTML.',
);
} else {
expectDev(console.error.calls.count()).toBe(0);
expectDev(console.warn.calls.count()).toBe(0);
}

// New explicit API
console.error.calls.reset();
console.warn.calls.reset();
if (ReactDOMFeatureFlags.useFiber) {
container = document.createElement('div');
container.innerHTML = markup;
ReactDOM.hydrate(<Parent />, container);
expectDev(console.error.calls.count()).toBe(0);
expectDev(console.warn.calls.count()).toBe(0);
}
});

Expand Down
3 changes: 2 additions & 1 deletion src/renderers/dom/fiber/ReactDOMFiberEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ var {
var {precacheFiberNode, updateFiberProps} = ReactDOMComponentTree;

if (__DEV__) {
var lowPriorityWarning = require('lowPriorityWarning');
var warning = require('fbjs/lib/warning');
var validateDOMNesting = require('validateDOMNesting');
var {updatedAncestorInfo} = validateDOMNesting;
Expand Down Expand Up @@ -608,7 +609,7 @@ function renderSubtreeIntoContainer(
if (__DEV__) {
if (shouldHydrate && !forceHydrate && !warnedAboutHydrateAPI) {
warnedAboutHydrateAPI = true;
warning(
lowPriorityWarning(
false,
'render(): Calling ReactDOM.render() to hydrate server-rendered markup ' +
'will stop working in React v17. Replace the ReactDOM.render() call ' +
Expand Down
24 changes: 13 additions & 11 deletions src/renderers/dom/shared/__tests__/ReactRenderDocument-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,19 @@ describe('rendering React components at document', () => {
describe('with old implicit hydration API', () => {
function expectDeprecationWarningWithFiber() {
if (ReactDOMFeatureFlags.useFiber) {
expectDev(console.error.calls.count()).toBe(1);
expectDev(console.error.calls.argsFor(0)[0]).toContain(
expectDev(console.warn.calls.count()).toBe(1);
expectDev(console.warn.calls.argsFor(0)[0]).toContain(
'render(): Calling ReactDOM.render() to hydrate server-rendered markup ' +
'will stop working in React v17. Replace the ReactDOM.render() call ' +
'with ReactDOM.hydrate() if you want React to attach to the server HTML.',
);
} else {
expectDev(console.error.calls.count()).toBe(0);
expectDev(console.warn.calls.count()).toBe(0);
}
}

it('should be able to adopt server markup', () => {
spyOn(console, 'error');
spyOn(console, 'warn');
class Root extends React.Component {
render() {
return (
Expand Down Expand Up @@ -82,7 +82,7 @@ describe('rendering React components at document', () => {
});

it('should not be able to unmount component from document node', () => {
spyOn(console, 'error');
spyOn(console, 'warn');
class Root extends React.Component {
render() {
return (
Expand Down Expand Up @@ -119,7 +119,7 @@ describe('rendering React components at document', () => {
});

it('should not be able to switch root constructors', () => {
spyOn(console, 'error');
spyOn(console, 'warn');
class Component extends React.Component {
render() {
return (
Expand Down Expand Up @@ -175,7 +175,7 @@ describe('rendering React components at document', () => {
});

it('should be able to mount into document', () => {
spyOn(console, 'error');
spyOn(console, 'warn');
class Component extends React.Component {
render() {
return (
Expand Down Expand Up @@ -234,16 +234,18 @@ describe('rendering React components at document', () => {
var testDocument = getTestDocument(markup);

if (ReactDOMFeatureFlags.useFiber) {
spyOn(console, 'warn');
spyOn(console, 'error');
ReactDOM.render(<Component text="Hello world" />, testDocument);
expect(testDocument.body.innerHTML).toBe('Hello world');
expectDev(console.error.calls.count()).toBe(2);
expectDev(console.error.calls.argsFor(0)[0]).toContain(
expectDev(console.warn.calls.count()).toBe(1);
expectDev(console.warn.calls.argsFor(0)[0]).toContain(
'render(): Calling ReactDOM.render() to hydrate server-rendered markup ' +
'will stop working in React v17. Replace the ReactDOM.render() call ' +
'with ReactDOM.hydrate() if you want React to attach to the server HTML.',
);
expectDev(console.error.calls.argsFor(1)[0]).toContain(
expectDev(console.error.calls.count()).toBe(1);
expectDev(console.error.calls.argsFor(0)[0]).toContain(
'Warning: Text content did not match.',
);
} else {
Expand Down Expand Up @@ -302,7 +304,7 @@ describe('rendering React components at document', () => {
});

it('supports findDOMNode on full-page components', () => {
spyOn(console, 'error');
spyOn(console, 'warn');
var tree = (
<html>
<head>
Expand Down
10 changes: 6 additions & 4 deletions src/renderers/dom/shared/__tests__/ReactServerRendering-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ describe('ReactDOMServer', () => {
});

it('should have the correct mounting behavior (old hydrate API)', () => {
spyOn(console, 'warn');
spyOn(console, 'error');
// This test is testing client-side behavior.
ExecutionEnvironment.canUseDOM = true;
Expand Down Expand Up @@ -298,16 +299,16 @@ describe('ReactDOMServer', () => {
var instance = ReactDOM.render(<TestComponent name="x" />, element);
expect(mountCount).toEqual(3);
if (ReactDOMFeatureFlags.useFiber) {
expectDev(console.error.calls.count()).toBe(1);
expectDev(console.error.calls.argsFor(0)[0]).toContain(
expectDev(console.warn.calls.count()).toBe(1);
expectDev(console.warn.calls.argsFor(0)[0]).toContain(
'render(): Calling ReactDOM.render() to hydrate server-rendered markup ' +
'will stop working in React v17. Replace the ReactDOM.render() call ' +
'with ReactDOM.hydrate() if you want React to attach to the server HTML.',
);
} else {
expectDev(console.error.calls.count()).toBe(0);
expectDev(console.warn.calls.count()).toBe(0);
}
console.error.calls.reset();
console.warn.calls.reset();

var expectedMarkup = lastMarkup;
if (ReactDOMFeatureFlags.useFiber) {
Expand Down Expand Up @@ -350,6 +351,7 @@ describe('ReactDOMServer', () => {
expect(numClicks).toEqual(1);
ReactTestUtils.Simulate.click(ReactDOM.findDOMNode(instance.refs.span));
expect(numClicks).toEqual(2);
expectDev(console.warn.calls.count()).toBe(0);
expectDev(console.error.calls.count()).toBe(0);
});

Expand Down

0 comments on commit 4fc2346

Please sign in to comment.