Skip to content

Commit

Permalink
Warn if the 2nd+ child is a "root" element but not first
Browse files Browse the repository at this point in the history
This triggers our non-reuse mode. This is covered by ReactMount already but
the test doesn't pass yet without also landing facebook#10026.
  • Loading branch information
sebmarkbage committed Jun 27, 2017
1 parent 28318fe commit 37a0139
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/renderers/dom/fiber/ReactDOMFiberEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -499,8 +499,22 @@ function renderSubtreeIntoContainer(
// First clear any existing content.
// TODO: Figure out the best heuristic here.
if (!shouldReuseContent(container)) {
let warned = false;
while (container.lastChild) {
container.removeChild(container.lastChild);
let 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);
Expand Down

0 comments on commit 37a0139

Please sign in to comment.