-
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
fix(react): export stable router reference for useIonRouter
hook
#25000
fix(react): export stable router reference for useIonRouter
hook
#25000
Conversation
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
cool 👍 My current workaround is to destructure result const { canGoBack } = useIonRouter()
useEffect(() => {
// ...
}, [canGoBack]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies for the delay around reviewing this PR. Had one suggested change and a question around the list of properties used.
Also, is there anyway we can write test around this behavior so that this does not regress in the future?
For example, could we re-create the failing test case in the reproduction app and write an E2E test that validates some level of functional behavior (no error, etc.)? I can help with this portion if you are unfamiliar with our testing suite.
Thanks @sean-perkins ! I let this slip off the radar. I was having some trouble with my fork so really appreciate you making this commit. Sorry again! I did notice |
@babycourageous no worries, thanks for the contribution! Both |
ah yes - i missed that detail. You're spot on! |
Merged. Thank you very much for the contribution! |
@liamdebeasi You're welcome! Thanks for having me and I hope to keep on contributing! |
Just experienced this for the first time yesterday. Nice to see this bug fix! |
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 #24987
Pull request checklist
Please check if your PR fulfills the following requirements:
npm run build
) was run locally and any changes were pushednpm run lint
) has passed locally and any fixes were made for failuresPull request type
Please check the type of change your PR introduces:
What is the current behavior?
Putting the router object exported by
useIonRouter
in dependency array ofuseEffect
causes maximum update depth exceeded due to it being unstable reference.Issue URL: #24987
What is the new behavior?
Wrap router object returned by
useIonRouter
inuseMemo
.Does this introduce a breaking change?
Other information