Skip to content

Commit eae1b1d

Browse files
Rename handle's render parameter to resolve (#1566)
* Rename handle's render parameter to respond * Rename to resolve * Update 04-hooks.md remove reference to 'renderer', which is confusing now that we no longer use `render` Co-authored-by: Rich Harris <[email protected]>
1 parent 6aa4988 commit eae1b1d

File tree

8 files changed

+18
-13
lines changed

8 files changed

+18
-13
lines changed

.changeset/tender-buckets-turn.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
Rename handle's render parameter to resolve

documentation/docs/04-hooks.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ An optional `src/hooks.js` (or `src/hooks.ts`, or `src/hooks/index.js`) file exp
88
99
### handle
1010

11-
This function runs on every request, and determines the response. It receives the `request` object and `render` method, which calls SvelteKit's default renderer. This allows you to modify response headers or bodies, or bypass SvelteKit entirely (for implementing endpoints programmatically, for example).
11+
This function runs on every request, for both pages and endpoints, and determines the response. It receives the `request` object and a function called `resolve`, which invokes SvelteKit's router and generates a response accordingly. This allows you to modify response headers or bodies, or bypass SvelteKit entirely (for implementing endpoints programmatically, for example).
1212

13-
If unimplemented, defaults to `({ request, render }) => render(request)`.
13+
If unimplemented, defaults to `({ request, resolve }) => resolve(request)`.
1414

1515
To add custom data to the request, which is passed to endpoints, populate the `request.locals` object, as shown below.
1616

@@ -37,16 +37,16 @@ type Response = {
3737

3838
type Handle<Locals = Record<string, any>> = (input: {
3939
request: Request<Locals>;
40-
render: (request: Request<Locals>) => Response | Promise<Response>;
40+
resolve: (request: Request<Locals>) => Response | Promise<Response>;
4141
}) => Response | Promise<Response>;
4242
```
4343

4444
```js
4545
/** @type {import('@sveltejs/kit').Handle} */
46-
export async function handle({ request, render }) {
46+
export async function handle({ request, resolve }) {
4747
request.locals.user = await getUserInformation(request.headers.cookie);
4848

49-
const response = await render(request);
49+
const response = await resolve(request);
5050

5151
return {
5252
...response,

packages/create-svelte/templates/default/src/hooks.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import cookie from 'cookie';
22
import { v4 as uuid } from '@lukeed/uuid';
33
import type { Handle } from '@sveltejs/kit';
44

5-
export const handle: Handle = async ({ request, render }) => {
5+
export const handle: Handle = async ({ request, resolve }) => {
66
const cookies = cookie.parse(request.headers.cookie || '');
77
request.locals.userid = cookies.userid || uuid();
88

@@ -11,7 +11,7 @@ export const handle: Handle = async ({ request, render }) => {
1111
request.method = request.query.get('_method').toUpperCase();
1212
}
1313

14-
const response = await render(request);
14+
const response = await resolve(request);
1515

1616
if (!cookies.userid) {
1717
// if this is the first time the user has visited this app,

packages/kit/src/core/build/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ async function build_server(
363363
// named imports without triggering Rollup's missing import detection
364364
const get_hooks = hooks => ({
365365
getSession: hooks.getSession || (() => ({})),
366-
handle: hooks.handle || (({ request, render }) => render(request))
366+
handle: hooks.handle || (({ request, resolve }) => resolve(request))
367367
});
368368
369369
const module_lookup = {

packages/kit/src/core/dev/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ class Watcher extends EventEmitter {
194194
},
195195
hooks: {
196196
getSession: hooks.getSession || (() => ({})),
197-
handle: hooks.handle || (({ request, render }) => render(request))
197+
handle: hooks.handle || (({ request, resolve }) => resolve(request))
198198
},
199199
hydrate: this.config.kit.hydrate,
200200
paths: this.config.kit.paths,

packages/kit/src/runtime/server/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export async function respond(incoming, options, state = {}) {
4141
params: null,
4242
locals: {}
4343
},
44-
render: async (request) => {
44+
resolve: async (request) => {
4545
if (state.prerender && state.prerender.fallback) {
4646
return await render_response({
4747
options,

packages/kit/test/apps/basics/src/hooks.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ export function getSession(request) {
66
}
77

88
/** @type {import('@sveltejs/kit').Handle} */
9-
export async function handle({ request, render }) {
9+
export async function handle({ request, resolve }) {
1010
const cookies = cookie.parse(request.headers.cookie || '');
1111

1212
request.locals.answer = 42;
1313
request.locals.name = cookies.name;
1414

15-
const response = await render(request);
15+
const response = await resolve(request);
1616

1717
if (response) {
1818
return {

packages/kit/types/hooks.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ export type GetSession<Locals = Record<string, any>, Session = any> = {
2929

3030
export type Handle<Locals = Record<string, any>> = (input: {
3131
request: ServerRequest<Locals>;
32-
render: (request: ServerRequest<Locals>) => ServerResponse | Promise<ServerResponse>;
32+
resolve: (request: ServerRequest<Locals>) => ServerResponse | Promise<ServerResponse>;
3333
}) => ServerResponse | Promise<ServerResponse>;

0 commit comments

Comments
 (0)