Skip to content

Commit

Permalink
Prepare ReactNativePrivateInterface for new React renderer calls to h…
Browse files Browse the repository at this point in the history
…andle root/document nodes (facebook#49010)

Summary:

Changelog: [internal]

This adds a stub method for `ReactNativePrivateInterface.createPublicRootInstance`, which just returns `null` for now, so we can synchronize the React renderer that will try to use it to create root instances.

Initially, this will not do anything and React will just pass the `null` value around. When we implement the document API, we will return a proper instance and React will pass it to `createPublicInstance` so we can link things at runtime.

Reviewed By: javache

Differential Revision: D68561173
  • Loading branch information
rubennorte authored and facebook-github-bot committed Jan 29, 2025
1 parent 3041bba commit b3e6519
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import type {
Node,
ViewConfig,
} from '../../Renderer/shims/ReactNativeTypes';
import type {RootTag} from '../RootTag';
import type ReactFabricHostComponent from './ReactFabricHostComponent';

import * as ReactNativeFeatureFlags from '../../../src/private/featureflags/ReactNativeFeatureFlags';
Expand All @@ -34,10 +35,19 @@ let ReadOnlyTextClass: Class<ReadOnlyText>;
// Lazy loaded to avoid evaluating the module when using the legacy renderer.
let RendererProxy: RendererProxyT;

// This is just a temporary placeholder so ReactFabric doesn't crash when synced.
type PublicRootInstance = null;

export function createPublicRootInstance(rootTag: RootTag): PublicRootInstance {
// This is just a placeholder so ReactFabric doesn't crash when synced.
return null;
}

export function createPublicInstance(
tag: number,
viewConfig: ViewConfig,
internalInstanceHandle: InternalInstanceHandle,
ownerDocument: PublicRootInstance,
): ReactFabricHostComponent | ReactNativeElement {
if (PublicInstanceClass == null) {
// We don't use inline requires in react-native, so this forces lazy loading
Expand All @@ -55,6 +65,7 @@ export function createPublicInstance(

export function createPublicTextInstance(
internalInstanceHandle: InternalInstanceHandle,
ownerDocument: PublicRootInstance,
): ReadOnlyText {
if (ReadOnlyTextClass == null) {
ReadOnlyTextClass =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import typeof RCTEventEmitter from '../EventEmitter/RCTEventEmitter';
import typeof CustomEvent from '../Events/CustomEvent';
import typeof {
createPublicInstance,
createPublicRootInstance,
createPublicTextInstance,
getInternalInstanceHandleFromPublicInstance,
getNativeTagFromPublicInstance,
Expand Down Expand Up @@ -94,6 +95,10 @@ module.exports = {
return require('../ReactNative/ReactFabricPublicInstance/ReactNativeAttributePayload')
.diff;
},
get createPublicRootInstance(): createPublicRootInstance {
return require('../ReactNative/ReactFabricPublicInstance/ReactFabricPublicInstance')
.createPublicRootInstance;
},
get createPublicInstance(): createPublicInstance {
return require('../ReactNative/ReactFabricPublicInstance/ReactFabricPublicInstance')
.createPublicInstance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7545,13 +7545,19 @@ exports[`public API should not change unintentionally Libraries/ReactNative/Reac
`;

exports[`public API should not change unintentionally Libraries/ReactNative/ReactFabricPublicInstance/ReactFabricPublicInstance.js 1`] = `
"declare export function createPublicInstance(
"type PublicRootInstance = null;
declare export function createPublicRootInstance(
rootTag: RootTag
): PublicRootInstance;
declare export function createPublicInstance(
tag: number,
viewConfig: ViewConfig,
internalInstanceHandle: InternalInstanceHandle
internalInstanceHandle: InternalInstanceHandle,
ownerDocument: PublicRootInstance
): ReactFabricHostComponent | ReactNativeElement;
declare export function createPublicTextInstance(
internalInstanceHandle: InternalInstanceHandle
internalInstanceHandle: InternalInstanceHandle,
ownerDocument: PublicRootInstance
): ReadOnlyText;
declare export function getNativeTagFromPublicInstance(
publicInstance: ReactFabricHostComponent | ReactNativeElement
Expand Down

0 comments on commit b3e6519

Please sign in to comment.