i18next: Reinitializing was working in version 19.8.7 but started breaking after 19.8.8
💥 Regression Report
As per our requirements we had to use a single instance of i18next through out the application. Within the application we are loading a base component library which works in a standalone mode (for culture) during development. Once developed this library is packaged and published on NPM. Within the application we are installing base components via NPM. Since base components are not bundled they point towards similar instance of i18next as the consumer. Due to incorrect loading sequence even if the base component initializes the i18next instance we want it to be reinitialize by the consumer (application) which would be finally responsible for pulling resources for the loaded base components in production.
I just saw the docs stating we shouldn’t ideally called init function twice, but as per our use case its essential for us to recall the init function so that even if the base component initializes the package, it is re initialized by the consumer. Ref: https://www.i18next.com/overview/api
This was working as expected till version 19.8.7 but in 19.8.8 something broke this behaviour, I tried going through the tags but couldn’t found something that would have broken the flow.
Kindly help us to resolve above issue. Looking forward to your reply
Last working version
Worked up to version: 19.8.7
Stopped working in version: 19.8.8
To Reproduce
Steps to reproduce the behavior:
Try calling init method twice for switching lng and resources, (Although this can be changed via other API as well, its important for us to have a completely fresh instance)
instance = i18next.createInstance()
coreInit = (options) => {
instance.init(options)
}
Expected behavior
Should be able reinitialize the package without any side effects
// Paste the results here
Your Environment
- runtime version: i.e. node v14
- i18next version: i.e. 19.8.8
- os: Windows
- any other relevant information
Ref: https://github.com/i18next/i18next/compare/v19.8.7...v19.8.8
I guess due to above change lng is not changing
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 1
- Comments: 19 (9 by maintainers)
Links to this issue
Commits related to this issue
- try to fix another edge case issue #1570 introduces by fixing #1552 — committed to i18next/i18next by adrai 3 years ago
- try to fix another edge case issue #1570 introduces by fixing #1552 — committed to plindse/i18next by adrai 3 years ago
- try to fix another edge case issue #1570 introduces by fixing #1552 — committed to plindse/i18next by adrai 3 years ago
- [F-1569] Add key name to format function as optional parameter (#1571) * try to fix another edge case issue #1570 introduces by fixing #1552 * [F-1569] Add key name to format function as optional ... — committed to i18next/i18next by plindse 3 years ago
@akshayr-tavisca One of those moments, where fixing one issue triggers the other one… Can you try with v19.9.2 ?
@adrai
19.9.2
looks to be working for us too, thanks for the quick fix 😄If you like this module don’t forget to star this repo. Make a tweet, share the word or have a look at our https://locize.com to support the devs of this project.
There are many ways to help this project 🙏
It worked on 19.9.2, thank you for the quick help @adrai
We’ve been experiencing a similar issue for the past 2-3 weeks in our projects but were unable to find the culprit. After seeing this thread, I looked at our
node_modules
and noticed thatv19.9.1
was being used. I degraded the version tov19.8.7
for a quick test and it actually does help.In our case the issue can be reproduced by simply logging in, the translations are just not there. However if the server is restarted while the user is logged in and the user refreshes the page, the translations will be there (until the user relogs).
The init function is here: https://github.com/SoftwareBrothers/admin-bro/blob/master/src/admin-bro.ts#L107 We check if i18n is already initialized in case it’s defined before in user’s own code. However, when reproducing this it goes into
else
.Will check if we can do another special check… will let you know asap