@sveltejs/kit/hooks
import { function sequence(...handlers: Handle[]): HandleA helper function for sequencing multiple handle calls in a middleware-like manner.
The behavior for the handle options is as follows:
transformPageChunk is applied in reverse order and merged
preload is applied in forward order, the first option “wins” and no preload options after it are called
filterSerializedResponseHeaders behaves the same as preload
src/hooks.serverimport { sequence } from '@sveltejs/kit/hooks';
/// type: import('@sveltejs/kit').Handle
async function first({ event, resolve }) {
console.log('first pre-processing');
const result = await resolve(event, {
transformPageChunk: ({ html }) => {
// transforms are applied in reverse order
console.log('first transform');
return html;
},
preload: () => {
// this one wins as it's the first defined in the chain
console.log('first preload');
return true;
}
});
console.log('first post-processing');
return result;
}
/// type: import('@sveltejs/kit').Handle
async function second({ event, resolve }) {
console.log('second pre-processing');
const result = await resolve(event, {
transformPageChunk: ({ html }) => {
console.log('second transform');
return html;
},
preload: () => {
console.log('second preload');
return true;
},
filterSerializedResponseHeaders: () => {
// this one wins as it's the first defined in the chain
console.log('second filterSerializedResponseHeaders');
return true;
}
});
console.log('second post-processing');
return result;
}
export const handle = sequence(first, second);
The example above would print:
first pre-processing
first preload
second pre-processing
second filterSerializedResponseHeaders
second transform
first transform
second post-processing
first post-processing
sequence } from '@sveltejs/kit/hooks';sequence
A helper function for sequencing multiple handle calls in a middleware-like manner.
The behavior for the handle options is as follows:
transformPageChunkis applied in reverse order and mergedpreloadis applied in forward order, the first option “wins” and nopreloadoptions after it are calledfilterSerializedResponseHeadersbehaves the same aspreload
import { function sequence(...handlers: Handle[]): HandleA helper function for sequencing multiple handle calls in a middleware-like manner.
The behavior for the handle options is as follows:
transformPageChunk is applied in reverse order and merged
preload is applied in forward order, the first option “wins” and no preload options after it are called
filterSerializedResponseHeaders behaves the same as preload
src/hooks.serverimport { sequence } from '@sveltejs/kit/hooks';
/// type: import('@sveltejs/kit').Handle
async function first({ event, resolve }) {
console.log('first pre-processing');
const result = await resolve(event, {
transformPageChunk: ({ html }) => {
// transforms are applied in reverse order
console.log('first transform');
return html;
},
preload: () => {
// this one wins as it's the first defined in the chain
console.log('first preload');
return true;
}
});
console.log('first post-processing');
return result;
}
/// type: import('@sveltejs/kit').Handle
async function second({ event, resolve }) {
console.log('second pre-processing');
const result = await resolve(event, {
transformPageChunk: ({ html }) => {
console.log('second transform');
return html;
},
preload: () => {
console.log('second preload');
return true;
},
filterSerializedResponseHeaders: () => {
// this one wins as it's the first defined in the chain
console.log('second filterSerializedResponseHeaders');
return true;
}
});
console.log('second post-processing');
return result;
}
export const handle = sequence(first, second);
The example above would print:
first pre-processing
first preload
second pre-processing
second filterSerializedResponseHeaders
second transform
first transform
second post-processing
first post-processing
sequence } from '@sveltejs/kit/hooks';
/** @type {import('@sveltejs/kit').Handle} */
async function function first({ event, resolve }: {
event: any;
resolve: any;
}): Promise<any>
first({ event: anyevent, resolve: anyresolve }) {
var console: Consoleconsole.Console.log(...data: any[]): voidlog('first pre-processing');
const const result: anyresult = await resolve: anyresolve(event: anyevent, {
transformPageChunk: ({ html }: {
html: any;
}) => any
transformPageChunk: ({ html: anyhtml }) => {
// transforms are applied in reverse order
var console: Consoleconsole.Console.log(...data: any[]): voidlog('first transform');
return html: anyhtml;
},
preload: () => booleanpreload: () => {
// this one wins as it's the first defined in the chain
var console: Consoleconsole.Console.log(...data: any[]): voidlog('first preload');
return true;
}
});
var console: Consoleconsole.Console.log(...data: any[]): voidlog('first post-processing');
return const result: anyresult;
}
/** @type {import('@sveltejs/kit').Handle} */
async function function second({ event, resolve }: {
event: any;
resolve: any;
}): Promise<any>
second({ event: anyevent, resolve: anyresolve }) {
var console: Consoleconsole.Console.log(...data: any[]): voidlog('second pre-processing');
const const result: anyresult = await resolve: anyresolve(event: anyevent, {
transformPageChunk: ({ html }: {
html: any;
}) => any
transformPageChunk: ({ html: anyhtml }) => {
var console: Consoleconsole.Console.log(...data: any[]): voidlog('second transform');
return html: anyhtml;
},
preload: () => booleanpreload: () => {
var console: Consoleconsole.Console.log(...data: any[]): voidlog('second preload');
return true;
},
filterSerializedResponseHeaders: () => booleanfilterSerializedResponseHeaders: () => {
// this one wins as it's the first defined in the chain
var console: Consoleconsole.Console.log(...data: any[]): voidlog('second filterSerializedResponseHeaders');
return true;
}
});
var console: Consoleconsole.Console.log(...data: any[]): voidlog('second post-processing');
return const result: anyresult;
}
export const const handle: Handlehandle = function sequence(...handlers: Handle[]): HandleA helper function for sequencing multiple handle calls in a middleware-like manner.
The behavior for the handle options is as follows:
transformPageChunk is applied in reverse order and merged
preload is applied in forward order, the first option “wins” and no preload options after it are called
filterSerializedResponseHeaders behaves the same as preload
src/hooks.serverimport { sequence } from '@sveltejs/kit/hooks';
/// type: import('@sveltejs/kit').Handle
async function first({ event, resolve }) {
console.log('first pre-processing');
const result = await resolve(event, {
transformPageChunk: ({ html }) => {
// transforms are applied in reverse order
console.log('first transform');
return html;
},
preload: () => {
// this one wins as it's the first defined in the chain
console.log('first preload');
return true;
}
});
console.log('first post-processing');
return result;
}
/// type: import('@sveltejs/kit').Handle
async function second({ event, resolve }) {
console.log('second pre-processing');
const result = await resolve(event, {
transformPageChunk: ({ html }) => {
console.log('second transform');
return html;
},
preload: () => {
console.log('second preload');
return true;
},
filterSerializedResponseHeaders: () => {
// this one wins as it's the first defined in the chain
console.log('second filterSerializedResponseHeaders');
return true;
}
});
console.log('second post-processing');
return result;
}
export const handle = sequence(first, second);
The example above would print:
first pre-processing
first preload
second pre-processing
second filterSerializedResponseHeaders
second transform
first transform
second post-processing
first post-processing
sequence(function first({ event, resolve }: {
event: any;
resolve: any;
}): Promise<any>
first, function second({ event, resolve }: {
event: any;
resolve: any;
}): Promise<any>
second);import { function sequence(...handlers: Handle[]): HandleA helper function for sequencing multiple handle calls in a middleware-like manner.
The behavior for the handle options is as follows:
transformPageChunk is applied in reverse order and merged
preload is applied in forward order, the first option “wins” and no preload options after it are called
filterSerializedResponseHeaders behaves the same as preload
src/hooks.serverimport { sequence } from '@sveltejs/kit/hooks';
/// type: import('@sveltejs/kit').Handle
async function first({ event, resolve }) {
console.log('first pre-processing');
const result = await resolve(event, {
transformPageChunk: ({ html }) => {
// transforms are applied in reverse order
console.log('first transform');
return html;
},
preload: () => {
// this one wins as it's the first defined in the chain
console.log('first preload');
return true;
}
});
console.log('first post-processing');
return result;
}
/// type: import('@sveltejs/kit').Handle
async function second({ event, resolve }) {
console.log('second pre-processing');
const result = await resolve(event, {
transformPageChunk: ({ html }) => {
console.log('second transform');
return html;
},
preload: () => {
console.log('second preload');
return true;
},
filterSerializedResponseHeaders: () => {
// this one wins as it's the first defined in the chain
console.log('second filterSerializedResponseHeaders');
return true;
}
});
console.log('second post-processing');
return result;
}
export const handle = sequence(first, second);
The example above would print:
first pre-processing
first preload
second pre-processing
second filterSerializedResponseHeaders
second transform
first transform
second post-processing
first post-processing
sequence } from '@sveltejs/kit/hooks';
import type { type Handle = (input: {
event: RequestEvent;
resolve: (event: RequestEvent, opts?: ResolveOptions) => MaybePromise<Response>;
}) => MaybePromise<...>
The handle hook runs every time the SvelteKit server receives a request and
determines the response.
It receives an event object representing the request and a function called resolve, which renders the route and generates a Response.
This allows you to modify response headers or bodies, or bypass SvelteKit entirely (for implementing routes programmatically, for example).
Handle } from '@sveltejs/kit';
const const first: Handlefirst: type Handle = (input: {
event: RequestEvent;
resolve: (event: RequestEvent, opts?: ResolveOptions) => MaybePromise<Response>;
}) => MaybePromise<...>
The handle hook runs every time the SvelteKit server receives a request and
determines the response.
It receives an event object representing the request and a function called resolve, which renders the route and generates a Response.
This allows you to modify response headers or bodies, or bypass SvelteKit entirely (for implementing routes programmatically, for example).
Handle = async ({ event: RequestEvent<Record<string, string>, string | null>event, resolve: (event: RequestEvent, opts?: ResolveOptions) => MaybePromise<Response>resolve }) => {
var console: Consoleconsole.Console.log(...data: any[]): voidlog('first pre-processing');
const const result: Responseresult = await resolve: (event: RequestEvent, opts?: ResolveOptions) => MaybePromise<Response>resolve(event: RequestEvent<Record<string, string>, string | null>event, {
ResolveOptions.transformPageChunk?: ((input: {
html: string;
done: boolean;
}) => MaybePromise<string | undefined>) | 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.
transformPageChunk: ({ html: stringhtml }) => {
// transforms are applied in reverse order
var console: Consoleconsole.Console.log(...data: any[]): voidlog('first transform');
return html: stringhtml;
},
ResolveOptions.preload?: ((input: {
type: "font" | "css" | "js" | "asset";
path: string;
}) => boolean) | undefined
Determines what should be added to the <head> tag to preload it.
By default, js and css files will be preloaded.
preload: () => {
// this one wins as it's the first defined in the chain
var console: Consoleconsole.Console.log(...data: any[]): voidlog('first preload');
return true;
}
});
var console: Consoleconsole.Console.log(...data: any[]): voidlog('first post-processing');
return const result: Responseresult;
};
const const second: Handlesecond: type Handle = (input: {
event: RequestEvent;
resolve: (event: RequestEvent, opts?: ResolveOptions) => MaybePromise<Response>;
}) => MaybePromise<...>
The handle hook runs every time the SvelteKit server receives a request and
determines the response.
It receives an event object representing the request and a function called resolve, which renders the route and generates a Response.
This allows you to modify response headers or bodies, or bypass SvelteKit entirely (for implementing routes programmatically, for example).
Handle = async ({ event: RequestEvent<Record<string, string>, string | null>event, resolve: (event: RequestEvent, opts?: ResolveOptions) => MaybePromise<Response>resolve }) => {
var console: Consoleconsole.Console.log(...data: any[]): voidlog('second pre-processing');
const const result: Responseresult = await resolve: (event: RequestEvent, opts?: ResolveOptions) => MaybePromise<Response>resolve(event: RequestEvent<Record<string, string>, string | null>event, {
ResolveOptions.transformPageChunk?: ((input: {
html: string;
done: boolean;
}) => MaybePromise<string | undefined>) | 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.
transformPageChunk: ({ html: stringhtml }) => {
var console: Consoleconsole.Console.log(...data: any[]): voidlog('second transform');
return html: stringhtml;
},
ResolveOptions.preload?: ((input: {
type: "font" | "css" | "js" | "asset";
path: string;
}) => boolean) | undefined
Determines what should be added to the <head> tag to preload it.
By default, js and css files will be preloaded.
preload: () => {
var console: Consoleconsole.Console.log(...data: any[]): voidlog('second preload');
return true;
},
ResolveOptions.filterSerializedResponseHeaders?: ((name: string, value: string) => boolean) | undefinedDetermines which headers should be included in serialized responses when a load function loads a resource with fetch.
By default, none will be included.
filterSerializedResponseHeaders: () => {
// this one wins as it's the first defined in the chain
var console: Consoleconsole.Console.log(...data: any[]): voidlog('second filterSerializedResponseHeaders');
return true;
}
});
var console: Consoleconsole.Console.log(...data: any[]): voidlog('second post-processing');
return const result: Responseresult;
};
export const const handle: Handlehandle = function sequence(...handlers: Handle[]): HandleA helper function for sequencing multiple handle calls in a middleware-like manner.
The behavior for the handle options is as follows:
transformPageChunk is applied in reverse order and merged
preload is applied in forward order, the first option “wins” and no preload options after it are called
filterSerializedResponseHeaders behaves the same as preload
src/hooks.serverimport { sequence } from '@sveltejs/kit/hooks';
/// type: import('@sveltejs/kit').Handle
async function first({ event, resolve }) {
console.log('first pre-processing');
const result = await resolve(event, {
transformPageChunk: ({ html }) => {
// transforms are applied in reverse order
console.log('first transform');
return html;
},
preload: () => {
// this one wins as it's the first defined in the chain
console.log('first preload');
return true;
}
});
console.log('first post-processing');
return result;
}
/// type: import('@sveltejs/kit').Handle
async function second({ event, resolve }) {
console.log('second pre-processing');
const result = await resolve(event, {
transformPageChunk: ({ html }) => {
console.log('second transform');
return html;
},
preload: () => {
console.log('second preload');
return true;
},
filterSerializedResponseHeaders: () => {
// this one wins as it's the first defined in the chain
console.log('second filterSerializedResponseHeaders');
return true;
}
});
console.log('second post-processing');
return result;
}
export const handle = sequence(first, second);
The example above would print:
first pre-processing
first preload
second pre-processing
second filterSerializedResponseHeaders
second transform
first transform
second post-processing
first post-processing
sequence(const first: Handlefirst, const second: Handlesecond);The example above would print:
first pre-processing
first preload
second pre-processing
second filterSerializedResponseHeaders
second transform
first transform
second post-processing
first post-processingfunction sequence(...handlers: Handle[]): Handle;Edit this page on GitHub llms.txt