Skip to content

Commit 2a6d5ac

Browse files
committed
refactor[isChildPublicInstance]: don't leak ReactNativeFiberHostComponent to Fabric implementation (#27923)
While inspecting the build artifacts for Fabric in https://www.internalfb.com/diff/D51816108, I've noticed it has some leaking implementation details from Paper, such as `ReactNativeFiberHostComponent`. The reason for it is the single implementation of `isChildPublicInstance` in `ReactNativePublicCompat`, in which we were using `instanceof ReactNativeFiberHostComponent`. This new implementation removes the `ReactNativeFiberHostComponent` leak, but decreases the Flow coverage. DiffTrain build for commit 6639ed3.
1 parent 772935f commit 2a6d5ac

File tree

9 files changed

+35
-193
lines changed

9 files changed

+35
-193
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
@@ -25524,7 +25524,7 @@ if (__DEV__) {
2552425524
return root;
2552525525
}
2552625526

25527-
var ReactVersion = "18.3.0-canary-49439b4db-20240110";
25527+
var ReactVersion = "18.3.0-canary-6639ed3b3-20240111";
2552825528

2552925529
// Might add PROFILE later.
2553025530

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
@@ -9117,7 +9117,7 @@ var devToolsConfig$jscomp$inline_1037 = {
91179117
throw Error("TestRenderer does not support findFiberByHostInstance()");
91189118
},
91199119
bundleType: 0,
9120-
version: "18.3.0-canary-49439b4db-20240110",
9120+
version: "18.3.0-canary-6639ed3b3-20240111",
91219121
rendererPackageName: "react-test-renderer"
91229122
};
91239123
var internals$jscomp$inline_1230 = {
@@ -9148,7 +9148,7 @@ var internals$jscomp$inline_1230 = {
91489148
scheduleRoot: null,
91499149
setRefreshHandler: null,
91509150
getCurrentFiber: null,
9151-
reconcilerVersion: "18.3.0-canary-49439b4db-20240110"
9151+
reconcilerVersion: "18.3.0-canary-6639ed3b3-20240111"
91529152
};
91539153
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
91549154
var hook$jscomp$inline_1231 = __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
@@ -9545,7 +9545,7 @@ var devToolsConfig$jscomp$inline_1079 = {
95459545
throw Error("TestRenderer does not support findFiberByHostInstance()");
95469546
},
95479547
bundleType: 0,
9548-
version: "18.3.0-canary-49439b4db-20240110",
9548+
version: "18.3.0-canary-6639ed3b3-20240111",
95499549
rendererPackageName: "react-test-renderer"
95509550
};
95519551
var internals$jscomp$inline_1271 = {
@@ -9576,7 +9576,7 @@ var internals$jscomp$inline_1271 = {
95769576
scheduleRoot: null,
95779577
setRefreshHandler: null,
95789578
getCurrentFiber: null,
9579-
reconcilerVersion: "18.3.0-canary-49439b4db-20240110"
9579+
reconcilerVersion: "18.3.0-canary-6639ed3b3-20240111"
95809580
};
95819581
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
95829582
var hook$jscomp$inline_1272 = __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
@@ -24,7 +24,7 @@ if (__DEV__) {
2424
) {
2525
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
2626
}
27-
var ReactVersion = "18.3.0-canary-49439b4db-20240110";
27+
var ReactVersion = "18.3.0-canary-6639ed3b3-20240111";
2828

2929
// ATTENTION
3030
// 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
@@ -580,4 +580,4 @@ exports.useSyncExternalStore = function (
580580
exports.useTransition = function () {
581581
return ReactCurrentDispatcher.current.useTransition();
582582
};
583-
exports.version = "18.3.0-canary-49439b4db-20240110";
583+
exports.version = "18.3.0-canary-6639ed3b3-20240111";

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
@@ -576,7 +576,7 @@ exports.useSyncExternalStore = function (
576576
exports.useTransition = function () {
577577
return ReactCurrentDispatcher.current.useTransition();
578578
};
579-
exports.version = "18.3.0-canary-49439b4db-20240110";
579+
exports.version = "18.3.0-canary-6639ed3b3-20240111";
580580
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
581581
"function" ===
582582
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
49439b4db858b2cfc17a601ae087d392479121da
1+
6639ed3b3a44f7736beb629144a7996145008f09

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

Lines changed: 13 additions & 168 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<8b9384a5c33886e7b65364a52f97f065>>
10+
* @generated SignedSource<<54456b8469c88ba73c0c7167b4b27e53>>
1111
*/
1212

1313
"use strict";
@@ -27822,7 +27822,7 @@ to return true:wantsResponderID| |
2782227822
return root;
2782327823
}
2782427824

27825-
var ReactVersion = "18.3.0-canary-26f7930f";
27825+
var ReactVersion = "18.3.0-canary-2e719699";
2782627826

2782727827
function createPortal$1(
2782827828
children,
@@ -28364,158 +28364,6 @@ to return true:wantsResponderID| |
2836428364
return instanceCache.get(tag) || null;
2836528365
}
2836628366

28367-
/**
28368-
* In the future, we should cleanup callbacks by cancelling them instead of
28369-
* using this.
28370-
*/
28371-
function mountSafeCallback_NOT_REALLY_SAFE(context, callback) {
28372-
return function () {
28373-
if (!callback) {
28374-
return undefined;
28375-
} // This protects against createClass() components.
28376-
// We don't know if there is code depending on it.
28377-
// We intentionally don't use isMounted() because even accessing
28378-
// isMounted property on a React ES6 class will trigger a warning.
28379-
28380-
if (typeof context.__isMounted === "boolean") {
28381-
if (!context.__isMounted) {
28382-
return undefined;
28383-
}
28384-
} // FIXME: there used to be other branches that protected
28385-
// against unmounted host components. But RN host components don't
28386-
// define isMounted() anymore, so those checks didn't do anything.
28387-
// They caused false positive warning noise so we removed them:
28388-
// https://github.com/facebook/react-native/issues/18868#issuecomment-413579095
28389-
// However, this means that the callback is NOT guaranteed to be safe
28390-
// for host components. The solution we should implement is to make
28391-
// UIManager.measure() and similar calls truly cancelable. Then we
28392-
// can change our own code calling them to cancel when something unmounts.
28393-
28394-
return callback.apply(context, arguments);
28395-
};
28396-
}
28397-
function warnForStyleProps(props, validAttributes) {
28398-
{
28399-
for (var key in validAttributes.style) {
28400-
if (!(validAttributes[key] || props[key] === undefined)) {
28401-
error(
28402-
"You are setting the style `{ %s" +
28403-
": ... }` as a prop. You " +
28404-
"should nest it in a style object. " +
28405-
"E.g. `{ style: { %s" +
28406-
": ... } }`",
28407-
key,
28408-
key
28409-
);
28410-
}
28411-
}
28412-
}
28413-
}
28414-
28415-
var ReactNativeFiberHostComponent = /*#__PURE__*/ (function () {
28416-
function ReactNativeFiberHostComponent(
28417-
tag,
28418-
viewConfig,
28419-
internalInstanceHandleDEV
28420-
) {
28421-
this._children = void 0;
28422-
this._nativeTag = void 0;
28423-
this._internalFiberInstanceHandleDEV = void 0;
28424-
this.viewConfig = void 0;
28425-
this._nativeTag = tag;
28426-
this._children = [];
28427-
this.viewConfig = viewConfig;
28428-
28429-
{
28430-
this._internalFiberInstanceHandleDEV = internalInstanceHandleDEV;
28431-
}
28432-
}
28433-
28434-
var _proto = ReactNativeFiberHostComponent.prototype;
28435-
28436-
_proto.blur = function blur() {
28437-
ReactNativePrivateInterface.TextInputState.blurTextInput(this);
28438-
};
28439-
28440-
_proto.focus = function focus() {
28441-
ReactNativePrivateInterface.TextInputState.focusTextInput(this);
28442-
};
28443-
28444-
_proto.measure = function measure(callback) {
28445-
ReactNativePrivateInterface.UIManager.measure(
28446-
this._nativeTag,
28447-
mountSafeCallback_NOT_REALLY_SAFE(this, callback)
28448-
);
28449-
};
28450-
28451-
_proto.measureInWindow = function measureInWindow(callback) {
28452-
ReactNativePrivateInterface.UIManager.measureInWindow(
28453-
this._nativeTag,
28454-
mountSafeCallback_NOT_REALLY_SAFE(this, callback)
28455-
);
28456-
};
28457-
28458-
_proto.measureLayout = function measureLayout(
28459-
relativeToNativeNode,
28460-
onSuccess,
28461-
onFail
28462-
/* currently unused */
28463-
) {
28464-
var relativeNode;
28465-
28466-
if (typeof relativeToNativeNode === "number") {
28467-
// Already a node handle
28468-
relativeNode = relativeToNativeNode;
28469-
} else {
28470-
var nativeNode = relativeToNativeNode;
28471-
28472-
if (nativeNode._nativeTag) {
28473-
relativeNode = nativeNode._nativeTag;
28474-
}
28475-
}
28476-
28477-
if (relativeNode == null) {
28478-
{
28479-
error(
28480-
"Warning: ref.measureLayout must be called with a node handle or a ref to a native component."
28481-
);
28482-
}
28483-
28484-
return;
28485-
}
28486-
28487-
ReactNativePrivateInterface.UIManager.measureLayout(
28488-
this._nativeTag,
28489-
relativeNode,
28490-
mountSafeCallback_NOT_REALLY_SAFE(this, onFail),
28491-
mountSafeCallback_NOT_REALLY_SAFE(this, onSuccess)
28492-
);
28493-
};
28494-
28495-
_proto.setNativeProps = function setNativeProps(nativeProps) {
28496-
{
28497-
warnForStyleProps(nativeProps, this.viewConfig.validAttributes);
28498-
}
28499-
28500-
var updatePayload = create(
28501-
nativeProps,
28502-
this.viewConfig.validAttributes
28503-
); // Avoid the overhead of bridge calls if there's no update.
28504-
// This is an expensive no-op for Android, and causes an unnecessary
28505-
// view invalidation for certain components (eg RCTTextInput) on iOS.
28506-
28507-
if (updatePayload != null) {
28508-
ReactNativePrivateInterface.UIManager.updateView(
28509-
this._nativeTag,
28510-
this.viewConfig.uiViewClassName,
28511-
updatePayload
28512-
);
28513-
}
28514-
};
28515-
28516-
return ReactNativeFiberHostComponent;
28517-
})();
28518-
2851928367
var ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
2852028368
function findHostInstance_DEPRECATED(componentOrHandle) {
2852128369
{
@@ -28712,20 +28560,17 @@ to return true:wantsResponderID| |
2871228560
{
2871328561
// Paper
2871428562
if (
28715-
parentInstance instanceof ReactNativeFiberHostComponent ||
28716-
childInstance instanceof ReactNativeFiberHostComponent
28563+
// $FlowExpectedError[incompatible-type]
28564+
// $FlowExpectedError[prop-missing] Don't check via `instanceof ReactNativeFiberHostComponent`, so it won't be leaked to Fabric.
28565+
parentInstance._internalFiberInstanceHandleDEV && // $FlowExpectedError[incompatible-type]
28566+
// $FlowExpectedError[prop-missing] Don't check via `instanceof ReactNativeFiberHostComponent`, so it won't be leaked to Fabric.
28567+
childInstance._internalFiberInstanceHandleDEV
2871728568
) {
28718-
if (
28719-
parentInstance instanceof ReactNativeFiberHostComponent &&
28720-
childInstance instanceof ReactNativeFiberHostComponent
28721-
) {
28722-
return doesFiberContain(
28723-
parentInstance._internalFiberInstanceHandleDEV,
28724-
childInstance._internalFiberInstanceHandleDEV
28725-
);
28726-
} // Means that one instance is from Fabric and other is from Paper.
28727-
28728-
return false;
28569+
return doesFiberContain(
28570+
// $FlowExpectedError[incompatible-call]
28571+
parentInstance._internalFiberInstanceHandleDEV, // $FlowExpectedError[incompatible-call]
28572+
childInstance._internalFiberInstanceHandleDEV
28573+
);
2872928574
}
2873028575

2873128576
var parentInternalInstanceHandle = // $FlowExpectedError[incompatible-call] Type for parentInstance should have been PublicInstance from ReactFiberConfigFabric.
@@ -28745,7 +28590,7 @@ to return true:wantsResponderID| |
2874528590
parentInternalInstanceHandle,
2874628591
childInternalInstanceHandle
2874728592
);
28748-
}
28593+
} // Means that one instance is from Fabric and other is from Paper.
2874928594

2875028595
return false;
2875128596
}

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

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<b760e9c760f299f1b32bf6b355fb1f38>>
10+
* @generated SignedSource<<fa0c9f533686c45b2c4dad69e529be7e>>
1111
*/
1212

1313
"use strict";
@@ -28263,7 +28263,7 @@ to return true:wantsResponderID| |
2826328263
return root;
2826428264
}
2826528265

