Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

react_native_assert failure: link_.status != Status::Running && "Surface must not be running." #48149

Closed
L0NG4R3S opened this issue Dec 6, 2024 · 4 comments
Labels
Resolution: Answered When the issue is resolved with a simple answer Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules)

Comments

@L0NG4R3S
Copy link

L0NG4R3S commented Dec 6, 2024

Description

I recently integrated React Native into my native Swift app, it worked normally with version 0.75.4
But I updated to React Native 0.76.3 to be able to use the new architecture.
After the update, when building, the app crashes with the error: "Surface must not be running".

Steps to reproduce

Integrate with existing Swift App following docs: https://reactnative.dev/docs/integration-with-existing-apps
Upgrade to React 0.76.3: https://react-native-community.github.io/upgrade-helper/?from=0.75.4&to=0.76.3

  1. Clone project: https://github.com/L0NG4R3S/SurfaceErrorRepository
  2. Run yarn start
  3. yarn install && cd ios && pod install
  4. yarn ios or open ReproducerApp.xcworkspace in xcode and run

React Native Version

0.76.3

Affected Platforms

Runtime - iOS

Areas

TurboModule - The New Native Module System

Output of npx react-native info

System:
  OS: macOS 15.1.1
  CPU: (8) x64 Intel(R) Core(TM) i7-8569U CPU @ 2.80GHz
  Memory: 227.51 MB / 16.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 21.7.3
    path: ~/.nvm/versions/node/v21.7.3/bin/node
  Yarn:
    version: 1.22.22
    path: ~/.nvm/versions/node/v21.7.3/bin/yarn
  npm:
    version: 10.5.0
    path: ~/.nvm/versions/node/v21.7.3/bin/npm
  Watchman:
    version: 2024.10.21.00
    path: /usr/local/bin/watchman
Managers:
  CocoaPods:
    version: 1.16.2
    path: /usr/local/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 24.1
      - iOS 18.1
      - macOS 15.1
      - tvOS 18.1
      - visionOS 2.1
      - watchOS 11.1
  Android SDK: Not Found
IDEs:
  Android Studio: 2023.2 AI-232.10300.40.2321.11567975
  Xcode:
    version: 16.1/16B40
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.11
    path: /usr/bin/javac
  Ruby:
    version: 2.6.10
    path: /usr/bin/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 16.0.0
    wanted: ^16.0.0
  react:
    installed: 19.0.0
    wanted: 19.0.0
  react-native:
    installed: 0.76.3
    wanted: 0.76.3
  react-native-macos:
    installed: 0.76.4
    wanted: ^0.76.4
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: true
  newArchEnabled: true

Stacktrace or Logs

WARNING: Logging before InitGoogleLogging() is written to STDERR
E1206 09:11:06.964253 89726976 SurfaceHandler.cpp:318] react_native_assert failure: link_.status != Status::Running && "Surface must not be running."
Assertion failed: (link_.status != Status::Running && "Surface must not be running."), function setUIManager, file SurfaceHandler.cpp, line 318.

Reproducer

https://github.com/L0NG4R3S/SurfaceErrorRepository

Screenshots and Videos

Captura de Tela 2024-12-06 às 09 29 05
@L0NG4R3S L0NG4R3S added Needs: Triage 🔍 Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules) labels Dec 6, 2024
@cortinico
Copy link
Contributor

But I updated to React Native 0.76.3 to be able to use the new architecture.

I'd suggest you first update to 0.76.3 without the New Architecture and then enable it. Otherwise it will be hard to understand what is causing the failure

@L0NG4R3S
Copy link
Author

L0NG4R3S commented Dec 6, 2024

But I updated to React Native 0.76.3 to be able to use the new architecture.

I'd suggest you first update to 0.76.3 without the New Architecture and then enable it. Otherwise it will be hard to understand what is causing the failure

If I run my application without the new architecture after running RCT_NEW_ARCH_ENABLED=0 pod install , the problem no longer happens. The error only occurs if the new architecture is enabled

I attached a video of my application operating without the new architecture

20241206114522443.mp4

@chinamcafee
Copy link

I met the same issue, perhaps react native can't support React 19 right now.

But I wonder if there is a roadmap when React Native can fully support React 19.

@cortinico
Copy link
Contributor

  react:
    installed: 19.0.0
    wanted: 19.0.0

@L0NG4R3S you can't install version 19 of React with React Native 0.76.
The version of React is dictated by the React Native version. You can read more about it here:

https://github.com/facebook/react-native/blob/main/packages/react-native/Libraries/Renderer/README.md

