dominicstop / react-native-ios-context-menu

A react-native component to use context menu's (UIMenu) on iOS 13/14+
MIT License
536 stars 24 forks source link

Unhandled error on iOS native side: viewNotFoundForReactTag #94

Open danielrhodes opened 8 months ago

danielrhodes commented 8 months ago

I am seeing these come up as unhandled errors in my exception tracker in production. I am on v 2.3 of this library and v 4.2.3 of react-native-ios-utilities. It seems to happen regardless of iOS version or device or React Native version (recently upgraded to 0.73 from 0.72).

I suspect what is happening is some sort of re-render is happening and the context menu loses its underlying reference to the root view.

Error domain: react-native-ios-utilities - code: viewNotFoundForReactTag - description: No corresponding view instance found for react tag - extraDebugValues: extraDebugValuesString: { node: 597, targetType: RNIContextMenuView } - fileName: /Users/<REDACTED>/code/<REDACTED>/packages/app/node_modules/react-native-ios-utilities/ios/Sources/Helpers/RNIModuleHelpers.swift - functionName: getView(withErrorType:forNode:type:bridge:) - lineNumber: 39 - columnNumber: 27 
    (native) construct
    (native) apply
    /Users/<REDACTED>/Library/Developer/Xcode/DerivedData/app-elacbqvdwmqsunameeuzcynrbwae/Build/Intermediates.noindex/ArchiveIntermediates/app/BuildProductsPath/Release-iphoneos/main.jsbundle:3211:28 _construct
    /Users/<REDACTED>/Library/Developer/Xcode/DerivedData/app-elacbqvdwmqsunameeuzcynrbwae/Build/Intermediates.noindex/ArchiveIntermediates/app/BuildProductsPath/Release-iphoneos/main.jsbundle:3173:25 Wrapper
    (native) construct
    /Users/<REDACTED>/Library/Developer/Xcode/DerivedData/app-elacbqvdwmqsunameeuzcynrbwae/Build/Intermediates.noindex/ArchiveIntermediates/app/BuildProductsPath/Release-iphoneos/main.jsbundle:187182:322 _createSuperInternal
    (native) call
    /Users/<REDACTED>/Library/Developer/Xcode/DerivedData/app-elacbqvdwmqsunameeuzcynrbwae/Build/Intermediates.noindex/ArchiveIntermediates/app/BuildProductsPath/Release-iphoneos/main.jsbundle:187195:26 CodedError

which references https://github.com/dominicstop/react-native-ios-utilities/blob/master/ios/Sources/Helpers/RNIModuleHelpers.swift#L38-L50

Is there anything I can do to mitigate this?

valentinchelle commented 8 months ago

I've noticed this issue too after upgrading to 0.73 (expo 50). I've also noticed a memory leak issue (the number of views in the performance monitoring wouldn't stop going up after multiple mount unmounts). I believe that the preview isn't being unmounted correctly (i tried all the props related to garbage collection) .

Additionally, I noticed that the Auxiliary preview crashes when dismissed.

danielrhodes commented 8 months ago

@valentinchelle I haven't been able to consistently reproduce it locally, but previously I found that it was quite vulnerable to remounts of the parent component / tree and fiddling with the cleanup may have helped somewhat.

nandorojo commented 7 months ago

Confirming we are getting the same issue:

image

dominicstop commented 7 months ago

sorry for the late response, i'll take a look and start debugging - progress log for issue #94


Progress Log

https://github.com/dominicstop/react-native-ios-context-menu/assets/18517029/2839671d-6440-4ecb-915c-21f0dcb3d499


https://github.com/dominicstop/react-native-ios-context-menu/assets/18517029/7e967af9-79c2-490e-955e-a9c34a2318ee


https://github.com/dominicstop/react-native-ios-context-menu/assets/18517029/43eb9b19-9862-4e59-a7cd-2e3ac42825ab


https://github.com/dominicstop/react-native-ios-context-menu/assets/18517029/7203d663-cd21-4701-a78b-649fecb6d78c



Explanation

hello, it looks like the recent patches i've made has caused a bunch of crashes; i apologize if you were affected by this.

i'll write a short explanation on why the "clean up" function is needed (hopefully, with the help of he community, we can find a solution that's reliable):

