Skip to content

fix: remove bridge! force-unwrap that crashes on RN 0.84+ bridgeless mode#4200

Merged
mfazekas merged 2 commits intomainfrom
fix/bridge-force-unwrap-crash-bridgeless
May 11, 2026
Merged

fix: remove bridge! force-unwrap that crashes on RN 0.84+ bridgeless mode#4200
mfazekas merged 2 commits intomainfrom
fix/bridge-force-unwrap-crash-bridgeless

Conversation

@mfazekas
Copy link
Copy Markdown
Contributor

@mfazekas mfazekas commented May 10, 2026

Fixes #4195

On React Native 0.84+ with Fabric/bridgeless mode, [RCTBridge currentBridge] returns nil because RCT_REMOVE_LEGACY_ARCH stubs it out. This causes crashes in two ways:

  1. bridge! force-unwraps in auto-generated RNMBXStyle.swift crash with EXC_BREAKPOINT
  2. Image loading via RCTImageLoader fails since it's accessed through the bridge

Root cause

TurboModules still receive a working RCTBridgeProxy via their bridge property (set by RCTTurboModuleManager), but ComponentViews used [RCTBridge currentBridge] which is nil.

Changes

Commit 1: Remove force-unwraps

  • RNMBXStyle.swift.ejs template: bridge!bridge
  • RNMBXStyleValue.swift: setImage accepts RCTBridge?, guards the fetch call
  • RNMBXImages.swift: guards fetchImages with if let bridge
  • RNMBXImageQueue.swift: guards bridge!.module(...) with early return

Commit 2: Bridge proxy resolution

  • New RNMBXBridgeManager captures the bridge proxy from RNMBXImageModule (a TurboModule)
  • RNMBXBridgeManager.currentBridge returns [RCTBridge currentBridge] ?: capturedProxy
  • All 18 ComponentViews now use [RNMBXBridgeManager currentBridge]

Test plan

  • Reproduced crash on RN 0.84 bridgeless: Fatal error at RNMBXImages.swift:133
  • After fix: no crash, images load correctly via bridge proxy
  • iOS build succeeds, unit tests pass (110/110)

mfazekas added 2 commits May 11, 2026 09:19
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].
@mfazekas mfazekas force-pushed the fix/bridge-force-unwrap-crash-bridgeless branch from eca1b3b to 2cff528 Compare May 11, 2026 07:20
@mfazekas mfazekas merged commit 7c8894b into main May 11, 2026
7 checks passed
@mfazekas mfazekas deleted the fix/bridge-force-unwrap-crash-bridgeless branch May 11, 2026 08:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Crash (EXC_BREAKPOINT / SIGTRAP) on Fabric / New Architecture due to bridge! force-unwrap in RNMBXStyle.swift

1 participant