-
-
Notifications
You must be signed in to change notification settings - Fork 72
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
Failed request to load remote resources aborts future reloads #147
Comments
Try with i18next-http-backend v2.6.0 and i18next v23.14.0 |
@adrai Thanks for the fix, will give it a try tomorrow and let you know 🙏 |
Hey @adrai, the new versions did not fix the problem unfortunately. There are is no request made for the reloadResources |
I just checked this twice and it seemed to work. |
Hi @adrai here is a sample repo Try running the app, and you will that the first time it will fail because the url is wrong and then the url is fixed but no request is made and there are logs about a failed/success request. And the key is still untranslated. If you fix the url from the beginning, both requests are logged and translations are there |
You can't just change the loadPath like that... it will not use the new url...
|
Hi @adrai, Didnt know that is not the correct way. I did that in the sample when I created the issue and didnt receive this feedback. Anyway I updated repo and you can pull the changes and test that it still doesnt work. Note that this is not what I do in production. This is simply a reproducible example to simulate the issue I am seeing in my react native app. |
2 points:
const i18next = require("i18next");
const HttpBackend = require("i18next-http-backend");
let loadPath = "https://WRONGjsonplaceholder.typicode.com/posts/1";
i18next
.use(HttpBackend)
.init({
backend: {
loadPath: loadPath,
customHeaders: {
"Cache-Control": "no-cache",
Pragma: "no-cache",
Expires: "0",
},
parse(data, languages, namespaces) {
console.log("languages", languages);
console.log("namespaces", namespaces);
return JSON.parse(data);
},
},
lng: "en",
fallbackLng: "en",
defaultNS: "translation",
ns: ["translation"],
debug: true,
})
.then(() => {
console.log(i18next.t("userId"));
console.log(i18next.t("title"));
// HACK: these 2 options needs to be overwritten, if the i18next instance is init() is not called again
i18next.options.backend.loadPath = "https://jsonplaceholder.typicode.com/posts/1";
i18next.services.backendConnector.backend.options.loadPath = i18next.options.backend.loadPath;
setTimeout(() => {
console.log("will reload");
i18next.reloadResources().then(() => {
console.log(i18next.t("userId"));
console.log(i18next.t("title"));
console.log("reloaded");
});
}, 1000);
}); |
Hey @adrai Alright I guess my reproducible isnt 100% accurate because it returns 404 while my actual error is when there is no internet My guess is that:In here i18next-http-backend/lib/index.js Line 77 in 541b257
If there was no response, you check for a specific error message, which I believe is the bug? To further check it yourself:I created a repo that is exactly the case I encounter. If you dont know how to run an expo react native app then expand this
Here is the normal case when user has internet: Screen.Recording.2024-08-21.at.9.mp4console logs
Now here is the case where I start offline and then go online: Screen.Recording.2024-08-21.at.9.1.mp4console logs:
|
did not try, but can you check if v2.6.1 works? |
Yes, it does. Thank you! Closing |
This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [i18next-http-backend](https://github.com/i18next/i18next-http-backend) | dependencies | minor | [`2.5.2` -> `2.6.1`](https://renovatebot.com/diffs/npm/i18next-http-backend/2.5.2/2.6.1) | --- ### Release Notes <details> <summary>i18next/i18next-http-backend (i18next-http-backend)</summary> ### [`v2.6.1`](https://github.com/i18next/i18next-http-backend/blob/HEAD/CHANGELOG.md#261) [Compare Source](i18next/i18next-http-backend@v2.6.0...v2.6.1) - optimize "Failed to fetch" retry case [147](i18next/i18next-http-backend#147) ### [`v2.6.0`](https://github.com/i18next/i18next-http-backend/blob/HEAD/CHANGELOG.md#260) [Compare Source](i18next/i18next-http-backend@v2.5.2...v2.6.0) - fix "Failed to fetch" retry case [147](i18next/i18next-http-backend#147) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOC40MC4wIiwidXBkYXRlZEluVmVyIjoiMzguODYuMCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiZGVwZW5kZW5jaWVzIl19--> Reviewed-on: https://git.tristess.app/alexandresoro/ouca/pulls/44 Reviewed-by: Alexandre Soro <[email protected]> Co-authored-by: renovate <[email protected]> Co-committed-by: renovate <[email protected]>
This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [i18next](https://www.i18next.com) ([source](https://github.com/i18next/i18next)) | dependencies | minor | [`23.13.0` -> `23.15.2`](https://renovatebot.com/diffs/npm/i18next/23.13.0/23.15.2) | --- ### Release Notes <details> <summary>i18next/i18next (i18next)</summary> ### [`v23.15.2`](https://github.com/i18next/i18next/blob/HEAD/CHANGELOG.md#23152) [Compare Source](i18next/i18next@v23.15.1...v23.15.2) - fix(types): make context related keys detection stricter [2243](i18next/i18next#2243) fixes [2242](i18next/i18next#2242) ### [`v23.15.1`](https://github.com/i18next/i18next/blob/HEAD/CHANGELOG.md#23151) [Compare Source](i18next/i18next@v23.15.0...v23.15.1) - types(TFunction): make return not inferrable and use defaultValue as return when provided [2234](i18next/i18next#2234) ### [`v23.15.0`](https://github.com/i18next/i18next/blob/HEAD/CHANGELOG.md#23150) [Compare Source](i18next/i18next@v23.14.0...v23.15.0) - support unescaped variables in TypeScript [2233](i18next/i18next#2233) ### [`v23.14.0`](https://github.com/i18next/i18next/blob/HEAD/CHANGELOG.md#23140) [Compare Source](i18next/i18next@v23.13.0...v23.14.0) - If backend errors with retry flag, set internal state to 0, so reloadingResources should work [147](i18next/i18next-http-backend#147) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOC40MC4wIiwidXBkYXRlZEluVmVyIjoiMzguMTEwLjIiLCJ0YXJnZXRCcmFuY2giOiJtYWluIiwibGFiZWxzIjpbImRlcGVuZGVuY2llcyJdfQ==--> Reviewed-on: https://git.tristess.app/alexandresoro/ouca/pulls/43 Reviewed-by: Alexandre Soro <[email protected]> Co-authored-by: renovate <[email protected]> Co-committed-by: renovate <[email protected]>
🐛 Bug Report
I am loading my translation resources using a backend. The issue is that if a request fails for some reason then subsequent requests are not attempted even if they were to succeed.
Use case in real case scenario: I have a react native app that loads resources from the backend. It is possible that user opens the app and translations are loaded while he is offline, which leads to a failed request. I reload resourced using
i18next.reloadResources()
at certain points to make sure translations are up to date, however reloading resources no longer makes a request, which is the bug.There is a similar issue #142 that was opened but it did not really fix this behavior
To Reproduce
If you run this, you will see in debug logs that there was an error because of the wrong url but later on the url was corrected but no request is attempted. Of course you need to pass in actual urls, these are placeholders
Expected behavior
I expect that every time
reloadResources
is called then a request is made to the backend, and not that subsequent failed requests not go throughYour Environment
The text was updated successfully, but these errors were encountered: