react-native-ios-utilities icon indicating copy to clipboard operation
react-native-ios-utilities copied to clipboard

[iOS] Crash on React Native 0.77 - Context Menu View x RNIBaseView

Open delphinebugner opened this issue 8 months ago โ€ข 15 comments
trafficstars

Hi!

Thanks for working on the lib; I'm updating my app from React Native 0.76 to React Native 0.77, and it crashes because of react-native-ios-context-menu and reat-native-ios-utilities

First opened an issue on Zeego's repo: https://github.com/nandorojo/zeego/issues/141#issue-2895339132

But it's the Context Menu View only that crashes with this stack trace:

0   CoreFoundation                	       0x1804b70e0 __exceptionPreprocess + 160
1   libobjc.A.dylib               	       0x18008ede8 objc_exception_throw + 72
2   CoreFoundation                	       0x1804b6c80 -[NSException init] + 0
3   Foundation                    	       0x180eaa40c -[NSObject(NSKeyValueCoding) valueForUndefinedKey:] + 188
4   Foundation                    	       0x180ea92f0 -[NSObject(NSKeyValueCoding) valueForKey:] + 260
5   App.debug.dylib                 0x107ca2e10 __49-[RCTComponentData createPropBlock:isShadowView:]_block_invoke_2.45 + 316 (RCTComponentData.mm:341)
6   App.debug.dylib           	       0x107ca367c __49-[RCTComponentData propBlockForKey:isShadowView:]_block_invoke_2 + 52 (RCTComponentData.mm:367)
7   App.debug.dylib           	       0x107d0a628 RCTPerformBlockWithLogFunction + 408 (RCTLog.mm:167)

Error message is "Error setting onMenuWillShow of RNIContextMenuButton"

Context Menu crashes because valueForUndefinedKey can't be found for props key reactEventHandler for a RCTView -> should it call RNIBaseView+KVC here?

See the (roughly) explaining screenshots:

image

It looks really close to the code written in this PR: https://github.com/dominicstop/react-native-ios-utilities/pull/11, so @coolsoftwaretyler if you have an opinion on this, as author of the RNIBaseView+KVC change !

Disclaimer: I'm a newbie concerning ObjectiveC code ๐Ÿ˜…

Tried to build a repro but it works fine on an empty project, only fails on my app :/

delphinebugner avatar Mar 07 '25 19:03 delphinebugner

Also:

  • I'm in New Arch
  • i'm not using dynamic frameworks
  • The error message when using a simple Context Menu View is a different than when I used Zeego, but similar: "Error setting property onDidSetViewID of RNIWrapperView"

Image

delphinebugner avatar Mar 07 '25 20:03 delphinebugner

Just stepped away from my computer a few days but if no one else gets to this before I do, I'll take a look soon!

coolsoftwaretyler avatar Mar 07 '25 22:03 coolsoftwaretyler

@delphinebugner - I know you said you can't get a repro to work, and I assume you can't share your full codebase, but is there ay chance you can share an example of your Zeego usage? I want to see if I can make a reproduction on my end. It would be helpful to see what your Zeego usage looks like.

coolsoftwaretyler avatar Mar 10 '25 01:03 coolsoftwaretyler

Both my implementation, Zeego's example and simple Context Menu View have the crash; so i think it comes from my app's setup. I'm in a pnpm monorepo; I use NativeWind, Reanimated, Gesture Handler... I build my repro adding them one by one to a blank template, currently still not able to provoque the crash ๐Ÿ™ must continue to search!

delphinebugner avatar Mar 10 '25 08:03 delphinebugner

Update: I just come back to this; tried with react-native-ios-utilities: 5.1.3 and I still have the issue!

Will look more into it now ๐Ÿ‘€

delphinebugner avatar Mar 31 '25 12:03 delphinebugner

I tried removing a lot of dependancies and config in my app - nothing changed.

Turns out it's the monorepo itself that causes the pb: we use pnpm + node-linker: isolated This goes against the recommandation for monorepo: React Native works better with node-linker=hoisted. But we can't have it on my project. The result is all of our node_modules subfolders are symlinks.

This causes the crash. When I manually copy (yes, this is shady) the react-native-ios-context-menu and react-native-ios-utilities folders in my node modules, it works.

Recap illustrated here:

Image

@dominicstop @coolsoftwaretyler do you have idea on how to make it work natively ? there's confusion in headers / import files because of the symlinks, definitely; I worked on a repro with pnpm, but can't have it work with node-linker: isolated yet -_-

delphinebugner avatar Apr 01 '25 10:04 delphinebugner

hello @delphinebugner

