Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix[getInternalInstanceHandleFromPublicInstance]: make it backwards compatible with previous Fabric implementation #42250

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Loading