Skip to content

Commit 1287670

Browse files
Jack-Worksgaearon
andauthored
Fix: React cannot render in ShadowRoot (#15894)
* fix: render in shadow root * fix: flow typing * Remove types and turn invariant into warning Co-authored-by: Dan Abramov <dan.abramov@me.com>
1 parent e4afb2f commit 1287670

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

packages/react-dom/src/client/ReactDOMComponent.js

+14-10
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
} from '../events/EventRegistry';
1414

1515
import {canUseDOM} from 'shared/ExecutionEnvironment';
16-
import invariant from 'shared/invariant';
1716

1817
import {
1918
getValueForAttribute,
@@ -66,6 +65,7 @@ import {
6665
DOCUMENT_NODE,
6766
ELEMENT_NODE,
6867
COMMENT_NODE,
68+
DOCUMENT_FRAGMENT_NODE,
6969
} from '../shared/HTMLNodeType';
7070
import isCustomComponent from '../shared/isCustomComponent';
7171
import possibleStandardNames from '../shared/possibleStandardNames';
@@ -266,15 +266,19 @@ export function ensureListeningTo(
266266
rootContainerInstance.nodeType === COMMENT_NODE
267267
? rootContainerInstance.parentNode
268268
: rootContainerInstance;
269-
// Containers should only ever be element nodes. We do not
270-
// want to register events to document fragments or documents
271-
// with the modern plugin event system.
272-
invariant(
273-
rootContainerElement != null &&
274-
rootContainerElement.nodeType === ELEMENT_NODE,
275-
'ensureListeningTo(): received a container that was not an element node. ' +
276-
'This is likely a bug in React.',
277-
);
269+
if (__DEV__) {
270+
if (
271+
rootContainerElement == null ||
272+
(rootContainerElement.nodeType !== ELEMENT_NODE &&
273+
// This is to support rendering into a ShadowRoot:
274+
rootContainerElement.nodeType !== DOCUMENT_FRAGMENT_NODE)
275+
) {
276+
console.error(
277+
'ensureListeningTo(): received a container that was not an element node. ' +
278+
'This is likely a bug in React. Please file an issue.',
279+
);
280+
}
281+
}
278282
listenToReactEvent(
279283
reactPropEvent,
280284
((rootContainerElement: any): Element),

0 commit comments

Comments
 (0)