Skip to content

Commit eee3aa6

Browse files
committed
Clean interface for public instances between React and React Native (#26416)
## Summary We are going to move the definition of public instances from React to React Native to have them together with the native methods in Fabric that they invoke. This will allow us to have a better type safety between them and iterate faster on the implementation of this proposal: react-native-community/discussions-and-proposals#607 The interface between React and React Native would look like this after this change and a following PR (#26418): React → React Native: ```javascript ReactNativePrivateInterface.createPublicInstance // to provide via refs ReactNativePrivateInterface.getNodeFromPublicInstance // for DevTools, commands, etc. ReactNativePrivateInterface.getNativeTagFromPublicInstance // to implement `findNodeHandle` ``` React Native → React (ReactFabric): ```javascript ReactFabric.getNodeFromInternalInstanceHandle // to get most recent node to call into native ReactFabric.getPublicInstanceFromInternalInstanceHandle // to get public instances from results from native ``` ## How did you test this change? Flow Existing unit tests DiffTrain build for commit 3554c88.
1 parent df61ea1 commit eee3aa6

File tree

13 files changed

+180
-163
lines changed

13 files changed

+180
-163
lines changed

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react-test-renderer/cjs/ReactTestRenderer-dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23499,7 +23499,7 @@ function createFiberRoot(
2349923499
return root;
2350023500
}
2350123501

23502-
var ReactVersion = "18.3.0-next-c57b90f50-20230320";
23502+
var ReactVersion = "18.3.0-next-3554c8852-20230320";
2350323503

2350423504
// Might add PROFILE later.
2350523505

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react-test-renderer/cjs/ReactTestRenderer-prod.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8526,7 +8526,7 @@ var devToolsConfig$jscomp$inline_1010 = {
85268526
throw Error("TestRenderer does not support findFiberByHostInstance()");
85278527
},
85288528
bundleType: 0,
8529-
version: "18.3.0-next-c57b90f50-20230320",
8529+
version: "18.3.0-next-3554c8852-20230320",
85308530
rendererPackageName: "react-test-renderer"
85318531
};
85328532
var internals$jscomp$inline_1202 = {
@@ -8557,7 +8557,7 @@ var internals$jscomp$inline_1202 = {
85578557
scheduleRoot: null,
85588558
setRefreshHandler: null,
85598559
getCurrentFiber: null,
8560-
reconcilerVersion: "18.3.0-next-c57b90f50-20230320"
8560+
reconcilerVersion: "18.3.0-next-3554c8852-20230320"
85618561
};
85628562
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
85638563
var hook$jscomp$inline_1203 = __REACT_DEVTOOLS_GLOBAL_HOOK__;

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react-test-renderer/cjs/ReactTestRenderer-profiling.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8953,7 +8953,7 @@ var devToolsConfig$jscomp$inline_1051 = {
89538953
throw Error("TestRenderer does not support findFiberByHostInstance()");
89548954
},
89558955
bundleType: 0,
8956-
version: "18.3.0-next-c57b90f50-20230320",
8956+
version: "18.3.0-next-3554c8852-20230320",
89578957
rendererPackageName: "react-test-renderer"
89588958
};
89598959
var internals$jscomp$inline_1241 = {
@@ -8984,7 +8984,7 @@ var internals$jscomp$inline_1241 = {
89848984
scheduleRoot: null,
89858985
setRefreshHandler: null,
89868986
getCurrentFiber: null,
8987-
reconcilerVersion: "18.3.0-next-c57b90f50-20230320"
8987+
reconcilerVersion: "18.3.0-next-3554c8852-20230320"
89888988
};
89898989
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
89908990
var hook$jscomp$inline_1242 = __REACT_DEVTOOLS_GLOBAL_HOOK__;

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ if (
2727
}
2828
"use strict";
2929

30-
var ReactVersion = "18.3.0-next-c57b90f50-20230320";
30+
var ReactVersion = "18.3.0-next-3554c8852-20230320";
3131

3232
// ATTENTION
3333
// When adding new symbols to this file,

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-prod.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,4 +639,4 @@ exports.useSyncExternalStore = function (
639639
);
640640
};
641641
exports.useTransition = useTransition;
642-
exports.version = "18.3.0-next-c57b90f50-20230320";
642+
exports.version = "18.3.0-next-3554c8852-20230320";

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-profiling.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ exports.useSyncExternalStore = function (
642642
);
643643
};
644644
exports.useTransition = useTransition;
645-
exports.version = "18.3.0-next-c57b90f50-20230320";
645+
exports.version = "18.3.0-next-3554c8852-20230320";
646646