alantoa commented 7 months ago

I encountered this issue before, and it was fixed by react-native-ios-context-menu v2.4.0 and react-native-ios-utilities v4.3.0 on my end. Could you guys try it out?

danielrhodes commented 7 months ago

I updated but this is still occurring for me, but I might have a better clue about what is happening:

I am using react-navigation, and if I click a menu item which triggers a screen change, it might cause this error. I believe this is because the menu has not closed by the time the view is removed.

I have no idea if this will fix it, but I am putting in a setTimeout after receiving an event - will see if that helps.

dominicstop commented 7 months ago

@danielrhodes hi, i need some sort of small repro/code snippet so i can debug this further (i'll add it as a test case in the example app for future reference). i'm having some trouble trying to recreate the issues you're describing.

if possible, can you please provide some screenshots/video of the performance monitor while re-creating the issue/bug? (you can crop the video via the photos app to redact the contents of your app)

(i've added some screen recordings in my previous reply)

danielrhodes commented 7 months ago

@dominicstop I haven't been able to replicate it locally, but I am seeing it quite often from exception logs in production.

Here is an example project that isn't much different from my own to give you something to work with. https://github.com/danielrhodes/ios-context-menu-bug-example

alantoa commented 7 months ago

yeah, we only found this error log in the production log. but so far I have discovered that this error has not caused the app to crash yet. so it's kind of weird...

dominicstop commented 7 months ago

@danielrhodes it looks like the view count in the performance monitor is not up to date somehow (there is no memory leak)

Screenshot 2024-02-21 at 11 02 32 PM



Screenshot 2024-02-21 at 11 21 17 PM



Screenshot 2024-02-21 at 11 14 04 PM



Screenshot 2024-02-21 at 11 20 35 PM
danielrhodes commented 7 months ago

@danielrhodes it looks like the view count in the performance monitor is not up to date somehow (there is no memory leak)

If that's using the project I shared above, this could be because FlashList does view recycling. I'm not too familiar with how this all works under the hood, but one thing I've wondered is if this error happens while a re-render is happens and the context menu is still displaying.

dominicstop commented 7 months ago

@danielrhodes hello, i've done some more research...

i look at the code for RCTPerformanceManager, and it looks like it just counts the views from the view registry....

2024-02-26-11-21-15

after that, i started debugging again...



2024-02-26-12-06-20 2024-02-26-12-16-03


EDIT: I think i might finally fixed this in the latest prerelease version.

https://github.com/dominicstop/react-native-ios-context-menu/assets/18517029/3684c9ec-6089-427c-bb05-0e2b355f9a99

nandorojo commented 7 months ago

Interestingly, I don't think I've had this issue since upgrading to 2.4.2 and ios-utilities 4.3.1

danielrhodes commented 6 months ago

EDIT: I think i might finally fixed this in the latest prerelease version.

Nice! When the release comes out, I can cut new release to try it.

dominicstop commented 6 months ago

hello @danielrhodes

for now you would have to use: react-native-ios-context-menu@v2.5.0-2 + react-native-ios-utilities@v4.4.0-5.

i'm still testing all of the example + test items in the example app; i just wanna be sure first that the changes i've made recently won't cause a crash somehow (i haven't found any issues so far...)

it would be great if you could try it out, and see if there are any bugs + give feedback ahsdjhkdsldfkdj

if you decide to install the pre-release version, i recommend adding the code snippet below in you App.js/app entry file so we can get some more debugging info (you can disable/remove them anytime).

import { setSharedEnvForRNICleanableViewRegistry, setSharedEnvForRNIUtilitiesModule } from 'react-native-ios-utilities';

setSharedEnvForRNIUtilitiesModule({
  debugShouldLogViewRegistryEntryRemoval: true,
  overrideEnableLogStackTrace: true,
  overrideShouldLogFileMetadata: true,
  overrideShouldLogFilePath: true
});

setSharedEnvForRNICleanableViewRegistry({
  debugShouldLogCleanup: true,
  debugShouldLogRegister: true,
  shouldGloballyDisableCleanup: false,
});