From 96d7e53e693d5676cb379876c2b1370596899f86 Mon Sep 17 00:00:00 2001 From: Haisheng Wu Date: Fri, 5 Jan 2018 10:51:02 -0800 Subject: [PATCH] topLevelUpdateWarnings is only for dev mode hence not necessary to have extra dev mode check. (#11924) --- packages/react-dom/src/client/ReactDOM.js | 73 +++++++++++------------ 1 file changed, 34 insertions(+), 39 deletions(-) diff --git a/packages/react-dom/src/client/ReactDOM.js b/packages/react-dom/src/client/ReactDOM.js index a46e57041d343..bfec81727faac 100644 --- a/packages/react-dom/src/client/ReactDOM.js +++ b/packages/react-dom/src/client/ReactDOM.js @@ -97,50 +97,45 @@ if (__DEV__) { } topLevelUpdateWarnings = (container: DOMContainer) => { - if (__DEV__) { - if ( - container._reactRootContainer && - container.nodeType !== COMMENT_NODE - ) { - const hostInstance = DOMRenderer.findHostInstanceWithNoPortals( - container._reactRootContainer._internalRoot.current, + if (container._reactRootContainer && container.nodeType !== COMMENT_NODE) { + const hostInstance = DOMRenderer.findHostInstanceWithNoPortals( + container._reactRootContainer._internalRoot.current, + ); + if (hostInstance) { + warning( + hostInstance.parentNode === container, + 'render(...): It looks like the React-rendered content of this ' + + 'container was removed without using React. This is not ' + + 'supported and will cause errors. Instead, call ' + + 'ReactDOM.unmountComponentAtNode to empty a container.', ); - if (hostInstance) { - warning( - hostInstance.parentNode === container, - 'render(...): It looks like the React-rendered content of this ' + - 'container was removed without using React. This is not ' + - 'supported and will cause errors. Instead, call ' + - 'ReactDOM.unmountComponentAtNode to empty a container.', - ); - } } + } - const isRootRenderedBySomeReact = !!container._reactRootContainer; - const rootEl = getReactRootElementInContainer(container); - const hasNonRootReactChild = !!( - rootEl && ReactDOMComponentTree.getInstanceFromNode(rootEl) - ); + const isRootRenderedBySomeReact = !!container._reactRootContainer; + const rootEl = getReactRootElementInContainer(container); + const hasNonRootReactChild = !!( + rootEl && ReactDOMComponentTree.getInstanceFromNode(rootEl) + ); - warning( - !hasNonRootReactChild || isRootRenderedBySomeReact, - 'render(...): Replacing React-rendered children with a new root ' + - 'component. If you intended to update the children of this node, ' + - 'you should instead have the existing children update their state ' + - 'and render the new components instead of calling ReactDOM.render.', - ); + warning( + !hasNonRootReactChild || isRootRenderedBySomeReact, + 'render(...): Replacing React-rendered children with a new root ' + + 'component. If you intended to update the children of this node, ' + + 'you should instead have the existing children update their state ' + + 'and render the new components instead of calling ReactDOM.render.', + ); - warning( - container.nodeType !== ELEMENT_NODE || - !((container: any): Element).tagName || - ((container: any): Element).tagName.toUpperCase() !== 'BODY', - 'render(): Rendering components directly into document.body is ' + - 'discouraged, since its children are often manipulated by third-party ' + - 'scripts and browser extensions. This may lead to subtle ' + - 'reconciliation issues. Try rendering into a container element created ' + - 'for your app.', - ); - } + warning( + container.nodeType !== ELEMENT_NODE || + !((container: any): Element).tagName || + ((container: any): Element).tagName.toUpperCase() !== 'BODY', + 'render(): Rendering components directly into document.body is ' + + 'discouraged, since its children are often manipulated by third-party ' + + 'scripts and browser extensions. This may lead to subtle ' + + 'reconciliation issues. Try rendering into a container element created ' + + 'for your app.', + ); }; warnOnInvalidCallback = function(callback: mixed, callerName: string) {