28266-
var ReactVersion = "18.3.0-canary-2073ee9d";
28266+
var ReactVersion = "18.3.0-canary-c6b3241d";
2826728267

2826828268
function createPortal$1(
2826928269
children,
@@ -28995,20 +28995,17 @@ to return true:wantsResponderID| |
2899528995
{
2899628996
// Paper
2899728997
if (
28998-
parentInstance instanceof ReactNativeFiberHostComponent ||
28999-
childInstance instanceof ReactNativeFiberHostComponent
28998+
// $FlowExpectedError[incompatible-type]
28999+
// $FlowExpectedError[prop-missing] Don't check via `instanceof ReactNativeFiberHostComponent`, so it won't be leaked to Fabric.
29000+
parentInstance._internalFiberInstanceHandleDEV && // $FlowExpectedError[incompatible-type]
29001+
// $FlowExpectedError[prop-missing] Don't check via `instanceof ReactNativeFiberHostComponent`, so it won't be leaked to Fabric.
29002+
childInstance._internalFiberInstanceHandleDEV
2900029003
) {
29001-
if (
29002-
parentInstance instanceof ReactNativeFiberHostComponent &&
29003-
childInstance instanceof ReactNativeFiberHostComponent
29004-
) {
29005-
return doesFiberContain(
29006-
parentInstance._internalFiberInstanceHandleDEV,
29007-
childInstance._internalFiberInstanceHandleDEV
29008-
);
29009-
} // Means that one instance is from Fabric and other is from Paper.
29010-
29011-
return false;
29004+
return doesFiberContain(
29005+
// $FlowExpectedError[incompatible-call]
29006+
parentInstance._internalFiberInstanceHandleDEV, // $FlowExpectedError[incompatible-call]
29007+
childInstance._internalFiberInstanceHandleDEV
29008+
);
2901229009
}
2901329010

2901429011
var parentInternalInstanceHandle = // $FlowExpectedError[incompatible-call] Type for parentInstance should have been PublicInstance from ReactFiberConfigFabric.
@@ -29028,7 +29025,7 @@ to return true:wantsResponderID| |
2902829025
parentInternalInstanceHandle,
2902929026
childInternalInstanceHandle
2903029027
);
29031-
}
29028+
} // Means that one instance is from Fabric and other is from Paper.
2903229029

2903329030
return false;
2903429031
}

0 commit comments

Comments
 (0)