Skip to content

Commit 822541c

Browse files
committed
Remove types and turn invariant into warning
1 parent acf8b96 commit 822541c

File tree

2 files changed

+26
-27
lines changed

2 files changed

+26
-27
lines changed

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

Lines changed: 25 additions & 25 deletions
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,
@@ -257,7 +256,7 @@ if (__DEV__) {
257256
}
258257

259258
export function ensureListeningTo(
260-
rootContainerInstance: Element | Node | ShadowRoot,
259+
rootContainerInstance: Element | Node,
261260
reactPropEvent: string,
262261
targetElement: Element | null,
263262
): void {
@@ -267,18 +266,19 @@ export function ensureListeningTo(
267266
rootContainerInstance.nodeType === COMMENT_NODE
268267
? rootContainerInstance.parentNode
269268
: rootContainerInstance;
270-
// Containers should only ever be element nodes. We do not
271-
// want to register events to document fragments or documents
272-
// with the modern plugin event system.
273-
invariant(
274-
rootContainerElement != null &&
275-
(rootContainerElement.nodeType === ELEMENT_NODE ||
276-
(rootContainerElement.nodeType === DOCUMENT_FRAGMENT_NODE &&
277-
// $FlowFixMe GH issue #8457
278-
((rootContainerElement: any): ShadowRoot).mode)),
279-
'ensureListeningTo(): received a container that was not an element node. ' +
280-
'This is likely a bug in React.',
281-
);
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+
}
282282
listenToReactEvent(
283283
reactPropEvent,
284284
((rootContainerElement: any): Element),
@@ -287,7 +287,7 @@ export function ensureListeningTo(
287287
}
288288

289289
function getOwnerDocumentFromRootContainer(
290-
rootContainerElement: Element | Document | ShadowRoot,
290+
rootContainerElement: Element | Document,
291291
): Document {
292292
return rootContainerElement.nodeType === DOCUMENT_NODE
293293
? (rootContainerElement: any)
@@ -312,7 +312,7 @@ export function trapClickOnNonInteractiveElement(node: HTMLElement) {
312312
function setInitialDOMProperties(
313313
tag: string,
314314
domElement: Element,
315-
rootContainerElement: Element | Document | ShadowRoot,
315+
rootContainerElement: Element | Document,
316316
nextProps: Object,
317317
isCustomComponentTag: boolean,
318318
): void {
@@ -397,7 +397,7 @@ function updateDOMProperties(
397397
export function createElement(
398398
type: string,
399399
props: Object,
400-
rootContainerElement: Element | Document | ShadowRoot,
400+
rootContainerElement: Element | Document,
401401
parentNamespace: string,
402402
): Element {
403403
let isCustomComponentTag;
@@ -503,7 +503,7 @@ export function createElement(
503503

504504
export function createTextNode(
505505
text: string,
506-
rootContainerElement: Element | Document | ShadowRoot,
506+
rootContainerElement: Element | Document,
507507
): Text {
508508
return getOwnerDocumentFromRootContainer(rootContainerElement).createTextNode(
509509
text,
@@ -514,7 +514,7 @@ export function setInitialProperties(
514514
domElement: Element,
515515
tag: string,
516516
rawProps: Object,
517-
rootContainerElement: Element | Document | ShadowRoot,
517+
rootContainerElement: Element | Document,
518518
): void {
519519
const isCustomComponentTag = isCustomComponent(tag, rawProps);
520520
if (__DEV__) {
@@ -649,7 +649,7 @@ export function diffProperties(
649649
tag: string,
650650
lastRawProps: Object,
651651
nextRawProps: Object,
652-
rootContainerElement: Element | Document | ShadowRoot,
652+
rootContainerElement: Element | Document,
653653
): null | Array<mixed> {
654654
if (__DEV__) {
655655
validatePropertiesInDevelopment(tag, nextRawProps);
@@ -914,7 +914,7 @@ export function diffHydratedProperties(
914914
tag: string,
915915
rawProps: Object,
916916
parentNamespace: string,
917-
rootContainerElement: Element | Document | ShadowRoot,
917+
rootContainerElement: Element | Document,
918918
): null | Array<mixed> {
919919
let isCustomComponentTag;
920920
let extraAttributeNames: Set<string>;
@@ -1213,7 +1213,7 @@ export function warnForUnmatchedText(textNode: Text, text: string) {
12131213
}
12141214

12151215
export function warnForDeletedHydratableElement(
1216-
parentNode: Element | Document | ShadowRoot,
1216+
parentNode: Element | Document,
12171217
child: Element,
12181218
) {
12191219
if (__DEV__) {
@@ -1230,7 +1230,7 @@ export function warnForDeletedHydratableElement(
12301230
}
12311231

12321232
export function warnForDeletedHydratableText(
1233-
parentNode: Element | Document | ShadowRoot,
1233+
parentNode: Element | Document,
12341234
child: Text,
12351235
) {
12361236
if (__DEV__) {
@@ -1247,7 +1247,7 @@ export function warnForDeletedHydratableText(
12471247
}
12481248

12491249
export function warnForInsertedHydratedElement(
1250-
parentNode: Element | Document | ShadowRoot,
1250+
parentNode: Element | Document,
12511251
tag: string,
12521252
props: Object,
12531253
) {
@@ -1265,7 +1265,7 @@ export function warnForInsertedHydratedElement(
12651265
}
12661266

12671267
export function warnForInsertedHydratedText(
1268-
parentNode: Element | Document | ShadowRoot,
1268+
parentNode: Element | Document,
12691269
text: string,
12701270
) {
12711271
if (__DEV__) {

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ export type EventTargetChildElement = {
104104
};
105105
export type Container =
106106
| (Element & {_reactRootContainer?: RootType, ...})
107-
| (Document & {_reactRootContainer?: RootType, ...})
108-
| (ShadowRoot & {_reactRootContainer?: RootType, ...});
107+
| (Document & {_reactRootContainer?: RootType, ...});
109108
export type Instance = Element;
110109
export type TextInstance = Text;
111110
export type SuspenseInstance = Comment & {_reactRetry?: () => void, ...};

0 commit comments

Comments
 (0)