647647
/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
648648
if (

compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-dev.fb.js

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26257,7 +26257,7 @@ function createFiberRoot(
2625726257
return root;
2625826258
}
2625926259

26260-
var ReactVersion = "18.3.0-next-c57b90f50-20230320";
26260+
var ReactVersion = "18.3.0-next-3554c8852-20230320";
2626126261

2626226262
function createPortal$1(
2626326263
children,
@@ -26792,11 +26792,18 @@ function injectIntoDevTools(devToolsConfig) {
2679226792
* `nativeFabricUIManager` to be defined in the global scope (which does not
2679326793
* happen in Paper).
2679426794
*/
26795+
2679526796
function getNativeTagFromPublicInstance(publicInstance) {
2679626797
return publicInstance.__nativeTag;
2679726798
}
26798-
function getInternalInstanceHandleFromPublicInstance(publicInstance) {
26799-
return publicInstance.__internalInstanceHandle;
26799+
function getNodeFromPublicInstance(publicInstance) {
26800+
if (publicInstance.__internalInstanceHandle == null) {
26801+
return null;
26802+
}
26803+
26804+
return getNodeFromInternalInstanceHandle(
26805+
publicInstance.__internalInstanceHandle
26806+
);
2680026807
}
2680126808

2680226809
var ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
@@ -26933,15 +26940,10 @@ function dispatchCommand(handle, command, args) {
2693326940
return;
2693426941
}
2693526942

26936-
var internalInstanceHandle =
26937-
getInternalInstanceHandleFromPublicInstance(handle);
26938-
26939-
if (internalInstanceHandle != null) {
26940-
var node = getNodeFromInternalInstanceHandle(internalInstanceHandle);
26943+
var node = getNodeFromPublicInstance(handle);
2694126944

26942-
if (node != null) {
26943-
nativeFabricUIManager.dispatchCommand(node, command, args);
26944-
}
26945+
if (node != null) {
26946+
nativeFabricUIManager.dispatchCommand(node, command, args);
2694526947
} else {
2694626948
ReactNativePrivateInterface.UIManager.dispatchViewManagerCommand(
2694726949
nativeTag,
@@ -26967,15 +26969,10 @@ function sendAccessibilityEvent(handle, eventType) {
2696726969
return;
2696826970
}
2696926971

26970-
var internalInstanceHandle =
26971-
getInternalInstanceHandleFromPublicInstance(handle);
26972-
26973-
if (internalInstanceHandle != null) {
26974-
var node = getNodeFromInternalInstanceHandle(internalInstanceHandle);
26972+
var node = getNodeFromPublicInstance(handle);
2697526973

26976-
if (node != null) {
26977-
nativeFabricUIManager.sendAccessibilityEvent(node, eventType);
26978-
}
26974+
if (node != null) {
26975+
nativeFabricUIManager.sendAccessibilityEvent(node, eventType);
2697926976
} else {
2698026977
ReactNativePrivateInterface.legacySendAccessibilityEvent(
2698126978
nativeTag,
@@ -27466,6 +27463,10 @@ function getPublicInstance(instance) {
2746627463

2746727464
return null;
2746827465
}
27466+
function getPublicInstanceFromInternalInstanceHandle(internalInstanceHandle) {
27467+
var instance = internalInstanceHandle.stateNode;
27468+
return getPublicInstance(instance);
27469+
}
2746927470
function prepareUpdate(instance, type, oldProps, newProps, hostContext) {
2747027471
var viewConfig = instance.canonical.viewConfig;
2747127472
var updatePayload = diff(oldProps, newProps, viewConfig.validAttributes); // TODO: If the event handlers have changed, we need to update the current props
@@ -27803,12 +27804,7 @@ function getInspectorDataForViewAtPoint(
2780327804
) {
2780427805
{
2780527806
var closestInstance = null;
27806-
var fabricInstanceHandle =
27807-
getInternalInstanceHandleFromPublicInstance(inspectedView);
27808-
var fabricNode =
27809-
fabricInstanceHandle != null
27810-
? getNodeFromInternalInstanceHandle(fabricInstanceHandle)
27811-
: null;
27807+
var fabricNode = getNodeFromPublicInstance(inspectedView);
2781227808

2781327809
if (fabricNode) {
2781427810
// For Fabric we can look up the instance handle directly and measure it.
@@ -27971,6 +27967,8 @@ exports.findHostInstance_DEPRECATED = findHostInstance_DEPRECATED;
2797127967
exports.findNodeHandle = findNodeHandle;
2797227968
exports.getInspectorDataForInstance = getInspectorDataForInstance;
2797327969
exports.getNodeFromInternalInstanceHandle = getNodeFromInternalInstanceHandle;
27970+
exports.getPublicInstanceFromInternalInstanceHandle =
27971+
getPublicInstanceFromInternalInstanceHandle;
2797427972
exports.render = render;
2797527973
exports.sendAccessibilityEvent = sendAccessibilityEvent;
2797627974
exports.stopSurface = stopSurface;

compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-prod.fb.js

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9461,7 +9461,7 @@ var roots = new Map(),
94619461
devToolsConfig$jscomp$inline_1030 = {
94629462
findFiberByHostInstance: getInstanceFromNode,
94639463
bundleType: 0,
9464-
version: "18.3.0-next-c57b90f50-20230320",
9464+
version: "18.3.0-next-3554c8852-20230320",
94659465
rendererPackageName: "react-native-renderer",
94669466
rendererConfig: {
94679467
getInspectorDataForViewTag: function () {
@@ -9503,7 +9503,7 @@ var internals$jscomp$inline_1277 = {
95039503
scheduleRoot: null,
95049504
setRefreshHandler: null,
95059505
getCurrentFiber: null,
9506-
reconcilerVersion: "18.3.0-next-c57b90f50-20230320"
9506+
reconcilerVersion: "18.3.0-next-3554c8852-20230320"
95079507
};
95089508
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
95099509
var hook$jscomp$inline_1278 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
@@ -9530,11 +9530,12 @@ exports.dispatchCommand = function (handle, command, args) {
95309530
var nativeTag =
95319531
null != handle._nativeTag ? handle._nativeTag : handle.__nativeTag;
95329532
null != nativeTag &&
9533-
((handle = handle.__internalInstanceHandle),
9533+
((handle =
9534+
null == handle.__internalInstanceHandle
9535+
? null
9536+
: getNodeFromInternalInstanceHandle(handle.__internalInstanceHandle)),
95349537
null != handle
9535-
? ((nativeTag = getNodeFromInternalInstanceHandle(handle)),
9536-
null != nativeTag &&
9537-
nativeFabricUIManager.dispatchCommand(nativeTag, command, args))
9538+
? nativeFabricUIManager.dispatchCommand(handle, command, args)
95389539
: ReactNativePrivateInterface.UIManager.dispatchViewManagerCommand(
95399540
nativeTag,
95409541
command,
@@ -9585,6 +9586,11 @@ exports.getInspectorDataForInstance = function (closestInstance) {
95859586
};
95869587
};
95879588
exports.getNodeFromInternalInstanceHandle = getNodeFromInternalInstanceHandle;
9589+
exports.getPublicInstanceFromInternalInstanceHandle = function (
9590+
internalInstanceHandle
9591+
) {
9592+
return getPublicInstance(internalInstanceHandle.stateNode);
9593+
};
95889594
exports.render = function (element, containerTag, callback, concurrentRoot) {
95899595
var root = roots.get(containerTag);
95909596
root ||
@@ -9620,11 +9626,12 @@ exports.sendAccessibilityEvent = function (handle, eventType) {
96209626
var nativeTag =
96219627
null != handle._nativeTag ? handle._nativeTag : handle.__nativeTag;
96229628
null != nativeTag &&
9623-
((handle = handle.__internalInstanceHandle),
9629+
((handle =
9630+
null == handle.__internalInstanceHandle
9631+
? null
9632+
: getNodeFromInternalInstanceHandle(handle.__internalInstanceHandle)),
96249633
null != handle
9625-
? ((nativeTag = getNodeFromInternalInstanceHandle(handle)),
9626-
null != nativeTag &&
9627-
nativeFabricUIManager.sendAccessibilityEvent(nativeTag, eventType))
9634+
? nativeFabricUIManager.sendAccessibilityEvent(handle, eventType)
96289635
: ReactNativePrivateInterface.legacySendAccessibilityEvent(
96299636
nativeTag,
96309637
eventType

compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-profiling.fb.js

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10171,7 +10171,7 @@ var roots = new Map(),
1017110171
devToolsConfig$jscomp$inline_1107 = {
1017210172
findFiberByHostInstance: getInstanceFromNode,
1017310173
bundleType: 0,
10174-
version: "18.3.0-next-c57b90f50-20230320",
10174+
version: "18.3.0-next-3554c8852-20230320",
1017510175
rendererPackageName: "react-native-renderer",
1017610176
rendererConfig: {
1017710177
getInspectorDataForViewTag: function () {
@@ -10226,7 +10226,7 @@ var roots = new Map(),
1022610226
scheduleRoot: null,
1022710227
setRefreshHandler: null,
1022810228
getCurrentFiber: null,
10229-
reconcilerVersion: "18.3.0-next-c57b90f50-20230320"
10229+
reconcilerVersion: "18.3.0-next-3554c8852-20230320"
1023010230
});
1023110231
exports.createPortal = function (children, containerTag) {
1023210232
return createPortal$1(
@@ -10240,11 +10240,12 @@ exports.dispatchCommand = function (handle, command, args) {
1024010240
var nativeTag =
1024110241
null != handle._nativeTag ? handle._nativeTag : handle.__nativeTag;
1024210242
null != nativeTag &&
10243-
((handle = handle.__internalInstanceHandle),
10243+
((handle =
10244+
null == handle.__internalInstanceHandle
10245+
? null
10246+
: getNodeFromInternalInstanceHandle(handle.__internalInstanceHandle)),
1024410247
null != handle
10245-
? ((nativeTag = getNodeFromInternalInstanceHandle(handle)),
10246-
null != nativeTag &&
10247-
nativeFabricUIManager.dispatchCommand(nativeTag, command, args))
10248+
? nativeFabricUIManager.dispatchCommand(handle, command, args)
1024810249
: ReactNativePrivateInterface.UIManager.dispatchViewManagerCommand(
1024910250
nativeTag,
1025010251
command,
@@ -10295,6 +10296,11 @@ exports.getInspectorDataForInstance = function (closestInstance) {
1029510296
};
1029610297
};
1029710298
exports.getNodeFromInternalInstanceHandle = getNodeFromInternalInstanceHandle;
10299+
exports.getPublicInstanceFromInternalInstanceHandle = function (
10300+
internalInstanceHandle
10301+
) {
10302+
return getPublicInstance(internalInstanceHandle.stateNode);
10303+
};
1029810304
exports.render = function (element, containerTag, callback, concurrentRoot) {
1029910305
var root = roots.get(containerTag);
1030010306
root ||
@@ -10332,11 +10338,12 @@ exports.sendAccessibilityEvent = function (handle, eventType) {
1033210338
var nativeTag =
1033310339
null != handle._nativeTag ? handle._nativeTag : handle.__nativeTag;
1033410340
null != nativeTag &&
10335-
((handle = handle.__internalInstanceHandle),
10341+
((handle =
10342+
null == handle.__internalInstanceHandle
10343+
? null
10344+
: getNodeFromInternalInstanceHandle(handle.__internalInstanceHandle)),
1033610345
null != handle
10337-
? ((nativeTag = getNodeFromInternalInstanceHandle(handle)),
10338-
null != nativeTag &&
10339-
nativeFabricUIManager.sendAccessibilityEvent(nativeTag, eventType))
10346+
? nativeFabricUIManager.sendAccessibilityEvent(handle, eventType)
1034010347
: ReactNativePrivateInterface.legacySendAccessibilityEvent(
1034110348
nativeTag,
1034210349
eventType

0 commit comments

Comments
 (0)