diff --git a/packages/react-native/Libraries/DOM/Nodes/ReadOnlyNode.js b/packages/react-native/Libraries/DOM/Nodes/ReadOnlyNode.js index 867d93b2cc5cc3..01720a2ecae4ab 100644 --- a/packages/react-native/Libraries/DOM/Nodes/ReadOnlyNode.js +++ b/packages/react-native/Libraries/DOM/Nodes/ReadOnlyNode.js @@ -18,7 +18,6 @@ import type NodeList from '../OldStyleCollections/NodeList'; import type ReadOnlyElement from './ReadOnlyElement'; import {getFabricUIManager} from '../../ReactNative/FabricUIManager'; -import ReactFabric from '../../Renderer/shims/ReactFabric'; import {createNodeList} from '../OldStyleCollections/NodeList'; import nullthrows from 'nullthrows'; @@ -309,6 +308,9 @@ function setInstanceHandle( } export function getShadowNode(node: ReadOnlyNode): ?ShadowNode { + // Lazy import Fabric here to avoid DOM Node APIs classes from having side-effects. + // With a static import we can't use these classes for Paper-only variants. + const ReactFabric = require('../../Renderer/shims/ReactFabric'); return ReactFabric.getNodeFromInternalInstanceHandle(getInstanceHandle(node)); } @@ -353,6 +355,9 @@ function getNodeSiblingsAndPosition( export function getPublicInstanceFromInternalInstanceHandle( instanceHandle: InternalInstanceHandle, ): ?ReadOnlyNode { + // Lazy import Fabric here to avoid DOM Node APIs classes from having side-effects. + // With a static import we can't use these classes for Paper-only variants. + const ReactFabric = require('../../Renderer/shims/ReactFabric'); const mixedPublicInstance = ReactFabric.getPublicInstanceFromInternalInstanceHandle(instanceHandle); // $FlowExpectedError[incompatible-return] React defines public instances as "mixed" because it can't access the definition from React Native. diff --git a/packages/react-native/Libraries/ReactNative/ReactFabricPublicInstance/ReactFabricPublicInstance.js b/packages/react-native/Libraries/ReactNative/ReactFabricPublicInstance/ReactFabricPublicInstance.js index 2502bab8692302..54d8368ff2b8c6 100644 --- a/packages/react-native/Libraries/ReactNative/ReactFabricPublicInstance/ReactFabricPublicInstance.js +++ b/packages/react-native/Libraries/ReactNative/ReactFabricPublicInstance/ReactFabricPublicInstance.js @@ -88,5 +88,12 @@ export function getNodeFromPublicInstance( export function getInternalInstanceHandleFromPublicInstance( publicInstance: ReactFabricHostComponent | ReactNativeElement, ): InternalInstanceHandle { + // TODO(T174762768): Remove this once OSS versions of renderers will be synced. + // $FlowExpectedError[prop-missing] Keeping this for backwards-compatibility with the renderers versions in open source. + if (publicInstance._internalInstanceHandle != null) { + // $FlowExpectedError[incompatible-return] Keeping this for backwards-compatibility with the renderers versions in open source. + return publicInstance._internalInstanceHandle; + } + return publicInstance.__internalInstanceHandle; }