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 #10026.
  • Loading branch information
sebmarkbage committed Jun 27, 2017
1 parent 28318fe commit bbd97bd
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/renderers/dom/fiber/ReactDOMFiberEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit bbd97bd

Please sign in to comment.