Skip to content

Commit 08375e6

Browse files
committed
Implement public instances for text nodes in Fabric (#26516)
## Summary This adds the ability to create public instances for text nodes in Fabric. The implementation for the public instances lives in React Native (as it does for host components after #26437). The logic here just handles their lazy instantiation when requested via `getPublicInstanceFromInternalInstanceHandle`, which is called by Fabric with information coming from the shadow tree. It's important that the creation of public instances for text nodes is done lazily to avoid regressing memory usage when unused. Instances for text nodes are left intact if the public instance is never accessed. This is necessary to implement access to text nodes in React Native as explained in react-native-community/discussions-and-proposals#607 ## How did you test this change? Added unit tests (also fixed a test that was only testing the logic in a mock :S). DiffTrain build for commit 0700dd5.
1 parent 6b19def commit 08375e6

14 files changed

+109
-73
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -23882,7 +23882,7 @@ function createFiberRoot(
2388223882
return root;
2388323883
}
2388423884

23885-
var ReactVersion = "18.3.0-next-4a1cc2ddd-20230403";
23885+
var ReactVersion = "18.3.0-next-0700dd50b-20230404";
2388623886

2388723887
// Might add PROFILE later.
2388823888

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -8683,7 +8683,7 @@ var devToolsConfig$jscomp$inline_1028 = {
86838683
throw Error("TestRenderer does not support findFiberByHostInstance()");
86848684
},
86858685
bundleType: 0,
8686-
version: "18.3.0-next-4a1cc2ddd-20230403",
8686+
version: "18.3.0-next-0700dd50b-20230404",
86878687
rendererPackageName: "react-test-renderer"
86888688
};
86898689
var internals$jscomp$inline_1220 = {
@@ -8714,7 +8714,7 @@ var internals$jscomp$inline_1220 = {
87148714
scheduleRoot: null,
87158715
setRefreshHandler: null,
87168716
getCurrentFiber: null,
8717-
reconcilerVersion: "18.3.0-next-4a1cc2ddd-20230403"
8717+
reconcilerVersion: "18.3.0-next-0700dd50b-20230404"
87188718
};
87198719
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
87208720
var hook$jscomp$inline_1221 = __REACT_DEVTOOLS_GLOBAL_HOOK__;

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -9108,7 +9108,7 @@ var devToolsConfig$jscomp$inline_1070 = {
91089108
throw Error("TestRenderer does not support findFiberByHostInstance()");
91099109
},
91109110
bundleType: 0,
9111-
version: "18.3.0-next-4a1cc2ddd-20230403",
9111+
version: "18.3.0-next-0700dd50b-20230404",
91129112
rendererPackageName: "react-test-renderer"
91139113
};
91149114
var internals$jscomp$inline_1261 = {
@@ -9139,7 +9139,7 @@ var internals$jscomp$inline_1261 = {
91399139
scheduleRoot: null,
91409140
setRefreshHandler: null,
91419141
getCurrentFiber: null,
9142-
reconcilerVersion: "18.3.0-next-4a1cc2ddd-20230403"
9142+
reconcilerVersion: "18.3.0-next-0700dd50b-20230404"
91439143
};
91449144
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
91459145
var hook$jscomp$inline_1262 = __REACT_DEVTOOLS_GLOBAL_HOOK__;

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

+1-1
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-4a1cc2ddd-20230403";
30+
var ReactVersion = "18.3.0-next-0700dd50b-20230404";
3131

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

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

+1-1
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-4a1cc2ddd-20230403";
642+
exports.version = "18.3.0-next-0700dd50b-20230404";

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

+1-1
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-4a1cc2ddd-20230403";
645+
exports.version = "18.3.0-next-0700dd50b-20230404";
646646

647647
/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
648648
if (
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4a1cc2ddd035f5c269e82ab6f7686e2e60d3b3ea
1+
0700dd50bda98f5ee86f2e3adfe5e9906ed1e8e3

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

+18-1
Original file line numberDiff line numberDiff line change
@@ -4985,7 +4985,24 @@ function getPublicInstance(instance) {
49854985

49864986
return null;
49874987
}
4988+
4989+
function getPublicTextInstance(textInstance, internalInstanceHandle) {
4990+
if (textInstance.publicInstance == null) {
4991+
textInstance.publicInstance =
4992+
ReactNativePrivateInterface.createPublicTextInstance(
4993+
internalInstanceHandle
4994+
);
4995+
}
4996+
4997+
return textInstance.publicInstance;
4998+
}
4999+
49885000
function getPublicInstanceFromInternalInstanceHandle(internalInstanceHandle) {
5001+
if (internalInstanceHandle.tag === HostText) {
5002+
var textInstance = internalInstanceHandle.stateNode;
5003+
return getPublicTextInstance(textInstance, internalInstanceHandle);
5004+
}
5005+
49895006
var instance = internalInstanceHandle.stateNode;
49905007
return getPublicInstance(instance);
49915008
}
@@ -27158,7 +27175,7 @@ function createFiberRoot(
2715827175
return root;
2715927176
}
2716027177

27161-
var ReactVersion = "18.3.0-next-4a1cc2ddd-20230403";
27178+
var ReactVersion = "18.3.0-next-0700dd50b-20230404";
2716227179

2716327180
function createPortal$1(
2716427181
children,

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

+41-32
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ eventPluginOrder = Array.prototype.slice.call([
940940
"ReactNativeBridgeEventPlugin"
941941
]);
942942
recomputePluginOrdering();
943-
var injectedNamesToPlugins$jscomp$inline_243 = {
943+
var injectedNamesToPlugins$jscomp$inline_244 = {
944944
ResponderEventPlugin: ResponderEventPlugin,
945945
ReactNativeBridgeEventPlugin: {
946946
eventTypes: {},
@@ -986,32 +986,32 @@ var injectedNamesToPlugins$jscomp$inline_243 = {
986986
}
987987
}
988988
},
989-
isOrderingDirty$jscomp$inline_244 = !1,
990-
pluginName$jscomp$inline_245;
991-
for (pluginName$jscomp$inline_245 in injectedNamesToPlugins$jscomp$inline_243)
989+
isOrderingDirty$jscomp$inline_245 = !1,
990+
pluginName$jscomp$inline_246;
991+
for (pluginName$jscomp$inline_246 in injectedNamesToPlugins$jscomp$inline_244)
992992
if (
993-
injectedNamesToPlugins$jscomp$inline_243.hasOwnProperty(
994-
pluginName$jscomp$inline_245
993+
injectedNamesToPlugins$jscomp$inline_244.hasOwnProperty(
994+
pluginName$jscomp$inline_246
995995
)
996996
) {
997-
var pluginModule$jscomp$inline_246 =
998-
injectedNamesToPlugins$jscomp$inline_243[pluginName$jscomp$inline_245];
997+
var pluginModule$jscomp$inline_247 =
998+
injectedNamesToPlugins$jscomp$inline_244[pluginName$jscomp$inline_246];
999999
if (
1000-
!namesToPlugins.hasOwnProperty(pluginName$jscomp$inline_245) ||
1001-
namesToPlugins[pluginName$jscomp$inline_245] !==
1002-
pluginModule$jscomp$inline_246
1000+
!namesToPlugins.hasOwnProperty(pluginName$jscomp$inline_246) ||
1001+
namesToPlugins[pluginName$jscomp$inline_246] !==
1002+
pluginModule$jscomp$inline_247
10031003
) {
1004-
if (namesToPlugins[pluginName$jscomp$inline_245])
1004+
if (namesToPlugins[pluginName$jscomp$inline_246])
10051005
throw Error(
10061006
"EventPluginRegistry: Cannot inject two different event plugins using the same name, `" +
1007-
(pluginName$jscomp$inline_245 + "`.")
1007+
(pluginName$jscomp$inline_246 + "`.")
10081008
);
1009-
namesToPlugins[pluginName$jscomp$inline_245] =
1010-
pluginModule$jscomp$inline_246;
1011-
isOrderingDirty$jscomp$inline_244 = !0;
1009+
namesToPlugins[pluginName$jscomp$inline_246] =
1010+
pluginModule$jscomp$inline_247;
1011+
isOrderingDirty$jscomp$inline_245 = !0;
10121012
}
10131013
}
1014-
isOrderingDirty$jscomp$inline_244 && recomputePluginOrdering();
1014+
isOrderingDirty$jscomp$inline_245 && recomputePluginOrdering();
10151015
var emptyObject$1 = {},
10161016
removedKeys = null,
10171017
removedKeyCount = 0,
@@ -9551,10 +9551,10 @@ batchedUpdatesImpl = function (fn, a) {
95519551
}
95529552
};
95539553
var roots = new Map(),
9554-
devToolsConfig$jscomp$inline_1048 = {
9554+
devToolsConfig$jscomp$inline_1052 = {
95559555
findFiberByHostInstance: getInstanceFromNode,
95569556
bundleType: 0,
9557-
version: "18.3.0-next-4a1cc2ddd-20230403",
9557+
version: "18.3.0-next-0700dd50b-20230404",
95589558
rendererPackageName: "react-native-renderer",
95599559
rendererConfig: {
95609560
getInspectorDataForViewTag: function () {
@@ -9569,11 +9569,11 @@ var roots = new Map(),
95699569
}.bind(null, findNodeHandle)
95709570
}
95719571
};
9572-
var internals$jscomp$inline_1293 = {
9573-
bundleType: devToolsConfig$jscomp$inline_1048.bundleType,
9574-
version: devToolsConfig$jscomp$inline_1048.version,
9575-
rendererPackageName: devToolsConfig$jscomp$inline_1048.rendererPackageName,
9576-
rendererConfig: devToolsConfig$jscomp$inline_1048.rendererConfig,
9572+
var internals$jscomp$inline_1297 = {
9573+
bundleType: devToolsConfig$jscomp$inline_1052.bundleType,
9574+
version: devToolsConfig$jscomp$inline_1052.version,
9575+
rendererPackageName: devToolsConfig$jscomp$inline_1052.rendererPackageName,
9576+
rendererConfig: devToolsConfig$jscomp$inline_1052.rendererConfig,
95779577
overrideHookState: null,
95789578
overrideHookStateDeletePath: null,
95799579
overrideHookStateRenamePath: null,
@@ -9589,26 +9589,26 @@ var internals$jscomp$inline_1293 = {
95899589
return null === fiber ? null : fiber.stateNode;
95909590
},
95919591
findFiberByHostInstance:
9592-
devToolsConfig$jscomp$inline_1048.findFiberByHostInstance ||
9592+
devToolsConfig$jscomp$inline_1052.findFiberByHostInstance ||
95939593
emptyFindFiberByHostInstance,
95949594
findHostInstancesForRefresh: null,
95959595
scheduleRefresh: null,
95969596
scheduleRoot: null,
95979597
setRefreshHandler: null,
95989598
getCurrentFiber: null,
9599-
reconcilerVersion: "18.3.0-next-4a1cc2ddd-20230403"
9599+
reconcilerVersion: "18.3.0-next-0700dd50b-20230404"
96009600
};
96019601
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
9602-
var hook$jscomp$inline_1294 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
9602+
var hook$jscomp$inline_1298 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
96039603
if (
9604-
!hook$jscomp$inline_1294.isDisabled &&
9605-
hook$jscomp$inline_1294.supportsFiber
9604+
!hook$jscomp$inline_1298.isDisabled &&
9605+
hook$jscomp$inline_1298.supportsFiber
96069606
)
96079607
try {
9608-
(rendererID = hook$jscomp$inline_1294.inject(
9609-
internals$jscomp$inline_1293
9608+
(rendererID = hook$jscomp$inline_1298.inject(
9609+
internals$jscomp$inline_1297
96109610
)),
9611-
(injectedHook = hook$jscomp$inline_1294);
9611+
(injectedHook = hook$jscomp$inline_1298);
96129612
} catch (err) {}
96139613
}
96149614
exports.createPortal = function (children, containerTag) {
@@ -9687,6 +9687,15 @@ exports.getNodeFromInternalInstanceHandle = function (internalInstanceHandle) {
96879687
exports.getPublicInstanceFromInternalInstanceHandle = function (
96889688
internalInstanceHandle
96899689
) {
9690+
if (6 === internalInstanceHandle.tag) {
9691+
var textInstance = internalInstanceHandle.stateNode;
9692+
null == textInstance.publicInstance &&
9693+
(textInstance.publicInstance =
9694+
ReactNativePrivateInterface.createPublicTextInstance(
9695+
internalInstanceHandle
9696+
));
9697+
return textInstance.publicInstance;
9698+
}
96909699
return getPublicInstance(internalInstanceHandle.stateNode);
96919700
};
96929701
exports.render = function (element, containerTag, callback, concurrentRoot) {

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

+34-25
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@ eventPluginOrder = Array.prototype.slice.call([
951951
"ReactNativeBridgeEventPlugin"
952952
]);
953953
recomputePluginOrdering();
954-
var injectedNamesToPlugins$jscomp$inline_259 = {
954+
var injectedNamesToPlugins$jscomp$inline_260 = {
955955
ResponderEventPlugin: ResponderEventPlugin,
956956
ReactNativeBridgeEventPlugin: {
957957
eventTypes: {},
@@ -997,32 +997,32 @@ var injectedNamesToPlugins$jscomp$inline_259 = {
997997
}
998998
}
999999
},
1000-
isOrderingDirty$jscomp$inline_260 = !1,
1001-
pluginName$jscomp$inline_261;
1002-
for (pluginName$jscomp$inline_261 in injectedNamesToPlugins$jscomp$inline_259)
1000+
isOrderingDirty$jscomp$inline_261 = !1,
1001+
pluginName$jscomp$inline_262;
1002+
for (pluginName$jscomp$inline_262 in injectedNamesToPlugins$jscomp$inline_260)
10031003
if (
1004-
injectedNamesToPlugins$jscomp$inline_259.hasOwnProperty(
1005-
pluginName$jscomp$inline_261
1004+
injectedNamesToPlugins$jscomp$inline_260.hasOwnProperty(
1005+
pluginName$jscomp$inline_262
10061006
)
10071007
) {
1008-
var pluginModule$jscomp$inline_262 =
1009-
injectedNamesToPlugins$jscomp$inline_259[pluginName$jscomp$inline_261];
1008+
var pluginModule$jscomp$inline_263 =
1009+
injectedNamesToPlugins$jscomp$inline_260[pluginName$jscomp$inline_262];
10101010
if (
1011-
!namesToPlugins.hasOwnProperty(pluginName$jscomp$inline_261) ||
1012-
namesToPlugins[pluginName$jscomp$inline_261] !==
1013-
pluginModule$jscomp$inline_262
1011+
!namesToPlugins.hasOwnProperty(pluginName$jscomp$inline_262) ||
1012+
namesToPlugins[pluginName$jscomp$inline_262] !==
1013+
pluginModule$jscomp$inline_263
10141014
) {
1015-
if (namesToPlugins[pluginName$jscomp$inline_261])
1015+
if (namesToPlugins[pluginName$jscomp$inline_262])
10161016
throw Error(
10171017
"EventPluginRegistry: Cannot inject two different event plugins using the same name, `" +
1018-
(pluginName$jscomp$inline_261 + "`.")
1018+
(pluginName$jscomp$inline_262 + "`.")
10191019
);
1020-
namesToPlugins[pluginName$jscomp$inline_261] =
1021-
pluginModule$jscomp$inline_262;
1022-
isOrderingDirty$jscomp$inline_260 = !0;
1020+
namesToPlugins[pluginName$jscomp$inline_262] =
1021+
pluginModule$jscomp$inline_263;
1022+
isOrderingDirty$jscomp$inline_261 = !0;
10231023
}
10241024
}
1025-
isOrderingDirty$jscomp$inline_260 && recomputePluginOrdering();
1025+
isOrderingDirty$jscomp$inline_261 && recomputePluginOrdering();
10261026
var emptyObject$1 = {},
10271027
removedKeys = null,
10281028
removedKeyCount = 0,
@@ -10259,10 +10259,10 @@ batchedUpdatesImpl = function (fn, a) {
1025910259
}
1026010260
};
1026110261
var roots = new Map(),
10262-
devToolsConfig$jscomp$inline_1126 = {
10262+
devToolsConfig$jscomp$inline_1130 = {
1026310263
findFiberByHostInstance: getInstanceFromNode,
1026410264
bundleType: 0,
10265-
version: "18.3.0-next-4a1cc2ddd-20230403",
10265+
version: "18.3.0-next-0700dd50b-20230404",
1026610266
rendererPackageName: "react-native-renderer",
1026710267
rendererConfig: {
1026810268
getInspectorDataForViewTag: function () {
@@ -10291,10 +10291,10 @@ var roots = new Map(),
1029110291
} catch (err) {}
1029210292
return hook.checkDCE ? !0 : !1;
1029310293
})({
10294-
bundleType: devToolsConfig$jscomp$inline_1126.bundleType,
10295-
version: devToolsConfig$jscomp$inline_1126.version,
10296-
rendererPackageName: devToolsConfig$jscomp$inline_1126.rendererPackageName,
10297-
rendererConfig: devToolsConfig$jscomp$inline_1126.rendererConfig,
10294+
bundleType: devToolsConfig$jscomp$inline_1130.bundleType,
10295+
version: devToolsConfig$jscomp$inline_1130.version,
10296+
rendererPackageName: devToolsConfig$jscomp$inline_1130.rendererPackageName,
10297+
rendererConfig: devToolsConfig$jscomp$inline_1130.rendererConfig,
1029810298
overrideHookState: null,
1029910299
overrideHookStateDeletePath: null,
1030010300
overrideHookStateRenamePath: null,
@@ -10310,14 +10310,14 @@ var roots = new Map(),
1031010310
return null === fiber ? null : fiber.stateNode;
1031110311
},
1031210312
findFiberByHostInstance:
10313-
devToolsConfig$jscomp$inline_1126.findFiberByHostInstance ||
10313+
devToolsConfig$jscomp$inline_1130.findFiberByHostInstance ||
1031410314
emptyFindFiberByHostInstance,
1031510315
findHostInstancesForRefresh: null,
1031610316
scheduleRefresh: null,
1031710317
scheduleRoot: null,
1031810318
setRefreshHandler: null,
1031910319
getCurrentFiber: null,
10320-
reconcilerVersion: "18.3.0-next-4a1cc2ddd-20230403"
10320+
reconcilerVersion: "18.3.0-next-0700dd50b-20230404"
1032110321
});
1032210322
exports.createPortal = function (children, containerTag) {
1032310323
return createPortal$1(
@@ -10395,6 +10395,15 @@ exports.getNodeFromInternalInstanceHandle = function (internalInstanceHandle) {
1039510395
exports.getPublicInstanceFromInternalInstanceHandle = function (
1039610396
internalInstanceHandle
1039710397
) {
10398+
if (6 === internalInstanceHandle.tag) {
10399+
var textInstance = internalInstanceHandle.stateNode;
10400+
null == textInstance.publicInstance &&
10401+
(textInstance.publicInstance =
10402+
ReactNativePrivateInterface.createPublicTextInstance(
10403+
internalInstanceHandle
10404+
));
10405+
return textInstance.publicInstance;
10406+
}
1039810407
return getPublicInstance(internalInstanceHandle.stateNode);
1039910408
};
1040010409
exports.render = function (element, containerTag, callback, concurrentRoot) {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -27698,7 +27698,7 @@ function createFiberRoot(
2769827698
return root;
2769927699
}
2770027700

27701-
var ReactVersion = "18.3.0-next-4a1cc2ddd-20230403";
27701+
var ReactVersion = "18.3.0-next-0700dd50b-20230404";
2770227702

2770327703
function createPortal$1(
2770427704
children,

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -9810,7 +9810,7 @@ var roots = new Map(),
98109810
devToolsConfig$jscomp$inline_1107 = {
98119811
findFiberByHostInstance: getInstanceFromTag,
98129812
bundleType: 0,
9813-
version: "18.3.0-next-4a1cc2ddd-20230403",
9813+
version: "18.3.0-next-0700dd50b-20230404",
98149814
rendererPackageName: "react-native-renderer",
98159815
rendererConfig: {
98169816
getInspectorDataForViewTag: function () {
@@ -9852,7 +9852,7 @@ var internals$jscomp$inline_1359 = {
98529852
scheduleRoot: null,
98539853
setRefreshHandler: null,
98549854
getCurrentFiber: null,
9855-
reconcilerVersion: "18.3.0-next-4a1cc2ddd-20230403"
9855+
reconcilerVersion: "18.3.0-next-0700dd50b-20230404"
98569856
};
98579857
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
98589858
var hook$jscomp$inline_1360 = __REACT_DEVTOOLS_GLOBAL_HOOK__;

0 commit comments

Comments
 (0)