i18next-http-backend icon indicating copy to clipboard operation
i18next-http-backend copied to clipboard

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

Open v1rtl opened this issue 1 year ago • 9 comments

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

  • [x] only relevant code is changed (make a diff before you submit the PR)
  • [x] run tests npm run test
  • [x] tests are included
  • [x] commit message and code follows the Developer's Certification of Origin

Checklist (for documentation change)

  • [ ] only relevant documentation part is changed (make a diff before you submit the PR)
  • [ ] motivation/reason is provided
  • [ ] commit message and code follows the Developer's Certification of Origin

v1rtl avatar Jun 28 '24 18:06 v1rtl

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?

adrai avatar Jun 28 '24 18:06 adrai

@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.

v1rtl avatar Jun 28 '24 19:06 v1rtl

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

adrai avatar Jun 28 '24 19:06 adrai

@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.

v1rtl avatar Jun 28 '24 19:06 v1rtl

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 avatar Jun 28 '24 19:06 adrai

@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...

adrai avatar Jun 28 '24 19:06 adrai

@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.

v1rtl avatar Jun 28 '24 19:06 v1rtl

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

adrai avatar Jun 28 '24 19:06 adrai

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

v1rtl avatar Jun 28 '24 19:06 v1rtl

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.

adrai avatar Nov 20 '24 13:11 adrai

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)

biast12 avatar Nov 20 '24 18:11 biast12

image

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

adrai avatar Nov 20 '24 18:11 adrai

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.

razor-1 avatar Nov 20 '24 23:11 razor-1

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 avatar Nov 21 '24 06:11 adrai

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

adrai avatar Nov 21 '24 08:11 adrai

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

This didn't solve the problem

smman89 avatar Nov 21 '24 08:11 smman89

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 avatar Nov 21 '24 08:11 adrai

v3.0.1 tries to remove the top-level await

adrai avatar Nov 21 '24 10:11 adrai

why was this PR closed?

v1rtl avatar Nov 25 '24 22:11 v1rtl

why was this PR closed?

because of this tldr; we will not remove cross-fetch and XMLHttpRequest for now, if you only want to use the in-built native fetch, use i18next-fetch-backend

adrai avatar Nov 25 '24 22:11 adrai