-
Notifications
You must be signed in to change notification settings - Fork 13.5k
bug: Hardware back event triggered twice (or more) if an IonReactRouter is unmounted and re-mounted #23170
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
Comments
Hi @Cyral, thanks for the issue! Can you reproduce this in an Ionic starter app and provide a link to the repo? |
@willmartindev I don't think there is a way to simulate the back button so you will have to open the android project and run it. There are two routers, one is when the user is "logged out" and one when they are "logged in". App.ts has a simple state to keep track of this. Click the login button, then try:
|
Thank you for reporting this issue and including code for reproduction! This has been resolved via #23224, and a fix will be available in an upcoming release of Ionic Framework. Additionally, when researching this issue, I came across facebook/react#12378, which you may also find helpful; I think it was one of the causes behind this issue. |
@willmartindev Thanks for the quick fix on this |
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out. |
Bug Report
Ionic version:
[ ] 4.x
[x] 5.x
Current behavior:
Hardware back button triggers the back event multiple times.
Expected behavior:
Hardware back button only triggers event once
Steps to reproduce:
Create a React app with two IonReactRouters.
For example, one router for logged out users and one for logged in users. The logged out router is mounted when the user is logged out, and upon login the new router is mounted. Only one router is mounted at any given moment, but users who log in or out will cause more than one router to be created during the app lifetime.
For example:
{isLoggedIn ? <AuthedApp/> : <UnauthedApp/>}
where each component has it's own routing.Navigate to at least two pages in the second router and then press back. Ionic will take you back two pages instead of one.
Related code:
I think the issue is that the ionBackButton event is registered but never removed when the router is unmounted. It should be removed when
componentWillUnmount
is called.Also seeing
Can't perform a React state update on an unmounted component.
from IonReactRouter which further points to this being the issue.Other information:
Ionic info:
The text was updated successfully, but these errors were encountered: