fix: remove bridge! force-unwrap that crashes on RN 0.84+ bridgeless mode#4200
Merged
fix: remove bridge! force-unwrap that crashes on RN 0.84+ bridgeless mode#4200
Conversation
64041ea to
eca1b3b
Compare
In RN 0.84+ with RCT_REMOVE_LEGACY_ARCH, [RCTBridge currentBridge] returns nil but TurboModules receive an RCTBridgeProxy via their bridge property. Add RNMBXBridgeManager that captures the bridge proxy from TurboModules and provides a currentBridge method that falls back to it. All ComponentViews now use [RNMBXBridgeManager currentBridge] instead of [RCTBridge currentBridge].
eca1b3b to
2cff528
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4195
On React Native 0.84+ with Fabric/bridgeless mode,
[RCTBridge currentBridge]returnsnilbecauseRCT_REMOVE_LEGACY_ARCHstubs it out. This causes crashes in two ways:bridge!force-unwraps in auto-generatedRNMBXStyle.swiftcrash withEXC_BREAKPOINTRCTImageLoaderfails since it's accessed through the bridgeRoot cause
TurboModules still receive a working
RCTBridgeProxyvia theirbridgeproperty (set byRCTTurboModuleManager), but ComponentViews used[RCTBridge currentBridge]which is nil.Changes
Commit 1: Remove force-unwraps
RNMBXStyle.swift.ejstemplate:bridge!→bridgeRNMBXStyleValue.swift:setImageacceptsRCTBridge?, guards the fetch callRNMBXImages.swift: guardsfetchImageswithif let bridgeRNMBXImageQueue.swift: guardsbridge!.module(...)with early returnCommit 2: Bridge proxy resolution
RNMBXBridgeManagercaptures the bridge proxy fromRNMBXImageModule(a TurboModule)RNMBXBridgeManager.currentBridgereturns[RCTBridge currentBridge] ?: capturedProxy[RNMBXBridgeManager currentBridge]Test plan
Fatal errorat RNMBXImages.swift:133