Repository: react-native
Issue: iOS crash - RCTCxxBridge enqueueApplicationScript:url:onComplete
Labels: Platform: iOS,Needs: Triage :mag:,Needs: Repro,Newer Patch Available,Needs: Attention

### Description

**we are experiencing this crash after upgrading react-native version from 0.66.5 to 0.71.13** 

Crashed: com.apple.root.user-interactive-qos
EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000000000000000

- RCTCxxBridge.mm - Line 1492
- RCTCxxBridge enqueueApplicationScript:url:onComplete:] + 1492
- RCTCxxBridge.mm - Line 1088
- RCTCxxBridge executeSourceCode:withSourceURL:sync:] + 1088
- RCTCxxBridge.mm - Line 512

__21-[RCTCxxBridge start]_block_invoke_2 + 512We

### Steps to reproduce

unable to reproduce @debug mode, only occurs in Firebase crash logs.

### React Native Version

0.71.13 (false)

### Affected Platforms

Runtime - iOS

### Output of `npx react-native info`

```text
System:
    OS: macOS 14.1.1
    CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
    Memory: 40.98 MB / 16.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 18.17.0 - ~/.nvm/versions/node/v18.17.0/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 9.6.7 - ~/.nvm/versions/node/v18.17.0/bin/npm
    Watchman: 2023.06.12.00 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.12.1 - /Users/macbookpro/.rvm/rubies/ruby-2.7.5/bin/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 23.0, iOS 17.0, macOS 14.0, tvOS 17.0, watchOS 10.0
    Android SDK: Not Found
  IDEs:
    Android Studio: 2022.2 AI-222.4459.24.2221.9862592
    Xcode: 15.0.1/15A507 - /usr/bin/xcodebuild
  Languages:
    Java: 11.0.19 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 18.2.0 => 18.2.0 
    react-native: 0.71.13 => 0.71.13 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found
```


### Stacktrace or Logs

```text
-[RCTCxxBridge enqueueApplicationScript:url:onComplete:]
EXC_BAD_ACCESS (KERN_INVALID_ADDRESS)

Crashed: com.apple.root.user-interactive-qos
EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000000000000000

Crashed: com.apple.root.user-interactive-qos
0                            0x303d0c -[RCTCxxBridge enqueueApplicationScript:url:onComplete:] + 1492 (RCTCxxBridge.mm:1492)
1                           0x301bf0 -[RCTCxxBridge executeSourceCode:withSourceURL:sync:] + 1088 (RCTCxxBridge.mm:1088)
2                          0x2ff8d0 __21-[RCTCxxBridge start]_block_invoke_2 + 512 (RCTCxxBridge.mm:512)
3  libdispatch.dylib              0x2320 _dispatch_call_block_and_release + 32
4  libdispatch.dylib              0x3eac _dispatch_client_callout + 20
5  libdispatch.dylib              0x15a64 _dispatch_root_queue_drain + 684
6  libdispatch.dylib              0x16158 _dispatch_worker_thread2 + 164
7  libsystem_pthread.dylib        0xda0 _pthread_wqthread + 228
8  libsystem_pthread.dylib        0xb7c start_wqthread + 8
```


### Reproducer

I can not find any pattern to get to the crash issue.

This is the stacktrace I got from firebase.


 Crashlytics - Stack trace
 Platform: apple
 Version: 10.0.0 (1)
Issue: 79e765fc6589aab56495ab1ac2b10d63
Session: ffed3e5f7ab449729098a9cb06b42316_DNE_0_v2

com.heartbeat.storage.1:952492006042:ios:f96f3a5be793b8f2ec1d23
0  Foundation                     0x3d208c specialized Data.init(referencing:) + 842
1                             0xf9314 HeartbeatStorage.load(from:) + 142 (HeartbeatStorage.swift:142)
2                             0xf921c closure #1 in HeartbeatStorage.readAndWriteSync(using:) + 99 (HeartbeatStorage.swift:99)
3                             0xf0e30 partial apply for thunk for @callee_guaranteed () -> () + 4309257776 (<compiler-generated>:4309257776)
4                             0xf03c8 thunk for @escaping @callee_guaranteed () -> () + 4309255112 (<compiler-generated>:4309255112)
5  libdispatch.dylib              0x3eac _dispatch_client_callout + 20
6  libdispatch.dylib              0x13428 _dispatch_lane_barrier_sync_invoke_and_complete + 56
7                             0xef1a8 HeartbeatController.flushHeartbeatFromToday() + 98 (HeartbeatStorage.swift:98)
8                             0xed168 @objc _ObjC_HeartbeatController.flush() + 4309242216
9                             0xeb224 -[FIRHeartbeatLogger heartbeatCodeForToday] + 81 (FIRHeartbeatLogger.m:81)
10                            0x14ad5c -[FIRMessagingTokenFetchOperation performTokenOperation] + 61 (FIRMessagingTokenFetchOperation.m:61)
11                            0x14fd34 __35-[FIRMessagingTokenOperation start]_block_invoke + 131 (FIRMessagingTokenOperation.m:131)
12                            0x12ed14 __55-[FIRInstallations authTokenForcingRefresh:completion:]_block_invoke_2 + 225 (FIRInstallations.m:225)
13                            0x1e9b58 __56-[FBLPromise chainOnQueue:chainedFulfill:chainedReject:]_block_invoke.18 + 273 (FBLPromise.m:273)
14 libdispatch.dylib              0x2320 _dispatch_call_block_and_release + 32
15 libdispatch.dylib              0x3eac _dispatch_client_callout + 20
16 libdispatch.dylib              0x12700 _dispatch_main_queue_drain + 1020
17 libdispatch.dylib              0x122f4 _dispatch_main_queue_callback_4CF + 44
18 CoreFoundation                 0x98c28 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 16
19 CoreFoundation                 0x7a560 __CFRunLoopRun + 1992
20 CoreFoundation                 0x7f3ec CFRunLoopRunSpecific + 612
21 GraphicsServices               0x135c GSEventRunModal + 164
22 UIKitCore                      0x39cf58 -[UIApplication _run] + 888
23 UIKitCore                      0x39cbbc UIApplicationMain + 340
24                            0xb460 main + 7 (main.m:7)
25 ???                            0x1b8eb4dec (Missing)

Thread
0  libsystem_kernel.dylib         0x11ac __workq_kernreturn + 8
1  libsystem_pthread.dylib        0xe28 _pthread_wqthread + 364
2  libsystem_pthread.dylib        0xb7c start_wqthread + 8

Thread
0  libsystem_pthread.dylib        0xb74 start_wqthread + 254

### Screenshots and Videos


![photo_2024-01-10_13-21-48](https://github.com/facebook/react-native/assets/129841919/d4c6f847-fc45-4a1c-9f79-a7ddd841d12b)