Skip to content

Commit

Permalink
Remove unnecessary warnings (#18135)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Feb 27, 2020
1 parent f9c0a45 commit 849e832
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 195 deletions.
37 changes: 0 additions & 37 deletions packages/react-dom/src/__tests__/ReactCompositeComponent-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -493,43 +493,6 @@ describe('ReactCompositeComponent', () => {
ReactDOM.render(<Component prop={123} />, container);
});

it('should warn about `setState` in getChildContext', () => {
const container = document.createElement('div');

let renderPasses = 0;

class Component extends React.Component {
state = {value: 0};

getChildContext() {
if (this.state.value === 0) {
this.setState({value: 1});
}
}

render() {
renderPasses++;
return <div />;
}
}
Component.childContextTypes = {};

let instance;

expect(() => {
instance = ReactDOM.render(<Component />, container);
}).toErrorDev(
'Warning: setState(...): Cannot call setState() inside getChildContext()',
);

expect(renderPasses).toBe(2);
expect(instance.state.value).toBe(1);

// Test deduplication; (no additional warnings are expected).
ReactDOM.unmountComponentAtNode(container);
ReactDOM.render(<Component />, container);
});

it('should cleanup even if render() fatals', () => {
class BadComponent extends React.Component {
render() {
Expand Down
47 changes: 0 additions & 47 deletions packages/react-dom/src/__tests__/ReactDOMComponent-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1242,53 +1242,6 @@ describe('ReactDOMComponent', () => {
);
});

it('should emit a warning once for a named custom component using shady DOM', () => {
const defaultCreateElement = document.createElement.bind(document);

try {
document.createElement = element => {
const container = defaultCreateElement(element);
container.shadyRoot = {};
return container;
};
class ShadyComponent extends React.Component {
render() {
return <polymer-component />;
}
}
const node = document.createElement('div');
expect(() => ReactDOM.render(<ShadyComponent />, node)).toErrorDev(
'ShadyComponent is using shady DOM. Using shady DOM with React can ' +
'cause things to break subtly.',
);
mountComponent({is: 'custom-shady-div2'});
} finally {
document.createElement = defaultCreateElement;
}
});

it('should emit a warning once for an unnamed custom component using shady DOM', () => {
const defaultCreateElement = document.createElement.bind(document);

try {
document.createElement = element => {
const container = defaultCreateElement(element);
container.shadyRoot = {};
return container;
};

expect(() => mountComponent({is: 'custom-shady-div'})).toErrorDev(
'A component is using shady DOM. Using shady DOM with React can ' +
'cause things to break subtly.',
);

// No additional warnings are expected
mountComponent({is: 'custom-shady-div2'});
} finally {
document.createElement = defaultCreateElement;
}
});

it('should treat menuitem as a void element but still create the closing tag', () => {
// menuitem is not implemented in jsdom, so this triggers the unknown warning error
const container = document.createElement('div');
Expand Down
27 changes: 0 additions & 27 deletions packages/react-dom/src/client/ReactDOMComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* @flow
*/

// TODO: direct imports like some-package/src/* are bad. Fix me.
import {getCurrentFiberOwnerNameInDevOrNull} from 'react-reconciler/src/ReactCurrentFiber';
import {registrationNameModules} from 'legacy-events/EventPluginRegistry';
import {canUseDOM} from 'shared/ExecutionEnvironment';
import endsWith from 'shared/endsWith';
Expand Down Expand Up @@ -90,7 +88,6 @@ import {
import {legacyListenToEvent} from '../events/DOMLegacyEventPluginSystem';

let didWarnInvalidHydration = false;
let didWarnShadyDOM = false;
let didWarnScriptTags = false;

const DANGEROUSLY_SET_INNER_HTML = 'dangerouslySetInnerHTML';
Expand Down Expand Up @@ -509,18 +506,6 @@ export function setInitialProperties(
const isCustomComponentTag = isCustomComponent(tag, rawProps);
if (__DEV__) {
validatePropertiesInDevelopment(tag, rawProps);
if (
isCustomComponentTag &&
!didWarnShadyDOM &&
(domElement: any).shadyRoot
) {
console.error(
'%s is using shady DOM. Using shady DOM with React can ' +
'cause things to break subtly.',
getCurrentFiberOwnerNameInDevOrNull() || 'A component',
);
didWarnShadyDOM = true;
}
}

// TODO: Make sure that we check isMounted before firing any of these events.
Expand Down Expand Up @@ -906,18 +891,6 @@ export function diffHydratedProperties(
suppressHydrationWarning = rawProps[SUPPRESS_HYDRATION_WARNING] === true;
isCustomComponentTag = isCustomComponent(tag, rawProps);
validatePropertiesInDevelopment(tag, rawProps);
if (
isCustomComponentTag &&
!didWarnShadyDOM &&
(domElement: any).shadyRoot
) {
console.error(
'%s is using shady DOM. Using shady DOM with React can ' +
'cause things to break subtly.',
getCurrentFiberOwnerNameInDevOrNull() || 'A component',
);
didWarnShadyDOM = true;
}
}

// TODO: Make sure that we check isMounted before firing any of these events.
Expand Down
12 changes: 5 additions & 7 deletions packages/react-reconciler/src/ReactCurrentFiber.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import getComponentName from 'shared/getComponentName';

const ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;

type LifeCyclePhase = 'render' | 'getChildContext';

function describeFiber(fiber: Fiber): string {
switch (fiber.tag) {
case HostRoot:
Expand Down Expand Up @@ -57,7 +55,7 @@ export function getStackByFiberInDevAndProd(workInProgress: Fiber): string {
}

export let current: Fiber | null = null;
export let phase: LifeCyclePhase | null = null;
export let isRendering: boolean = false;

export function getCurrentFiberOwnerNameInDevOrNull(): string | null {
if (__DEV__) {
Expand Down Expand Up @@ -88,20 +86,20 @@ export function resetCurrentFiber() {
if (__DEV__) {
ReactDebugCurrentFrame.getCurrentStack = null;
current = null;
phase = null;
isRendering = false;
}
}

export function setCurrentFiber(fiber: Fiber) {
if (__DEV__) {
ReactDebugCurrentFrame.getCurrentStack = getCurrentFiberStackInDev;
current = fiber;
phase = null;
isRendering = false;
}
}

export function setCurrentPhase(lifeCyclePhase: LifeCyclePhase | null) {
export function setIsRendering(rendering: boolean) {
if (__DEV__) {
phase = lifeCyclePhase;
isRendering = rendering;
}
}
36 changes: 11 additions & 25 deletions packages/react-reconciler/src/ReactFiberBeginWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ import ReactStrictModeWarnings from './ReactStrictModeWarnings';
import {refineResolvedLazyComponent} from 'shared/ReactLazyComponent';
import {REACT_LAZY_TYPE, getIteratorFn} from 'shared/ReactSymbols';
import {
setCurrentPhase,
getCurrentFiberOwnerNameInDevOrNull,
getCurrentFiberStackInDev,
setIsRendering,
} from './ReactCurrentFiber';
import {startWorkTimer, cancelWorkTimer} from './ReactDebugFiberPerf';
import {
Expand Down Expand Up @@ -193,7 +193,6 @@ let didWarnAboutContextTypeOnFunctionComponent;
let didWarnAboutGetDerivedStateOnFunctionComponent;
let didWarnAboutFunctionRefs;
export let didWarnAboutReassigningProps;
let didWarnAboutMaxDuration;
let didWarnAboutRevealOrder;
let didWarnAboutTailOptions;
let didWarnAboutDefaultPropsOnFunctionComponent;
Expand All @@ -205,7 +204,6 @@ if (__DEV__) {
didWarnAboutGetDerivedStateOnFunctionComponent = {};
didWarnAboutFunctionRefs = {};
didWarnAboutReassigningProps = false;
didWarnAboutMaxDuration = false;
didWarnAboutRevealOrder = {};
didWarnAboutTailOptions = {};
didWarnAboutDefaultPropsOnFunctionComponent = {};
Expand Down Expand Up @@ -312,7 +310,7 @@ function updateForwardRef(
prepareToReadContext(workInProgress, renderExpirationTime);
if (__DEV__) {
ReactCurrentOwner.current = workInProgress;
setCurrentPhase('render');
setIsRendering(true);
nextChildren = renderWithHooks(
current,
workInProgress,
Expand All @@ -337,7 +335,7 @@ function updateForwardRef(
);
}
}
setCurrentPhase(null);
setIsRendering(false);
} else {
nextChildren = renderWithHooks(
current,
Expand Down Expand Up @@ -644,7 +642,7 @@ function updateFunctionComponent(
prepareToReadContext(workInProgress, renderExpirationTime);
if (__DEV__) {
ReactCurrentOwner.current = workInProgress;
setCurrentPhase('render');
setIsRendering(true);
nextChildren = renderWithHooks(
current,
workInProgress,
Expand All @@ -669,7 +667,7 @@ function updateFunctionComponent(
);
}
}
setCurrentPhase(null);
setIsRendering(false);
} else {
nextChildren = renderWithHooks(
current,
Expand Down Expand Up @@ -720,7 +718,7 @@ function updateBlock(
prepareToReadContext(workInProgress, renderExpirationTime);
if (__DEV__) {
ReactCurrentOwner.current = workInProgress;
setCurrentPhase('render');
setIsRendering(true);
nextChildren = renderWithHooks(
current,
workInProgress,
Expand All @@ -745,7 +743,7 @@ function updateBlock(
);
}
}
setCurrentPhase(null);
setIsRendering(false);
} else {
nextChildren = renderWithHooks(
current,
Expand Down Expand Up @@ -923,15 +921,15 @@ function finishClassComponent(
}
} else {
if (__DEV__) {
setCurrentPhase('render');
setIsRendering(true);
nextChildren = instance.render();
if (
debugRenderPhaseSideEffectsForStrictMode &&
workInProgress.mode & StrictMode
) {
instance.render();
}
setCurrentPhase(null);
setIsRendering(false);
} else {
nextChildren = instance.render();
}
Expand Down Expand Up @@ -1637,18 +1635,6 @@ function updateSuspenseComponent(

pushSuspenseContext(workInProgress, suspenseContext);

if (__DEV__) {
if ('maxDuration' in nextProps) {
if (!didWarnAboutMaxDuration) {
didWarnAboutMaxDuration = true;
console.error(
'maxDuration has been removed from React. ' +
'Remove the maxDuration prop.',
);
}
}
}

// This next part is a bit confusing. If the children timeout, we switch to
// showing the fallback children in place of the "primary" children.
// However, we don't want to delete the primary children because then their
Expand Down Expand Up @@ -2732,9 +2718,9 @@ function updateContextConsumer(
let newChildren;
if (__DEV__) {
ReactCurrentOwner.current = workInProgress;
setCurrentPhase('render');
setIsRendering(true);
newChildren = render(newValue);
setCurrentPhase(null);
setIsRendering(false);
} else {
newChildren = render(newValue);
}
Expand Down
8 changes: 1 addition & 7 deletions packages/react-reconciler/src/ReactFiberContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import getComponentName from 'shared/getComponentName';
import invariant from 'shared/invariant';
import checkPropTypes from 'prop-types/checkPropTypes';

import {setCurrentPhase, getCurrentFiberStackInDev} from './ReactCurrentFiber';
import {getCurrentFiberStackInDev} from './ReactCurrentFiber';
import {startPhaseTimer, stopPhaseTimer} from './ReactDebugFiberPerf';
import {createCursor, push, pop} from './ReactFiberStack';

Expand Down Expand Up @@ -210,15 +210,9 @@ function processChildContext(
}

let childContext;
if (__DEV__) {
setCurrentPhase('getChildContext');
}
startPhaseTimer(fiber, 'getChildContext');
childContext = instance.getChildContext();
stopPhaseTimer();
if (__DEV__) {
setCurrentPhase(null);
}
for (let contextKey in childContext) {
invariant(
contextKey in childContextTypes,
Expand Down
4 changes: 2 additions & 2 deletions packages/react-reconciler/src/ReactFiberReconciler.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ import {
import {createUpdate, enqueueUpdate} from './ReactUpdateQueue';
import {
getStackByFiberInDevAndProd,
phase as ReactCurrentFiberPhase,
isRendering as ReactCurrentFiberIsRendering,
current as ReactCurrentFiberCurrent,
} from './ReactCurrentFiber';
import {StrictMode} from './ReactTypeOfMode';
Expand Down Expand Up @@ -259,7 +259,7 @@ export function updateContainer(

if (__DEV__) {
if (
ReactCurrentFiberPhase === 'render' &&
ReactCurrentFiberIsRendering &&
ReactCurrentFiberCurrent !== null &&
!didWarnAboutNestedUpdates
) {
Expand Down
Loading

0 comments on commit 849e832

Please sign in to comment.