-
Notifications
You must be signed in to change notification settings - Fork 13.5k
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
bug: Ionic React useIonRouter returns unstable reference causing maximum update depth error in useEffect #24987
Comments
Oh - sorry meant to say happy to submit the PR. Just thought I would need to file the issue first. Thanks! |
Thanks, I can reproduce this behavior. We are happy to review a PR. |
Thanks for confirming @liamdebeasi. I'll look over your CONTRIB docs and get something in the queue for ya! |
@liamdebeasi sorry to ping you here - just having a small issue following the PR guidelines.
Do i need to run the |
|
Wrap router object that is returned in a `useMemo` to provide stable reference for any dependency arrays it may be supplied to. This would address and close ionic-team#24987
Thanks for the issue. This has been resolved via #25000, and a fix will be available in an upcoming release of Ionic Framework. |
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. |
Prerequisites
Ionic Framework Version
Current Behavior
When using the
router
object returned fromuseIonRouter
inside auseEffect
, the router must be placed in the dependency array. TheuseIonRouter
hook returns the object un-memoized so the dependency inuseEffect
causes an infinite loop.Expected Behavior
The object returned by
useIonRouter
should be stable to be able to use in dependency arrays.Steps to Reproduce
Run the repro - on the home page click the redirect button. It uses an effect to push to a new route. The router object is required in the dependency array and it causes the maximum update exceeded loop.
Code Reproduction URL
https://github.com/babycourageous/ionic-stable-useIonRouter
Ionic Info
Ionic:
Ionic CLI : 6.18.1 (/Users/renedellefont/.fnm/node-versions/v16.13.1/installation/lib/node_modules/@ionic/cli)
Ionic Framework : @ionic/react 6.0.13
Capacitor:
Capacitor CLI : 3.4.3
@capacitor/android : not installed
@capacitor/core : 3.4.3
@capacitor/ios : not installed
Utility:
cordova-res : not installed globally
native-run : 1.5.0
System:
NodeJS : v16.13.1 (/Users/renedellefont/.fnm/node-versions/v16.13.1/installation/bin/node)
npm : 8.1.2
OS : macOS Big Sur
Additional Information
I locally replaced the
useIonRouter
supplied by Ionic with the following and it fixed the issue. The object returned is wrapped byuseMemo
so that it's a stable reference for any dependency arrays it is included in.The github repro is Ionic 6 but I can confirm the same issue exists in Ionic 5.
Thanks!
The text was updated successfully, but these errors were encountered: