react-native-ios-context-menu: Unhandled error on iOS native side: viewNotFoundForReactTag
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?
About this issue
- Original URL
- State: open
- Created 5 months ago
- Reactions: 5
- Comments: 15 (7 by maintainers)
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.
sorry for the late response, i’ll take a look and start debugging - progress log for issue #94
Progress Log
2024-02-06-17:08- hi, during the refactor to expo, i moved a bunch of stuff around and accidentally broke the code that’s responsible for the cleanup logic/routine.2024-02-06-17:38- i’ve decided to re-write the logic that mounts the “aux. preview”/“custom preview” views + the logic that handles the cleanup routine (this might take some time) — in the meantime i’ll push some temp. fixes.2024-02-06-19:44-react-native-ios-context-menu(Release: v2.3.1 | changes)ContextMenuViewrender function.2024-02-06-21:31-react-native-ios-context-menu(Release: v2.3.2 | changes)nilReactBridgeandviewNotFoundForReactTagerrors (i.e. silent failure).2024-02-06-21:44-react-native-ios-utilities(Release: v4.2.4 | changes)RNIDetachedView.shouldNotifyOnComponentWillUnmount, and suppressnilReactBridgeerror fromRNIDetachedViewModule.notifyOnComponentWillUnmount.2024-02-07-02:17-react-native-ios-utilities(Release: v4.3.0 | changes)v4.3.0-11andv4.2.4.2024-02-07-16:34-react-native-ios-context-menu(Release: v2.4.0 | changes)react-native-ios-adaptive-modal- Raise min. dep. version toreact-native-ios-utilities@v4.3.0, and fix native build/TS type errors.2024-02-07-17:24-DGSwiftUtilities(Release: 0.13.0 | changes)HorizontalAlignmentPosition.createHorizontalConstraints.2024-02-07-17:57-ContextMenuAuxiliaryPreview(Release: 0.4.0 | changes)DGSwiftUtilities@0.13.0, and fix exit animation bug that occurs whenAuxiliaryPreviewConfig.horizontalAlignmentis set toHorizontalAlignmentPosition.stretch.2024-02-08-03:57-react-native-ios-context-menu(Release: v2.4.1 | changes)2024-02-08-15:40- Log: Testing - Push multiple screens and pop them.https://github.com/dominicstop/react-native-ios-context-menu/assets/18517029/2839671d-6440-4ecb-915c-21f0dcb3d499
2024-02-08-15:45- Log: Testing - Show and close the context menu example test items that have aux. previews; this is a test forRNIDetachedViewcleanup.https://github.com/dominicstop/react-native-ios-context-menu/assets/18517029/7e967af9-79c2-490e-955e-a9c34a2318ee
2024-02-12-22:14-react-native-ios-context-menu(Release: v2.5.0-0 | changes)internalViewCleanupModeprop.2024-02-13-05:06-DGSwiftUtilities(Release: 0.14.0 | changes)DeinitialzationObserver+ related sources fromreact-native-ios-utilities.2024-02-13-05:22-react-native-ios-utilities(changes)RNICleanableView+ related sources fromreact-native-ios-utilities.2024-02-13-05:32-react-native-ios-context-menu(Release: v2.5.0-1 | changes)RNICleanableView, and replace w/ impl. fromreact-native-ios-utilities.2024-02-14-03:41-DGSwiftUtilities(changes)ClassRegistry+ related sources fromreact-native-ios-utilities, and impl.Singletonprotocol.2024-02-15-18:57-react-native-ios-utilities(changes)RNIHelpers.recursivelyRemoveFromViewRegistry.2024-02-15-22:06-react-native-ios-context-menu(changes)2024-02-15-23:31-react-native-ios-utilities(v4.4.0-2 | changes)RNIDetachedView.internalViewCleanupModeprop, updateRNICleanableViewRegistry, impl.RNIUtiltiesModule+RNICleanableViewRegistryEnv.2024-02-18-09:40-DGSwiftUtilities(changes)VerboseError, impl.VerboseErrorSharedEnv+InitializableSingletonprotocol.2024-02-20-07:11-react-native-ios-utilities(Release: v4.4.0-3 | changes)RNICleanableView+ related sources.2024-02-21-01:07- Log:react-native-ios-utilities- TestingRNIDetachedViewTest01https://github.com/dominicstop/react-native-ios-context-menu/assets/18517029/43eb9b19-9862-4e59-a7cd-2e3ac42825ab
2024-02-26-10:01-react-native-ios-utilities(v4.4.0-4 | changes)2024-02-27-02:26-react-native-ios-utilities(v4.4.0-5 | changes)2024-02-27-18:57-react-native-ios-context-menu(Release: v2.5.0-2 | changes)react-native-ios-utilities, and update cleanup logic forRNIContextMenuView, andRNIContextMenuButton.2024-02-27-19:05- # Log:react-native-ios-context-menu- Testinghttps://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):
RCTUIManagersingleton has a private variable called_viewRegistry._viewRegistryis a dictionary (i.e.NSDictionary<NSNumber, RCTView>)_viewRegistry.reactTag: NSNumberproperty (which AFAIK just mirrorsUIView.tag).reactTagtogether to reference a react view in the app’s view hierarchy.ReactNative.findNodeHandle), but has since been deprecated in the new architecture (and should no longer be used).onReactTagDidSetevent, and pass the “react tag” value to JS.RCTUIManager._viewRegistrykeeps a strong a reference to everyRCTViewinstance to prevent them from vanishing into the void.RCTUIManageris a singleton, and will “live” for the entire duration of the app, anything inside_viewRegistrywill also “live” for the entire duration of the app.UIKit, neverthelessRCTUIManagerdoes not like it when you interfere with anRCTView’s view lifecycle (e.g. moving it to a different view, removing it from it’s parent, etc).RCTUIManager, it’ll no longer manage the lifecycle for that specific view instance.RCTViewinstance to get “orphaned” and live forever.CALayer, as such it shouldn’t be using any resources).reanimatedworklet), a crash will occur.onComponentWillUnmount, anddeinitto trigger the cleanup routine.Nice! When the release comes out, I can cut new release to try it.
Interestingly, I don’t think I’ve had this issue since upgrading to 2.4.2 and ios-utilities 4.3.1
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.
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 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
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.
I encountered this issue before, and it was fixed by
react-native-ios-context-menuv2.4.0 andreact-native-ios-utilitiesv4.3.0 on my end. Could you guys try it out?Confirming we are getting the same issue: