Skip to content

Commit 55da9e5

Browse files
hoxyqfacebook-github-bot
authored andcommitted
[skip ci] refactor[ReadOnlyNode]: lazy import ReactFabric (#42285)
Summary: Changelog: [Internal] Having a static import of `ReactFabric` blocks from using `ReactNativeElement` class for Paper-only applications. Although DOM Node APIs are Fabric-only, the ability to use `instanceof ReactNativeElement` is a nice tool for gating purposes, which currently can't be used because of the static import. Reviewed By: rubennorte Differential Revision: D52784886
1 parent 0c7008f commit 55da9e5

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

packages/react-native/Libraries/DOM/Nodes/ReadOnlyNode.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import type NodeList from '../OldStyleCollections/NodeList';
1818
import type ReadOnlyElement from './ReadOnlyElement';
1919

2020
import {getFabricUIManager} from '../../ReactNative/FabricUIManager';
21-
import ReactFabric from '../../Renderer/shims/ReactFabric';
2221
import {createNodeList} from '../OldStyleCollections/NodeList';
2322
import nullthrows from 'nullthrows';
2423

@@ -309,6 +308,9 @@ function setInstanceHandle(
309308
}
310309

311310
export function getShadowNode(node: ReadOnlyNode): ?ShadowNode {
311+
// Lazy import Fabric here to avoid DOM Node APIs classes from having side-effects.
312+
// With a static import we can't use these classes for Paper-only variants.
313+
const ReactFabric = require('../../Renderer/shims/ReactFabric');
312314
return ReactFabric.getNodeFromInternalInstanceHandle(getInstanceHandle(node));
313315
}
314316

@@ -353,6 +355,9 @@ function getNodeSiblingsAndPosition(
353355
export function getPublicInstanceFromInternalInstanceHandle(
354356
instanceHandle: InternalInstanceHandle,
355357
): ?ReadOnlyNode {
358+
// Lazy import Fabric here to avoid DOM Node APIs classes from having side-effects.
359+
// With a static import we can't use these classes for Paper-only variants.
360+
const ReactFabric = require('../../Renderer/shims/ReactFabric');
356361
const mixedPublicInstance =
357362
ReactFabric.getPublicInstanceFromInternalInstanceHandle(instanceHandle);
358363
// $FlowExpectedError[incompatible-return] React defines public instances as "mixed" because it can't access the definition from React Native.

0 commit comments

Comments
 (0)