Skip to content

fix(docs): update custom fetch example #329

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

Merged
merged 1 commit into from
Dec 16, 2021
Merged

fix(docs): update custom fetch example #329

merged 1 commit into from
Dec 16, 2021

Conversation

jacobwgillespie
Copy link
Contributor

@jacobwgillespie jacobwgillespie commented Dec 16, 2021

What kind of change does this PR introduce?

This updates the documentation example of providing a custom fetch implementation (introduced in #297). While the previous example was conceptually correct, in most environments it's not possible to assign a native built-in function like fetch to an object, as calling it later will attempt to call the native function in the context of the object and throw an illegal invocation error.

Creating a new fetch function by binding to the global scope, for instance fetch.bind(global) in Node or fetch.bind(self) in Cloudflare Workers, fixes this issue, but creating a new arrow function is the most univerally functional example since it doesn't require you to know if global is defined or not, so this PR uses that as an example:

{
  fetch: (...args) => fetch(...args),
}

Additional context

This is followup to #297.

@jacobwgillespie jacobwgillespie changed the title Update custom fetch example fix(docs): update custom fetch example Dec 16, 2021
@soedirgo soedirgo merged commit abec733 into supabase:master Dec 16, 2021
@jacobwgillespie jacobwgillespie deleted the patch-1 branch December 16, 2021 17:32
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

Successfully merging this pull request may close these issues.

2 participants