-
-
Notifications
You must be signed in to change notification settings - Fork 762
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
refactor: reuse existing instance #2226
Conversation
Can you please provide a minimal example repo I can use to verify the issue first? |
While creating reproduction, I found that when using suspense in layout component(located in _app, higher than page level), the issue is always reproduced. Please see https://github.com/wjaykim/next-i18next-infinite-suspense for reproduction, and also I added Also I think maybe #2095 is caused by this. |
I accidentally closed PR. |
The question I have is why do you want to prevent it from being rendered on the server? |
I don't want to add
What do you mean? It doesn't works, actually.. |
But why do you set useSuspense to true? |
btw: using your "fixed" version in this example you can see the language change does not work properly anymore: https://github.com/i18next/next-i18next/tree/master/examples/simple |
Didn't know that at first, but if this change can make next-i18next be compatible with Suspense, why shouldn't we apply this fix?
I didn't know that, so updated code (adding |
Yes that's right. I want you to check if my change doesn't change any existing behavior, and I'm willing to make this PR perfect so it can be merged because suspense is really fascinating feature to me. To find out this PR has no problem, what's the best way to prove it? Running official examples of this repo? |
Yes, exactly the examples of this repo are the minimum, and afterwards also this example: https://github.com/i18next/i18next-http-backend/tree/master/example/next |
not good yet.... (this happens when navigating between pages) the addResourceBundle call is done too late... the t function is already called before that... maybe move it here: https://github.com/i18next/next-i18next/pull/2226/files#diff-dc78a43079a28bdd9c1d6b6edb580f0131b8627926f905054069b15470bd6553R73 ? |
Right.. I'll reach you after find more good way and when all tests passed (including e2e) |
Latest code passes all tests including e2e in local. Can you take a look? |
looks good |
I hope this does not influence some other edge case usage.... |
Yes, if we concern more about stability, we can make the code works same as before for default, and add option to reuse instance optionally. |
67149ea
to
29f860f
Compare
but only if issues arise |
Thank you very much for your contribution. |
This PR changes how next-i18next loads resources on page or locale change.
Instead of creating a new instance on page or locale change, the change uses
addResourceBundle
method to load newly changed resources if instance was already created.I made this change because I found an edge-case:
getStaticProps
andserverSideTranslations
configured.serverSideTranslations
, instead load translations in client-side with i18next-http-backend;Also I used
suspense
option totrue
useTranslation
hook got suspended, and it suspends forever because i18next instance is created repeatedly, thus not initialized forever.After applying this patch, the infinite suspending issue was removed.
Checklist
npm run test