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

Add fetch to RequestEvent #7113

Merged
merged 10 commits into from Oct 4, 2022
Merged

Add fetch to RequestEvent #7113

merged 10 commits into from Oct 4, 2022

Conversation

Rich-Harris
Copy link
Member

@Rich-Harris Rich-Harris commented Oct 1, 2022

Closes #6320. This moves SvelteKit's fetch wrapper to RequestEvent so that it can be used by server-only load functions and +server.js handlers as well as shared load functions. (It can even be used in handle, or — somewhat pointlessly — inside handleFetch, as a consequence of where it now lives.)

Marking as draft because we're no longer using (or able to use) GENERIC_ERROR, and I'm not quite sure what the consequences of that are just yet.

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. All changesets should be patch until SvelteKit 1.0

@changeset-bot
Copy link

changeset-bot bot commented Oct 1, 2022

🦋 Changeset detected

Latest commit: cc74f19

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Conduitry
Copy link
Member

Will the fetch that's passed to handleFetch now be identical to the event.fetch that's passed? It'd be a breaking change, but would this be a reason to stop passing fetch to keep things tidy?

@Rich-Harris
Copy link
Member Author

Will the fetch that's passed to handleFetch now be identical to the event.fetch that's passed?

No. event.fetch invokes handleFetch({ event, request, fetch }); if the fetch argument was equivalent to event.fetch then it would call handleFetch({ event, request, fetch }), and you'd keep going round in circles.

Co-authored-by: repsac <repsac-by@users.noreply.github.com>
@Conduitry
Copy link
Member

I'm not sure where best to document this, but I do think we're probably overdue for a little bit of an explanation somewhere about how the different instances of fetch interact. I don't think it's enough to just add fetch as a method to the RequestEvent type. There are a number of nuances about browser vs server behavior, and about credential handling, and about calling handle instead of making a network request for same-origin fetches, etc. etc.

@Rich-Harris
Copy link
Member Author

Agree, it could be clearer. Do you think that blocks this PR, or are we good to merge it in the meantime? #7087 is blocked on this one (though there is some discussion in that issue about rethinking docs as well)

@Conduitry
Copy link
Member

@Rich-Harris Nope, I'm fine foregoing docs updates for now if we're going to be rethinking these docs in the context for #7087 anyway.

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.

Add fetch method to ServerLoadEvent similar to LoadEvent to address same issues
3 participants