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

Support for different runtimes #199

Open
kvz opened this issue Nov 18, 2024 · 9 comments
Open

Support for different runtimes #199

kvz opened this issue Nov 18, 2024 · 9 comments

Comments

@kvz
Copy link
Member

kvz commented Nov 18, 2024

For example:

And maybe even

  • Browsers
  • React Native

We should then rename the node-sdk to @transloadit/client perhaps. Optionally we can support different runtimes with named exports like import { BunClient } from '@transloadit/client' or similar.

@mifi
Copy link
Collaborator

mifi commented Nov 29, 2024

In order to support all these platforms with upload progress we could either:

Make our own abstraction above fetch and XMLHttpRequest (fetch is needed for Node.js and React Native, XMLHttpRequest is needed for upload progress).

Use a library: The only popular library that I can find that satisfies all of these is the good ol' axios, but it has a relatively large bundle size of 13.7kB gzipped. I tried asking AI but they just hallucinate and also cannot find any libraries other than axios that satisfy all the requirements:

  • upload progress support
  • runs in browsers (xmlhttprequest for upload progress)
  • runs in react native (I believe fetch API)
  • runs in node.js

Alternatively just use fetch, but then the only browser that we would be able to support upload progress in is chrome.

@Acconut
Copy link
Member

Acconut commented Nov 29, 2024

  • upload progress support

It's possible to get upload progress using the Fetch API by jumping through a few hoops: https://x.com/vvoyer/status/1856287377188368449

At some point Fetch will get native support for upload progress, but not soon: whatwg/fetch#607

@mifi
Copy link
Collaborator

mifi commented Nov 29, 2024

It's possible to get upload progress using the Fetch API by jumping through a few hoops: https://x.com/vvoyer/status/1856287377188368449

afaik this is what i mentioned above, that this workaround only works for chrome, and the only alternative that works cross-browser is XMLHttprequest

@Acconut
Copy link
Member

Acconut commented Nov 29, 2024

that this workaround only works for chrome

You're right, thanks! I didn't know this but the tweet also means the lacking support in Firefox and Safari. That's unfortunate. Upload progress is an important components for good user experience and ensuring its always available is also a hassle in tus-js-client.

@mifi
Copy link
Collaborator

mifi commented Nov 29, 2024

Yup. If we want to support all these platforms (or specifically node.js+browser) and support upload progress, I think it boils down to that we have to either:

  1. just use axios, or
  2. make a tiny wrapper around fetch and XMLHttpRequest which supports upload progress, or maybe we can even make a new open source http request library a.la ky that does this, because evidently there's lack of such a library in the npm ecosystem

@mifi
Copy link
Collaborator

mifi commented Nov 29, 2024

Looks like 2 is exactly what Vincent Voier (twitter/vercel) is doing: inspired by axios, he created a tiny wrapper which uses fetch if the client supports upload progress over fetch, then falls back to xhr if not:

@Acconut
Copy link
Member

Acconut commented Nov 29, 2024

  1. just use axios, or

At some point, I tried using Axios to get upload progress, but it didn't work if I passed it the upload data as one big buffer. A workaround would have been to stream the buffer into Axios, but that's more cumbersome.

That being said, I am wondering if upload progress is a concern in the Node SDK itself. Isn't the uploading of files deferred to tus-js-client nowadays? If so, we have to think about upload progress in tus-js-client. That would likely be a similar discussion, but Node SDK could already move to the Fetch API and we just have to figure out how to make tus-js-client compatible with these platforms while still offering upload progress. Does that make sense to you?

@mifi
Copy link
Collaborator

mifi commented Nov 29, 2024

That being said, I am wondering if upload progress is a concern in the Node SDK itself. Isn't the uploading of files deferred to tus-js-client nowadays? If so, we have to think about upload progress in tus-js-client. That would likely be a similar discussion, but Node SDK could already move to the Fetch API and we just have to figure out how to make tus-js-client compatible with these platforms while still offering upload progress. Does that make sense to you?

That's a good point. tus-js-client is being used by node-sdk iff isResumable: true and the value false is deprecated so maybe we should remove it in the next major?

'Parameter value isResumable = false is deprecated. All uploads will be resumable (using TUS) in the future',

like you said, if we remove the option it will allow us to only use tus-js-client for uploads, and thus we can use only fetch because we don't need any upload progress in node-sdk. wdyt @kvz can we remove the deprecated isResumable option in the next major?

@kvz
Copy link
Member Author

kvz commented Nov 29, 2024

Ah great idea to bundle that removal in the next major, just in time!

I think we should also bundle the robot types in the major @remcohaszing, we’re so close 🤞

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

No branches or pull requests

3 participants