From fc01ed92aeb731aa9bf8b4343edd166405a09e3c Mon Sep 17 00:00:00 2001 From: Jack Works Date: Mon, 3 Feb 2020 20:39:19 +0800 Subject: [PATCH] [DOM] Fix findDOMNode throw on ShadowRoot --- packages/react-dom/src/client/ReactDOMLegacy.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/react-dom/src/client/ReactDOMLegacy.js b/packages/react-dom/src/client/ReactDOMLegacy.js index 519a0be3bb551..3479e26321ac1 100644 --- a/packages/react-dom/src/client/ReactDOMLegacy.js +++ b/packages/react-dom/src/client/ReactDOMLegacy.js @@ -22,6 +22,7 @@ import { DOCUMENT_NODE, ELEMENT_NODE, COMMENT_NODE, + DOCUMENT_FRAGMENT_NODE, } from '../shared/HTMLNodeType'; import { @@ -222,7 +223,7 @@ function legacyRenderSubtreeIntoContainer( } export function findDOMNode( - componentOrElement: Element | ?React$Component, + componentOrElement: Element | DocumentFragment | ?React$Component, ): null | Element | Text { if (__DEV__) { let owner = (ReactCurrentOwner.current: any); @@ -244,7 +245,8 @@ export function findDOMNode( if (componentOrElement == null) { return null; } - if ((componentOrElement: any).nodeType === ELEMENT_NODE) { + const nodeType = (componentOrElement: any).nodeType; + if (nodeType === ELEMENT_NODE || nodeType === DOCUMENT_FRAGMENT_NODE) { return (componentOrElement: any); } if (__DEV__) {