Skip to content
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

Provide AbortController implementation for load({ fetch }) #4866

Closed
furudean opened this issue May 10, 2022 · 4 comments
Closed

Provide AbortController implementation for load({ fetch }) #4866

furudean opened this issue May 10, 2022 · 4 comments
Labels
feature request New feature or request
Milestone

Comments

@furudean
Copy link
Contributor

furudean commented May 10, 2022

Describe the problem

The preferred way to set up timeouts with fetch is to use AbortController. This is a browser API that does not exist in most supported node versions (or other environments) and requires a user provided polyfill to work correctly. abort-controller is what node-fetch suggests as a solution.

The user has to handle both the browser and ssr rendering cases with something like:

const AbortController = globalThis.AbortController || await import('abort-controller')

This is awkward, and I think it's in the spirit of Svelte Kit to help out with this.

Describe the proposed solution

Expose a polyfilled AbortController implementation as a parameter like we did with fetch, i.e. load({ fetch, AbortController }), or as a global.

Alternatives considered

Bring your own polyfill and set up logic yourself.

Importance

would make my life easier

Additional Information

No response

@Rich-Harris Rich-Harris added the feature request New feature or request label May 11, 2022
@Rich-Harris Rich-Harris added this to the 1.0 milestone May 11, 2022
@Rich-Harris
Copy link
Member

Yeah, agree with this. Now that WinterCG exists, we could look to this document for guidance on which APIs should be available. install-fetch probably needs to become something like install-runtime (and maybe we need to have different versions of it for different Node versions, since future versions of Node will include more of this stuff).

@Rich-Harris
Copy link
Member

Actually, looking at https://developer.mozilla.org/en-US/docs/Web/API/AbortController#browser_compatibility, AbortController is supported in Node in versions 15 and above. As of #4922, SvelteKit only supports Node 16 and above, which means we can guarantee that AbortController is present - no polyfills needed.

@furudean
Copy link
Contributor Author

What about other environments?

@abdo643-HULK
Copy link

What about other environments?

Deno and cloudflare have out of the box support and all other environments officially supported by the sveltekit team run on aws lambda which gets defaulted into using Node 16.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants