Skip to content

Commit

Permalink
fix: bind globalThis.fetch to globalThis (#1242)
Browse files Browse the repository at this point in the history
This makes the assigned fetch behave a bit differently than a regular
`globalThis.fetch`. a globalThis.fetch will sometimes fail if you do
`const me = { fetch }; await me.fetch(url)` but now this bound one won't
and will instead behave differently than `globalThis.fetch`.

I think the difference in behavior doesn't matter too much because we
just use the assigned fetch right away without passing it along or
calling it in such a way that we'd change the default behavior of
function calling where `this` is `globalThis` in a way that all `fetch`
i've encountered can work with.
  • Loading branch information
gobengo authored Dec 13, 2023
1 parent 86aedbc commit ef59358
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/upload-client/src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ export async function add(
const responseAddUpload = result.out.ok

const fetchWithUploadProgress =
options.fetchWithUploadProgress || options.fetch || globalThis.fetch
options.fetchWithUploadProgress ||
options.fetch ||
globalThis.fetch.bind(globalThis)

let fetchDidCallUploadProgressCb = false
const res = await retry(
Expand Down

0 comments on commit ef59358

Please sign in to comment.