From bbd97bd02a57b6be34fcc5557d3cc35a45a60dd2 Mon Sep 17 00:00:00 2001 From: Sebastian Markbage Date: Tue, 27 Jun 2017 15:50:45 -0700 Subject: [PATCH] Warn if the 2nd+ child is a "root" element but not first This triggers our non-reuse mode. This is covered by ReactMount already but the test doesn't pass yet without also landing #10026. --- src/renderers/dom/fiber/ReactDOMFiberEntry.js | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/renderers/dom/fiber/ReactDOMFiberEntry.js b/src/renderers/dom/fiber/ReactDOMFiberEntry.js index 8d9a8369577df..7997326f9aca7 100644 --- a/src/renderers/dom/fiber/ReactDOMFiberEntry.js +++ b/src/renderers/dom/fiber/ReactDOMFiberEntry.js @@ -499,8 +499,25 @@ function renderSubtreeIntoContainer( // First clear any existing content. // TODO: Figure out the best heuristic here. if (!shouldReuseContent(container)) { - while (container.lastChild) { - container.removeChild(container.lastChild); + let warned = false; + let rootSibling; + while ((rootSibling = container.lastChild)) { + if (__DEV__) { + if ( + !warned && + rootSibling.nodeType === ELEMENT_NODE && + (rootSibling: any).hasAttribute(ID_ATTRIBUTE_NAME) + ) { + warned = true; + warning( + false, + 'render(): Target node has markup rendered by React, but there ' + + 'are unrelated nodes as well. This is most commonly caused by ' + + 'white-space inserted around server-rendered markup.', + ); + } + } + container.removeChild(rootSibling); } } const newRoot = DOMRenderer.createContainer(container);