@L0NG4R3S L0NG4R3S closed this as completed Dec 9, 2024
@cortinico cortinico added Resolution: Answered When the issue is resolved with a simple answer and removed Needs: Triage 🔍 labels Dec 9, 2024
facebook-github-bot pushed a commit that referenced this issue Dec 24, 2024
#48213)

Summary:
Fixes #48149. Actually this issue is not caused by React 19. The underlying problem arises because we retain the surface in RCTHost at the time of its creation. Even though we call stop, there is a return check that prevents execution if the status is not running. For reference, you can view the relevant code here: [RCTFabricSurface.mm](https://github.com/facebook/react-native/blob/7d771de8a79b05e8dfed91e07de30d9f72d3c1c3/packages/react-native/React/Fabric/Surface/RCTFabricSurface.mm#L118).

To resolve this issue, we can implement a weak reference to the surface.

bt:
```
(lldb) bt
* thread #13, queue = 'com.apple.root.user-interactive-qos', stop reason = signal SIGABRT
    frame #0: 0x0000000105699008 libsystem_kernel.dylib`__pthread_kill + 8
    frame #1: 0x00000001045df408 libsystem_pthread.dylib`pthread_kill + 256
    frame #2: 0x000000018016c4ec libsystem_c.dylib`abort + 104
    frame #3: 0x000000018016b934 libsystem_c.dylib`__assert_rtn + 268
    frame #4: 0x000000010651f4b4 React_Fabric`facebook::react::SurfaceHandler::setUIManager(this=0x0000000108108620, uiManager=0x0000000000000000) const at SurfaceHandler.cpp:317:3
    frame #5: 0x00000001064c98f4 React_Fabric`facebook::react::Scheduler::unregisterSurface(this=0x0000600003500370, surfaceHandler=0x0000000108108620) const at Scheduler.cpp:252:18
    frame #6: 0x0000000104c3e8a8 RCTFabric`-[RCTScheduler unregisterSurface:](self=0x000060000212a940, _cmd="unregisterSurface:", surfaceHandler=0x0000000108108620) at RCTScheduler.mm:163:15
    frame #7: 0x0000000104c61fc4 RCTFabric`-[RCTSurfacePresenter unregisterSurface:](self=0x00000001081080d0, _cmd="unregisterSurface:", surface=0x0000000108108610) at RCTSurfacePresenter.mm:126:5
  * frame #8: 0x0000000104bc30a0 RCTFabric`-[RCTFabricSurface dealloc](self=0x0000000108108610, _cmd="dealloc") at RCTFabricSurface.mm:87:3
    frame #9: 0x0000000104b9ae44 RCTFabric`__destroy_helper_block_ea8_32s((null)=0x0000600000cb5a70) at RCTBoxShadow.mm:0
    frame #10: 0x00000001800f6edc libsystem_blocks.dylib`_call_dispose_helpers_excp + 44
    frame #11: 0x00000001800f7d24 libsystem_blocks.dylib`_Block_release + 300
    frame #12: 0x000000010760a7b8 libdispatch.dylib`_dispatch_client_callout + 16
    frame #13: 0x000000010761e608 libdispatch.dylib`_dispatch_root_queue_drain + 936
    frame #14: 0x000000010761ef7c libdispatch.dylib`_dispatch_worker_thread2 + 256
    frame #15: 0x00000001045dbb38 libsystem_pthread.dylib`_pthread_wqthread + 224
```

## Changelog:

[IOS] [FIXED] - Fabric: Fixes assert failure when surface stop before we start surface

Pull Request resolved: #48213

Test Plan:
Please see demo in #48149. Or open RNTester and apply the patch like below:
```
 diff --git a/packages/rn-tester/RNTester/AppDelegate.mm b/packages/rn-tester/RNTester/AppDelegate.mm
index 64c5d4122e7..cf015458619 100644
 --- a/packages/rn-tester/RNTester/AppDelegate.mm
+++ b/packages/rn-tester/RNTester/AppDelegate.mm
@@ -50,7 +50,10 @@ static NSString *kBundlePath = @"js/RNTesterApp.ios";

   [[UNUserNotificationCenter currentNotificationCenter] setDelegate:self];

-  return [super application:application didFinishLaunchingWithOptions:launchOptions];
+  [super application:application didFinishLaunchingWithOptions:launchOptions];
+  self.window.rootViewController = [UIViewController new];
+  [self.window makeKeyAndVisible];
+  return YES;
 }

 - (void)applicationDidEnterBackground:(UIApplication *)application

```

Reviewed By: javache

Differential Revision: D67335792

Pulled By: cipolleschi

fbshipit-source-id: e93aaaa60b3d204d7ed2cda6758b3b1d9dfcbc88
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Answered When the issue is resolved with a simple answer Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants