fix: iOS crash occurring when navigating to a new app screen with a displaying modal
Summary:
Our app is using the react-native v0.74.2 with the react-navigation lib for screen navigation, we're facing an issue in the built iOS app that when we try to navigate to a new app screen with the react-navigation's reset or replace method and meanwhile there's a react native modal displaying, then the iOS app always crashes.
I saw there is already a relevant PR and discussion targeting this issue, but I still think it would be better if this kind of crash can be suppressed in the framework level, currently I guess it's common in the iOS apps based on react native.
Changelog:
[IOS] [FIXED] - app crash happening when navigate to a new app screen with a displaying modal
Test Plan:
More issue details and the reproduction steps can be found in this PR :)
Hi @zhouzh1!
Thank you for your pull request and welcome to our community.
Action Required
In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.
Process
In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.
Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.
If you have received this in error or have any questions, please contact us at [email protected]. Thanks!
@mojodna @jsierles @augustl could you help take a review? Thanks.
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!
Anyone can help take a look or provide some insights about if this change is safe or not?
This issue is causing multiple crashes for us in production every day. Would appreciate if a fix like this could be merged. We use reset/replace actions when following deep links. No good way to know if the user has a modal open when we do so.
Tested applying the suggested fix manually and it seems to work without issue.
@mrand15 Glad to hear that it's working for you, I already applied this fix in our production app for a long while, seems that this issue has been resolved and this change didn't introduce other new issues. @cortinico Could you help take a look please?
@cipolleschi Sorry that our app hasn't started to apply the new React native architecture, so I am not sure if it's suffering from this issue as well, but I took a look at the above RCTModalHostViewComponentView file that you posted, I guess it's no problem, because in this file, the _shouldPresent variable replaces the _visible variable in the old architecture, and there is already such a process similar to what this fix PR does.
@cipolleschi Could you help take a look again? We're going to upgrade the react native in our project, if this fix makes sense, then we may don't need the extra patch file for react native.
@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.
@cipolleschi merged this pull request in facebook/react-native@52888c0c1e722a799f233c2f502e01b9dd4a7174.
This pull request was successfully merged by Zhi Zhou in 52888c0c1e722a799f233c2f502e01b9dd4a7174
When will my fix make it into a release? | How to file a pick request?
@zhouzh1 which version are you using? can you create a pick request for the versions that needs the fix?
@cipolleschi - My project has upgraded to react-native:0.73.7 3 months back.I raised the issue #44612 . Can I add this line [self setVisible: NO]; below the code for a temporary fix or Can I pick a request to react-native:0.73.7 to fix issue #44612 ? node_modules>react-native>React>Views>RCTModalHostView.m We will upgrade my project to the latest react-native version once the client approves the newest version.
(void)dismissModalViewController { if (_isPresented) { [_delegate dismissModalHostView:self withViewController:_modalViewController animated:[self hasAnimationType]]; _isPresented = NO; [self setVisible: NO] // Add this line // } }
yeah, 0.73 is still in the support window. I created the cherry pick request: https://github.com/reactwg/react-native-releases/issues/531 We need the same pick for other versions too, let me create them.
@cipolleschi - Thanks for your update. https://github.com/reactwg/react-native-releases/issues/531 release fix will resolve my issue #44612 ?
@gkasireddy202 I don't know... I understood you were asking to pick the fix because you tested it and it fixed it... 😅
Can you try to:
- add that line in your project
- try to trigger the crash
- report back whether it worked or not
@cipolleschi - I added that line to my project and tested it. I triggered the crash. This is the issue that I faced in react-native:0.73.7.
https://github.com/facebook/react-native/issues/44612#issuecomment-2360716821
This pull request was successfully merged by Zhi Zhou in 8ec672204d5dee2b967cac08adf03c082e36ad79.
When will my fix make it into a release? | How to file a pick request?