Skip to content

Commit bbd97bd

Browse files
committed
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 facebook#10026.
1 parent 28318fe commit bbd97bd

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/renderers/dom/fiber/ReactDOMFiberEntry.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,8 +499,25 @@ function renderSubtreeIntoContainer(
499499
// First clear any existing content.
500500
// TODO: Figure out the best heuristic here.
501501
if (!shouldReuseContent(container)) {
502-
while (container.lastChild) {
503-
container.removeChild(container.lastChild);
502+
let warned = false;
503+
let rootSibling;
504+
while ((rootSibling = container.lastChild)) {
505+
if (__DEV__) {
506+
if (
507+
!warned &&
508+
rootSibling.nodeType === ELEMENT_NODE &&
509+
(rootSibling: any).hasAttribute(ID_ATTRIBUTE_NAME)
510+
) {
511+
warned = true;
512+
warning(
513+
false,
514+
'render(): Target node has markup rendered by React, but there ' +
515+
'are unrelated nodes as well. This is most commonly caused by ' +
516+
'white-space inserted around server-rendered markup.',
517+
);
518+
}
519+
}
520+
container.removeChild(rootSibling);
504521
}
505522
}
506523
const newRoot = DOMRenderer.createContainer(container);

0 commit comments

Comments
 (0)