Fix multiple changeLanguage calls may resolve to a wrong language#2298
Conversation
8886908 to
f4e4474
Compare
|
this PR will increase the package by approx. 3kb... this will undo all our efforts at v24 to reduce the bundle size... fyi: @VIKTORVAV99 |
|
@adrai Oh, you are right, this is indeed much simpler, and the test case still passed. |
f4e4474 to
94e4e7b
Compare
|
I think the new option is not necessary. Please remove it. |
|
But it may introducing breaking changes. If someone relies on the old behavior, their code might stop working after the upgrade. And another concern is here Lines 348 to 354 in 94e4e7b The |
|
The old behaviour is not reliable by itself... so this does not matter. |
|
I still feel that it is a bit too hasty to change it directly, after all, this problem has existed for so long. Lots of project already adopted with i18next's old behaviour. |
|
The old wrong behaviour occurs only if the changeLanguage is used in a wrong way. So this is a fix after all... But if you think this is breaking we will release a new major release... no problem. But I don't like to introduce a new option because of a "bug" or "wrong usage" behaviour. |
feel free to optimize this... an alternative to a "reject" could be also an additional parameter that illustrates that a subsequent changeLanguage call has "overwritten" this one... btw: this is even better in my opinion: And since we can make a major release, we can just keep it like that (no reject, etc...) and document this new behaviour in the changelog and in the migration guide. |
|
Make sense to me, I'll look into this a bit later. |
94e4e7b to
6617013
Compare
|
I was thinking if we could optimize the changeLanguage function. It seems to involve three things: detect the language using a detector if language not provided, normalize the detected language, and load the language resources then set the related state. Maybe we can separate these steps to make the process clearer. I created a new branch for this idea, if it looks good, I'll create a new PR for it. |
Not sure if I like the idea - changeLanguage does no detection with that change -> leads to a breaking version for no real benefit. Also adding |
It's ok if |
|
I also don't like that change... For example, there are scenarios out there, where there is a lng passed via options but also a language detector... |
|
Sure, we can discuss more on that later. 😄 |
|
included in v25 |


Fix #1605
Checklist
npm run testChecklist (for documentation change)