replace externalFetch with handleFetch - #6565
Conversation
🦋 Changeset detectedLatest commit: ecf3ecb The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
✅ Deploy Preview for kit-demo ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
|
Do you think it makes sense to call out the cookie sibling subdomain thing explicitly in the docs? Can we do that without it being too confusing? We've heard from a few people that it took then a while to even understand why their app wasn't working, so this might also be a good opportunity to tell people how the default conservative cookie passing works. |
|
Excellent point. Does b96a5fd spark joy? (I will settle for 'it is coherent and correct') |
|
Maybe write the code to check Edit: Oh, we don't have a URL instance here necessarily. Should we normalize it so that we do? |
|
in the code or in the docs? |
|
Uh. I had meant in the code, but in the docs might suffice, as long as they are careful not to instantiate URLs from relative |
There's no such thing — if you create a |
nhunzaker
left a comment
There was a problem hiding this comment.
Reading over the documentation changes and code, I think this'll work great for my use case. Thank you for considering it and making changes to the API.
… is not a string or TypedArray (#16501) A universal load `fetch` with a `URLSearchParams`, `FormData` or `Blob` body crashes SSR with `TypeError: value must be a string or TypedArray` when the response would be inlined. #1385 guarded serialization on the request body being a string, #6565 re-pointed the check at the response body, and #9801 removed the throw that had been masking the loss. This restores the guard. The response isn't serialized and the browser repeats the fetch. The client lookup gets the same rule. It hashed only the headers when it couldn't hash the body, so during hydration such a fetch could resolve with a different same-url request's serialized response instead of being sent. Both tests fail on the base branch.
Migration guide
externalFetchhas been replaced withhandleFetch. WhereasexternalFetchonly ran when yourloadfunction contained afetchcall for an external URL,handleFetchruns for allfetchcalls inloadthat run on the server. Instead of receiving arequestargument, it receives{ event, request, fetch }, whereeventis the underlyingRequestEventandfetchis SvelteKit's internalfetchimplementation.Original PR description
Supersedes part of #6541
Closes #5253
Closes #5195
Closes #4750
This replaces
externalFetchwith a newhandleFetchhook, which gives developers the ability to forward whichever headers they need on a case-by-case basis — so for example if yourloadfunction looks like this......the
fetchwill be made without any non-default headers, but you can add custom headers insidehandleFetch:If unimplemented, defaults to
({ request, fetch }) => fetch(request).Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm testand lint the project withpnpm lintandpnpm checkChangesets
pnpm changesetand following the prompts. All changesets should bepatchuntil SvelteKit 1.0