-
-
Notifications
You must be signed in to change notification settings - Fork 764
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
Navigating between pages with or without translations causes _app remounts #1075
Comments
I believe this is fixed by #1064 – @skrivanos can you confirm? |
@isaachinman My PR won't fix this. I believe it's caused by this snippet: It creates a different instance of the WrappedComponent (i.e. app) depending on if there's an i18n instance or not, and there won't be an instance if serverSideTranslations are not used. #1049 is related and would probably fix this. Also related: the key is set to the locale, making the app also unmount and mount on locale changes. Is there a good reason for setting the key? |
Thanks for pointing @skrivanos. The conditional rendering and the I have patched the package on my local machine to test and removing the conditional rendering does not fix the issue. So I tried removing the I was surprised because the example repo I linked in the description does not do any locale switch at any point, so I added a few logs around to find out what's up. It turns out that when navigating to the home page (the one that is not using I tried then adding some links that would switch the locale to Now, I don't know the side effects removing these two things could have as I don't know why there are there in the first place. From a fresh point of view, I would say that the conditional rendering can surely be removed. For the #1049 is kind of related indeed, but much more niche. There we are talking about fallback rendering, which is a quite small portion of the usage (static + static paths + fallback true). Here, it's any page that doesn't use i18n in your app. Click to see my diff
|
It's necessary to force the app to re-render, although we may be able to remove that based on some of your proposed changes, @skrivanos. @enzoferey What is your use case for translating some pages and not others? I'm open to any reasonable PR that might solve your issue, but do regard it as an edge case. |
@isaachinman My usage is about embedding pages from outside Next.js inside by page. As those pages will already come with i18n built-in, I want to wrap them in my Next.js applications but I don't need any translations from You can certainly hack your way around requesting empty namespaces or no namespaces at all, I haven't tried those solutions, they might work. I just think that as a user you don't expect that the fact of not using an add-on will break Next.js architecture principles like rerendering the |
As I said, PRs welcome! |
In our case our header disappears when we switch locales, until we refresh the page. We think it's related to this bug. |
Hi all, We met this issue too. We want to use next-auth and next-i18next in our nextjs project. Here is a simple example which I combined the example of next-auth and the example of next-i18next. When navigating between pages with or without translations, the session of next-auth would be undefined until you manually refresh the page. I think it's related to the remounts of _app. |
next-auth-i18n-bug.mp4attach repro video here |
In our app all pages have translations, but even though, changing from default locale
Update:
As long as there's no return i18n !== null ? (
<I18nextProvider i18n={i18n}>
<WrappedComponent {...props} />
</I18nextProvider>
) : (
<WrappedComponent {...props} />
); |
We are in the same situation as yours, we are doing next-auth GitHub authentication and use next-i18next for French and English. Also tried with a simple repo similar to yours to the same avail.
|
I have same issue. |
Any update on that? |
Created a new component: Trans.tsx
_app.tsx
Seems to work fine |
@jln13x Sure, you are reiterating the same approach I've relayed to similar questions many times. Most recent example is: #1710 (comment). |
Fixed by #1631 |
it took me a day to find this weird bug :) |
@thienna This issue is fixed in latest versions. Please let me know if you can reproduce after upgrading. |
i still face this issue :( my config: const path = require('path')
module.exports = {
i18n: {
defaultLocale: 'en',
locales: ['en', 'vi'],
},
localePath: path.resolve('./src/i18n/locales'),
} in page A: ...(await serverSideTranslations(ctx.locale || 'en', ['common'])), in page B (target route): |
Please open a new issue, with a minimum reproducible repository linked. |
i have edit my words |
@isaachinman, this problem still happens. I'm using |
@ciceropablo Can you provide a minimal reproducible repo? |
Describe the bug
When navigating from a static page that is using
serverSideTranslations
to a page that is not using it (or the other way around), the_app
remounts. This leads to unexpected behaviour as the_app
is generally used to setup context providers or run one time browser-only initializations.Occurs in next-i18next version
Version:
^8.1.2
Steps to reproduce
yarn dev
._app
mount and unmount.Expected behaviour
You will see that navigating from the home page (no
serverSideTranslations
usage) to the other pages (serverSideTranslations
usage) the_app
remounts, however when navigating between the signup and about pages (both useserverSideTranslations
), the_app
doesn't remount as expected.Screenshots
OS (please complete the following information)
Notes
I'm quite sure there is something wrong around the
appWithTranslation
HOC. I do see that we are rendering different things based on locale existence and that could cause a whole remount, but I don't know Nextjs i18n routing internal props well enough to hint for a solution. It might actually be an expected behaviour on your side by design of the solution, I don't know.The text was updated successfully, but these errors were encountered: