-
-
Notifications
You must be signed in to change notification settings - Fork 763
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: better support for shallow route changes #1064
fix: better support for shallow route changes #1064
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/isaachinman/next-i18next/3bChh7HvMWM93jXnVYUbidpHSgRL |
Reckon examples/simple/pages/index.ts should be changed to use shallow routing for the change locale button? |
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.
In general, these type of changes make me a little nervous, as it seems like even though it might fix shallow routing, it may also cause other issues.
Would something like this work as well? I'm not sure I'm keen on memoising the entire client.
Let me know your thoughts!
I can understand that. But no, that fix alone would not help (and it's also baked into this PR). One of the problems is that creating a new instance causes two re-renders of memoized components on every shallow route change, leading to extremely poor performance. |
Sorry for a delayed response. Happy to keep this PR moving and get it merged in. |
a998fc1
to
aa6320f
Compare
aa6320f
to
5a51c28
Compare
@isaachinman Noticed a slight hiccup when using this branch in our real application: switching the locale with a shallow route change will not load resources for the new language, because serverSideTranslations aren't re-run (expected). However, this cannot be fixed by including the HTTP backend either because it will not fetch missing resources if the The question is whether this should be solved in the context of this PR or not. Perhaps the scope of the PR should simply be changed (i.e. change commit message and rename it) to only cover #1059 rather than #1023 as well. Edit: |
@skrivanos Do you have an example use case for switching the locale and wanting shallow routing at the same time? That seems like somewhat of an edge case to me. |
@isaachinman No, I don't and I agree that it's an edge case. Although it might be considered unexpected that it doesn't work, but could perhaps just mention in the README. |
Cool, then I agree it should be handled in a separate PR (if at all). |
In general, we should be able to cease passing |
Yes, I believe so. I can update the PR to remove it, just very short on time lately. |
Cool, no worries – I know the feeling. |
Hey both, just to confirm that initialLocale is safe to remove from the props returned by serverSideTranslations. Ive changed it in my PR too so once we're good to merge this I'll rebase and pull apart mine. |
5a51c28
to
5ca42f9
Compare
@isaachinman @DanPurdy finally had time to updated the MR now - I opted to exclude #1023 since this does not solve it completely. |
@skrivanos Can you rebase against latest? This PR is my top priority and would love to get it in ASAP. |
* Memoize the i18n client and do not re-create it unless the route or locale has changed. * Let Next's router locale take precedence over initialLocale. [fix i18next#1059]
eae0751
to
181a43a
Compare
@isaachinman Done! |
@skrivanos @DanPurdy This PR has caused #1484. Any objections to leaving the memoisation, but removing the |
@isaachinman Won't have time to dive into this again soon unfortunately since I'm a bit overcrowded with work at the moment. I can't quite remember why I changed it to use router.locale but there has to be a reason. |
Memoize the i18n client and do not re-create it unless the route or
locale has changed (fix Re-renders of memoized components on shallow route changes #1059).
Let Next's router locale take precedence over initialLocale.