thank you for the detailed issue, and sorry for the late response! (i am unable to do OSS atm but i'll do my best to help)

i upgraded the example from v75 to v77 but i am unable to repro (see attached video)

https://github.com/user-attachments/assets/41670fef-2947-40c4-b9f3-318ea6ee4034



can you please do the ff:

  • run bundle exec pod install and paste the output?
  • paste the contents of: ios/build/generated/ios/RCTThirdPartyComponentsProvider.mm
  • paste your AppDelegate.mm or AppDelegate.swift
  • run yarn run react-native info and paste the output

in the meantime, i'll take a look at the info you've provided to see if there's anything i've missed...

dominicstop avatar Apr 01 '25 17:04 dominicstop

Yes, it works with a normal RN 0.77 setup; I reproduce only in a pnpm monorepo with node-linker: isolated - a small repro of it is in progress ๐Ÿ™‚

delphinebugner avatar Apr 01 '25 20:04 delphinebugner

I have the repro!!!!! So happy, I'd never managed to have it before on a showable repo!

Just clone it from here: https://github.com/delphinebugner/expo-monorepo-example

I hope you'll find all your answers in it ๐Ÿ™‚

delphinebugner avatar Apr 01 '25 21:04 delphinebugner

Nit: is probably similar to this issue on React Native Screen -> https://github.com/software-mansion/react-native-screens/issues/2718

Something changed in the way React Native 0.77 link native dep!

delphinebugner avatar Apr 03 '25 10:04 delphinebugner

I got the same crash. My investigation indicated that this may be related to dynamic linking.

[
    "expo-build-properties",
    {
      "ios": {
        "deploymentTarget": "17.0",
        "useFrameworks": "dynamic"
      }
    }
]

I was testing using expo default template with the following dependency. If I enabled dynamic use_frameworks in cocoapods, this will crash. However, I'm not sure if it's related to which dependency.

"react-native-ios-context-menu": "3.1.0",
"react-native-ios-utilities": "5.1.2",
"react-native-reanimated": "~3.16.1",

icodesign avatar Apr 15 '25 13:04 icodesign

I can also confirm in my setup that the crash only happens when using a symlink'd pnpm monorepo.

When I add node-linker=hoisted to .npmrc in the workspace root, it works without changing anything else. I did a full clean and reinstall/rebuild of everything testing it to verify it.

zhm avatar Apr 16 '25 02:04 zhm

When I add node-linker=hoisted to .npmrc in the workspace root, it works without changing anything else. I did a full clean and reinstall/rebuild of everything testing it to verify it.

If this is the root cause for @delphinebugner and @icodesign - I don't think there's much that react-native-ios-utilities needs to change. Expo has this setting documented in their monorepo instructions.

@delphinebugner - I'm trying to check if node-linker=hoisted works on your reproducer app, but I'm getting a totally different error on a clean build:

Seems unrelated to this issue at hand. Any chance you can try node-linker=hoisted and report back?

Interestingly: I ran npx expo install --fix on your reproducer (after removing the ignore block in apps/example/package.json) and then everything worked fine on pnpm build:ios. Of course, that downgrades back to React Native 0.76.9 :/

coolsoftwaretyler avatar Apr 27 '25 23:04 coolsoftwaretyler

Thanks for the info @coolsoftwaretyler!

I just cloned the @delphinebugner's reproducer app and I was able to reproduce the error. And then deleted all the intermediate files and replaced node-linker=isolated with node-linker=hoisted and it works correctly.

I know the expo docs do mentioned using hoisted, but support for symlink'd dependencies was turned on by default in RN 0.73. I wonder if the docs just need to be updated? In my app I have many of the common community packages installed and they all work fine inside a symlinked pnpm monorepo. Only this package seems to be impacted, which is weird.

zhm avatar Apr 29 '25 17:04 zhm

I still can't get the reproducer past the (maybe) unrelated error, so I'm not sure if I can be super helpful. I tried after clearing my pod cache and it's still got the same runtime not ready error. Still no luck :/

coolsoftwaretyler avatar May 03 '25 01:05 coolsoftwaretyler

Update on my side:

  • still having the issue with React Native 0.79 + Expo 53 + node_linker: isolated
  • still can't use node_linker: hoisted on Expo 53, this time because of a Native Wind issue (here)
  • still needing to find a fix therefore ๐Ÿ˜…

delphinebugner avatar May 28 '25 11:05 delphinebugner

Tried with

[
    "expo-build-properties",
    {
      "ios": {
        "deploymentTarget": "17.0",
        "useFrameworks": "static"
      }
    }
]

Spoiler: did not solve the issue (I don't need to activate the frameworks on my project anyway)

delphinebugner avatar May 28 '25 11:05 delphinebugner

@delphinebugner thanks for the update. I've got some more time this week and I will try to take another look.

coolsoftwaretyler avatar May 28 '25 14:05 coolsoftwaretyler

I tried to use expo-ui ContextMenu to try to replace this lib, but it currently does not work either on my app ๐Ÿ˜ญ We're cursed with Menu ahah

delphinebugner avatar May 28 '25 14:05 delphinebugner

@delphinebugner I'm curious about the NativeWind problem, I'm using NativeWind with hoisted and it's all working for me.

Using these versions of various libraries, ContextMenu works for me (with hoisted of course!):

react: 19.0.0 react-native: 0.79.2 expo: 53.0.9 nativewind: 4.1.23 react-native-ios-utilities: 5.1.5

zhm avatar May 28 '25 18:05 zhm

Okaay Titozz have found something incredibly interesting - Webview also had an issue with PNPM + RN 0.77 : https://github.com/react-native-webview/react-native-webview/issues/3697#issuecomment-2920364688

Will need to try on this lib the new Codegen config! And / or fix the pnpm exclusion issue on RN core

@zhm haven't found the root cause for Native Wind - I havn't dig a lot yet, in the end I want to keep node-linker isolated!

delphinebugner avatar May 30 '25 06:05 delphinebugner

@delphinebugner - I was able to get your reproduce app to work (as in, to get the bug reproduction). I had to run this in apps/example:

npx expo install react-native@~0.77.1 react-native-reanimated@~3.16.7 react-native-gesture-handler@~2.22.0 react-native-screens@~4.8.0 react-native-safe-area-context@~5.1.0 react-native-webview@~13.13.1

Now that I can reproduce locally, I'll take a closer look this weekend and see if I can help actually solve the issue.

coolsoftwaretyler avatar May 31 '25 20:05 coolsoftwaretyler

@delphinebugner - I have confirmed that this patch into React Native will fix the issue on your reproducer.

Here are my debugging steps from tonight: https://www.notion.so/RN-iOS-Utilities-Issue-21-Debuggin-20412393824d80de9977ff285c9cd3e3?source=copy_link

I'll submit a PR to your reproducer repro with the patch so that you can see it in action. I don't think this is for react-native-ios-utilities to fix, but rather upstream instead. If the patch works on your actual code, will you let us know and close this out? (or @dominicstop - maybe we keep this open until React Native closes https://github.com/reactwg/react-native-releases/issues/971)

coolsoftwaretyler avatar Jun 01 '25 00:06 coolsoftwaretyler

I just tried quickly the patch on my real-life project:

  • I don't have the crash anymore ๐ŸŽ‰
  • but getting a Fabric issue "Unimplemented component"
Image

~I will try on the empty app, but I think - as Thibault explained in the WebView issue - there is something to do in this library. If you want to use the Codegen properly, you need to add additional configuration: https://reactnative.dev/docs/next/the-new-architecture/using-codegen#configuring-codegen~

Edit: probably a cache & rebuild issue, no longer having it!

delphinebugner avatar Jun 02 '25 07:06 delphinebugner

Ah I see. I think we'll need to update https://github.com/dominicstop/react-native-ios-context-menu/blob/master/package.json over in a different repo.

coolsoftwaretyler avatar Jun 02 '25 11:06 coolsoftwaretyler

Looks like there's an open issue for that: https://github.com/dominicstop/react-native-ios-context-menu/issues/127 Unimplemented component: <RNIContextMenuView> ยท Issue #127 ยท dominicstop/react-native-ios-context-menu

coolsoftwaretyler avatar Jun 02 '25 11:06 coolsoftwaretyler

Interesting @coolsoftwaretyler! The user is on Expo 52 + RN 0.76, it should be fixable apart from any RN 77 / monorepo setup

delphinebugner avatar Jun 02 '25 12:06 delphinebugner

Well, after I-don't-know which magical operation of cleaning and rebuild, I don't have the unimplemented error anymore; it is really resolved! The discovery of the .pnpm folder is enough :)

delphinebugner avatar Jun 03 '25 16:06 delphinebugner

If anyone happens to run into this issue in the future, this same crash can also be caused by naming a monorepo react-native. Totally on me for poor naming conventions so I'm not creating an issue for it, but hopefully this can save someone the 6 hours I'll never get back.

P.S. Thanks for all the super thorough documentation of debugging in this thread!

nathan-ahn avatar Jun 19 '25 05:06 nathan-ahn

i'm still facing this crash in a bare React Native project

"react-native": "0.80.2", "react-native-ios-utilities": "^5.1.8",

chiefchief avatar Jul 30 '25 18:07 chiefchief