Skip to content

Commit 8109690

Browse files
Emily Janzerfacebook-github-bot
Emily Janzer
authored andcommitted
Use bridgeless flag instead of specific binding in UIManagerBinding
Summary: This fix is still a little hypothetical. We have a few different JS errors that we're seeing with bridgeless mode that seem to be caused by Fabric trying to access `__fbBatchedBridge` from C++. I think what's happening is: 1. User encounters an unrelated JS error very early in rendering a new surface (possibly while the bundle is still loading?) 2. In release builds, BridgelessReactFragment handles the error by stopping the surface and rendering a retry button (actually, the surface is stopped in a bunch of places in BaseFbReactFragment, which might be why this is popping up now - I recently refactored that class to share more of its logic in bridgeless mode) 3. Fabric stops the surface by first checking to see if the custom binding `RN$stopSurface` exists; if not, it falls back to calling the registered callable module `ReactFabric`. I think #3 is where things are going wrong for bridgeless mode; if you call stopSurface before `RN$stopSurface` is installed (which happens when ReactFabric shim is required) then you'll fall back to the bridge version. My solution here is to instead rely on a flag set in C++ to determine whether we're in bridgeless mode, and then check to see if the stopSurface binding has been installed. If not, we just noop - if the ReactFabric shim hasn't been required, we probably don't actually have a React surface that needs to be stopped. At least, that's my current theory. We'll see if this actually works. Changelog: [Fixed][iOS] Fix an issue calling stopSurface in bridgeless mode before surface is started Reviewed By: mdvacca Differential Revision: D25453696 fbshipit-source-id: bff76675c43989101d0ba5ae0aba60089db230bf
1 parent 11cf9ca commit 8109690

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

ReactCommon/react/renderer/uimanager/UIManagerBinding.cpp

+9-4
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,15 @@ void UIManagerBinding::startSurface(
113113

114114
void UIManagerBinding::stopSurface(jsi::Runtime &runtime, SurfaceId surfaceId)
115115
const {
116-
if (runtime.global().hasProperty(runtime, "RN$stopSurface")) {
117-
auto method =
118-
runtime.global().getPropertyAsFunction(runtime, "RN$stopSurface");
119-
method.call(runtime, {jsi::Value{surfaceId}});
116+
auto global = runtime.global();
117+
if (global.hasProperty(runtime, "RN$Bridgeless")) {
118+
if (!global.hasProperty(runtime, "RN$stopSurface")) {
119+
// ReactFabric module has not been loaded yet; there's no surface to stop.
120+
return;
121+
}
122+
// Bridgeless mode uses a custom JSI binding instead of callable module.
123+
global.getPropertyAsFunction(runtime, "RN$stopSurface")
124+
.call(runtime, {jsi::Value{surfaceId}});
120125
} else {
121126
auto module = getModule(runtime, "ReactFabric");
122127
auto method =

0 commit comments

Comments
 (0)