i18next / i18next-http-backend

i18next-http-backend is a backend layer for i18next using in Node.js, in the browser and for Deno.
MIT License
452 stars 70 forks source link

BREAKING CHANGE: drop support for XMLHttpRequest and remove cross-fetch #144

Open talentlessguy opened 4 months ago

talentlessguy commented 4 months ago

This PR removes support for XMLHttpRequest as it is not used widely anymore for fetching things. Fetch API no longer requires a polyfill on Node.js, and is supported by all major browsers and runtimes.

See compatibility table: https://developer.mozilla.org/en-US/docs/Web/API/fetch#browser_compatibility and: https://caniuse.com/fetch

For environments that don't support fetch (such as IE11) - they should install a fetch polyfill in their projects.

It also removes dependency on cross-fetch as it is not needed anymore. Node.js supports fetch natively since 18.x. I've added an engines.node field to notify that minimum node 18 is required.

Since it's a breaking change, in my opinion a semver major bump is required.

Checklist

Checklist (for documentation change)

adrai commented 4 months ago

XMLHttpRequest is only used as fallback... if no fetch is available... Also cross-fetch is only used if fetch is not available... At runtime there should be no difference on modern environments of having or not having the XMLHttpRequest and/or cross-fetch "logic" in i18next-http-backend or not... So what hurts in keeping i18next-http-backend like is it now for a longer while?

talentlessguy commented 4 months ago

@adrai unnecessary code being downloaded by browsers and package managers. Other packages might also import cross-fetch but with another version, resulting in dependency duplication.

adrai commented 4 months ago

Do you have an actual issue with the current i18next-http-backend version? Do you need to have this merged soon? Because of what?

talentlessguy commented 4 months ago

@adrai there's no urgency of it getting merged, I just submitted a PR as a general ecosystem cleanup. That's done so that modern environments aren't slowed down by unnecessary polyfills.

adrai commented 4 months ago

My concern is, I know there are users out there having still the need for this fallbacks... if I merge this now, there risk is high there will be more github issues, etc... asking for bringing back support etc... Would you be ready to respond to those github issues?

adrai commented 4 months ago

@adrai there's no urgency of it getting merged, I just submitted a PR as a general ecosystem cleanup. That's done so that modern environments aren't slowed down by unnecessary polyfills.

ok, then let's keep this PR open for a while...

talentlessguy commented 4 months ago

@adrai

1) in case of fallbacks, they should pin a version to the previous major. This is very simple, just doing a ^major... works. Stuff might break only if it's imported without specifying a version, which is a risk of it's own anyway. Any further bugfixes can be backported to previous major if needed, in case there's an urgent security bug. 2) I labeled it as "BREAKING CHANGE" specifically for preserving compat, so that other projects who don't need all these fallbacks and polyfills (which are the majoeity) don't have to download/pull the code. 3) yes, I'm ready to fix it if there's any issues arising with it.

adrai commented 4 months ago

will come back to this in 6-7 months...

talentlessguy commented 4 months ago

@adrai thanks for reaching out and taking time to look at the PR! I'll ping in 6 months in case of anything

adrai commented 1 day ago

fyi: a new version has been released that addresses an issue with Deno 2... With this change, the getFetch.cjs is not necessary anymore and I rechecked this PR again... I asked some devs I know are still using Node.js 16 and other environments like Electron etc... It would be better if we keep the support for them for a while. Beside that if we would also drop the XMLHttpRequest support, there would be no real difference to the i18next-fetch-backend module.

biast12 commented 1 day ago

Mmmm so i just tried that update..... it completely crashes my app The error:


[vite] X [ERROR] Top-level await is not available in the configured target environment ("chrome87", "edge88", "es2020", "firefox78", "safari14" + 2 overrides)
[vite]     node_modules/i18next-http-backend/esm/request.js:37:16:
[vite]       37 │     fetchApi = (await import('cross-fetch')).default;
[vite]          ╵                 ~~~~~
[vite] 19.35.11 [vite] error while updating dependencies:
[vite] Error: Build failed with 1 error:
[vite] node_modules/i18next-http-backend/esm/request.js:37:16: ERROR: Top-level await is not available in the configured target environment ("chrome87", "edge88", "es2020", "firefox78", "safari14" + 2 overrides)
[vite]     at failureErrorWithLog (C:\Path\to\the\app\node_modules\esbuild\lib\main.js:1651:15)
[vite]     at C:\Path\to\the\app\node_modules\esbuild\lib\main.js:1059:25
[vite]     at C:\Path\to\the\app\node_modules\esbuild\lib\main.js:1527:9
[vite]     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
adrai commented 1 day ago
image

fyi: https://github.com/i18next/i18next-http-backend/issues/158

razor-1 commented 1 day ago

It would be nice for this to have been a major version change, since it's breaking (even though the fix is trivial). But thank you for making it easy to find and resolve.

adrai commented 1 day ago

It would be nice for this to have been a major version change, since it's breaking (even though the fix is trivial). But thank you for making it easy to find and resolve.

I did not know before releasing, the default vite settings has problems with that. That's why I did not a major bump.

adrai commented 1 day ago

v2.7.0 has now been deprecated and v3.0.0 was released

smman89 commented 1 day ago

v2.7.0 has now been deprecated and v3.0.0 was released

This didn't solve the problem

adrai commented 1 day ago

v2.7.0 has now been deprecated and v3.0.0 was released

This didn't solve the problem

@smman89 have you read the changelog?

fix for Deno 2 and removal of unnecessary .cjs file
for esm build environments not supporting top-level await, you should import the i18next-http-backend/cjs export or stay at v2.6.2

for vite https://github.com/i18next/i18next-http-backend/issues/158#issuecomment-2488663775:

Have you tried to adapt the config? https://stackoverflow.com/questions/72618944/get-error-to-build-my-project-in-vite-top-level-await-is-not-available-in-the

that should do the trick:

image

https://github.com/i18next/i18next-http-backend/issues/158#issuecomment-2488690194 Alternatively, change your import like this: import backend from 'i18next-http-backend/cjs'

adrai commented 23 hours ago

v3.0.1 tries to remove the top-level await