Skip to content

Commit

Permalink
refactor[ReadOnlyNode]: lazy import ReactFabric
Browse files Browse the repository at this point in the history
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.

Differential Revision: D52784886

fbshipit-source-id: c130e340da226e1a3bab757a27e6da689e596b80
  • Loading branch information
Ruslan Lesiutin authored and facebook-github-bot committed Jan 15, 2024
1 parent 668a011 commit f8ddd1e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/react-native/Libraries/DOM/Nodes/ReadOnlyNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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));
}

Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit f8ddd1e

Please sign in to comment.