You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- it can be used to make credentialed requests on the server, as it inherits the `cookie` and `authorization` headers for the page request
144
144
- it can make relative requests on the server (ordinarily, `fetch` requires a URL with an origin when used in a server context)
145
145
- internal requests (e.g. for `+server.js` routes) go direct to the handler function when running on the server, without the overhead of an HTTP call
146
-
- during server-side rendering, the response will be captured and inlined into the rendered HTML
146
+
- during server-side rendering, the response will be captured and inlined into the rendered HTML. Note that headers will _not_ be serialized, unless explicitly included via [`filterSerializedResponseHeaders`](/docs/hooks#handle)
147
147
- during hydration, the response will be read from the HTML, guaranteeing consistency and preventing an additional network request
148
148
149
149
> Cookies will only be passed through if the target host is the same as the SvelteKit application or a more specific subdomain of it.
Copy file name to clipboardExpand all lines: documentation/docs/06-hooks.md
+3-1
Original file line number
Diff line number
Diff line change
@@ -64,13 +64,15 @@ You can add call multiple `handle` functions with [the `sequence` helper functio
64
64
`resolve` also supports a second, optional parameter that gives you more control over how the response will be rendered. That parameter is an object that can have the following fields:
65
65
66
66
-`transformPageChunk(opts: { html: string, done: boolean }): MaybePromise<string | undefined>` — applies custom transforms to HTML. If `done` is true, it's the final chunk. Chunks are not guaranteed to be well-formed HTML (they could include an element's opening tag but not its closing tag, for example) but they will always be split at sensible boundaries such as `%sveltekit.head%` or layout/page components.
67
+
-`filterSerializedResponseHeaders(name: string, value: string): boolean` — determines which headers should be included in serialized responses when a `load` function loads a resource with `fetch`. By default, none will be included.
67
68
68
69
```js
69
70
/// file: src/hooks.js
70
71
/**@type{import('@sveltejs/kit').Handle}*/
71
72
exportasyncfunctionhandle({ event, resolve }) {
72
73
constresponse=awaitresolve(event, {
73
-
transformPageChunk: ({ html }) =>html.replace('old', 'new')
74
+
transformPageChunk: ({ html }) =>html.replace('old', 'new'),
`Failed to get response header "${lower}" — it must be included by the \`filterSerializedResponseHeaders\` option: https://kit.svelte.dev/docs/hooks#handle`
0 commit comments