@sveltejs/kit 1.17.1 → 1.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +6 -1
- package/src/core/adapt/builder.js +3 -3
- package/src/core/config/index.js +2 -2
- package/src/core/config/options.js +8 -3
- package/src/core/env.js +1 -1
- package/src/core/generate_manifest/index.js +2 -2
- package/src/core/postbuild/analyse.js +3 -3
- package/src/core/postbuild/fallback.js +1 -1
- package/src/core/postbuild/prerender.js +1 -1
- package/src/core/sync/create_manifest_data/index.js +2 -2
- package/src/core/sync/write_ambient.js +1 -1
- package/src/core/sync/write_client_manifest.js +1 -1
- package/src/core/sync/write_server.js +2 -1
- package/src/core/sync/write_types/index.js +24 -24
- package/src/exports/hooks/sequence.js +71 -7
- package/src/exports/index.js +88 -12
- package/src/exports/node/index.js +14 -3
- package/src/exports/node/polyfills.js +8 -0
- package/src/exports/public.d.ts +1264 -0
- package/src/exports/vite/build/build_server.js +2 -2
- package/src/exports/vite/build/build_service_worker.js +1 -1
- package/src/exports/vite/dev/index.js +3 -3
- package/src/exports/vite/index.js +11 -6
- package/src/runtime/app/environment.js +3 -4
- package/src/runtime/app/forms.js +63 -7
- package/src/runtime/app/navigation.js +95 -0
- package/src/runtime/app/stores.js +28 -7
- package/src/runtime/client/client.js +26 -14
- package/src/runtime/client/singletons.js +6 -4
- package/src/runtime/client/start.js +1 -1
- package/src/runtime/client/types.d.ts +4 -12
- package/src/runtime/client/utils.js +29 -10
- package/src/runtime/control.js +12 -9
- package/src/runtime/server/ambient.d.ts +3 -3
- package/src/runtime/server/cookie.js +3 -3
- package/src/runtime/server/data/index.js +5 -4
- package/src/runtime/server/endpoint.js +11 -4
- package/src/runtime/server/fetch.js +4 -6
- package/src/runtime/server/index.js +2 -2
- package/src/runtime/server/page/actions.js +13 -13
- package/src/runtime/server/page/csp.js +7 -2
- package/src/runtime/server/page/index.js +6 -5
- package/src/runtime/server/page/load_data.js +20 -9
- package/src/runtime/server/page/render.js +11 -11
- package/src/runtime/server/page/respond_with_error.js +4 -3
- package/src/runtime/server/respond.js +6 -6
- package/src/runtime/server/utils.js +7 -7
- package/src/types/ambient-private.d.ts +11 -0
- package/src/types/ambient.d.ts +108 -0
- package/{types → src/types}/internal.d.ts +4 -13
- package/{types → src/types}/private.d.ts +1 -10
- package/src/utils/error.js +3 -3
- package/src/utils/exports.js +2 -2
- package/src/utils/routing.js +1 -39
- package/src/utils/streaming.js +2 -2
- package/types/index.d.ts +2081 -1100
- package/types/index.d.ts.map +165 -0
- package/src/internal.d.ts +0 -16
- package/types/ambient.d.ts +0 -486
- /package/{types → src/types}/synthetic/$env+dynamic+private.md +0 -0
- /package/{types → src/types}/synthetic/$env+dynamic+public.md +0 -0
- /package/{types → src/types}/synthetic/$env+static+private.md +0 -0
- /package/{types → src/types}/synthetic/$env+static+public.md +0 -0
- /package/{types → src/types}/synthetic/$lib.md +0 -0
|
@@ -32,10 +32,10 @@ const warned = new WeakSet();
|
|
|
32
32
|
const valid_link_options = /** @type {const} */ ({
|
|
33
33
|
'preload-code': ['', 'off', 'tap', 'hover', 'viewport', 'eager'],
|
|
34
34
|
'preload-data': ['', 'off', 'tap', 'hover'],
|
|
35
|
-
keepfocus: ['', 'off'],
|
|
36
|
-
noscroll: ['', 'off'],
|
|
37
|
-
reload: ['', 'off'],
|
|
38
|
-
replacestate: ['', 'off']
|
|
35
|
+
keepfocus: ['', 'true', 'off', 'false'],
|
|
36
|
+
noscroll: ['', 'true', 'off', 'false'],
|
|
37
|
+
reload: ['', 'true', 'off', 'false'],
|
|
38
|
+
replacestate: ['', 'true', 'off', 'false']
|
|
39
39
|
});
|
|
40
40
|
|
|
41
41
|
/**
|
|
@@ -176,13 +176,27 @@ export function get_router_options(element) {
|
|
|
176
176
|
el = /** @type {Element} */ (parent_element(el));
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
+
/** @param {string | null} value */
|
|
180
|
+
function get_option_state(value) {
|
|
181
|
+
switch (value) {
|
|
182
|
+
case '':
|
|
183
|
+
case 'true':
|
|
184
|
+
return true;
|
|
185
|
+
case 'off':
|
|
186
|
+
case 'false':
|
|
187
|
+
return false;
|
|
188
|
+
default:
|
|
189
|
+
return null;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
179
193
|
return {
|
|
180
194
|
preload_code: levels[preload_code ?? 'off'],
|
|
181
195
|
preload_data: levels[preload_data ?? 'off'],
|
|
182
|
-
keep_focus: keep_focus
|
|
183
|
-
noscroll: noscroll
|
|
184
|
-
reload: reload
|
|
185
|
-
replace_state: replace_state
|
|
196
|
+
keep_focus: get_option_state(keep_focus),
|
|
197
|
+
noscroll: get_option_state(noscroll),
|
|
198
|
+
reload: get_option_state(reload),
|
|
199
|
+
replace_state: get_option_state(replace_state)
|
|
186
200
|
};
|
|
187
201
|
}
|
|
188
202
|
|
|
@@ -219,6 +233,13 @@ export function notifiable_store(value) {
|
|
|
219
233
|
export function create_updated_store() {
|
|
220
234
|
const { set, subscribe } = writable(false);
|
|
221
235
|
|
|
236
|
+
if (DEV || !BROWSER) {
|
|
237
|
+
return {
|
|
238
|
+
subscribe,
|
|
239
|
+
check: async () => false
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
|
|
222
243
|
const interval = __SVELTEKIT_APP_VERSION_POLL_INTERVAL__;
|
|
223
244
|
|
|
224
245
|
/** @type {NodeJS.Timeout} */
|
|
@@ -226,8 +247,6 @@ export function create_updated_store() {
|
|
|
226
247
|
|
|
227
248
|
/** @type {() => Promise<boolean>} */
|
|
228
249
|
async function check() {
|
|
229
|
-
if (DEV || !BROWSER) return false;
|
|
230
|
-
|
|
231
250
|
clearTimeout(timeout);
|
|
232
251
|
|
|
233
252
|
if (interval) timeout = setTimeout(check, interval);
|
package/src/runtime/control.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export
|
|
1
|
+
export class HttpError {
|
|
2
2
|
/**
|
|
3
3
|
* @param {number} status
|
|
4
4
|
* @param {{message: string} extends App.Error ? (App.Error | string | undefined) : App.Error} body
|
|
@@ -17,9 +17,9 @@ export let HttpError = class HttpError {
|
|
|
17
17
|
toString() {
|
|
18
18
|
return JSON.stringify(this.body);
|
|
19
19
|
}
|
|
20
|
-
}
|
|
20
|
+
}
|
|
21
21
|
|
|
22
|
-
export
|
|
22
|
+
export class Redirect {
|
|
23
23
|
/**
|
|
24
24
|
* @param {300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308} status
|
|
25
25
|
* @param {string} location
|
|
@@ -28,12 +28,12 @@ export let Redirect = class Redirect {
|
|
|
28
28
|
this.status = status;
|
|
29
29
|
this.location = location;
|
|
30
30
|
}
|
|
31
|
-
}
|
|
31
|
+
}
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
34
|
* @template {Record<string, unknown> | undefined} [T=undefined]
|
|
35
35
|
*/
|
|
36
|
-
export
|
|
36
|
+
export class ActionFailure {
|
|
37
37
|
/**
|
|
38
38
|
* @param {number} status
|
|
39
39
|
* @param {T} [data]
|
|
@@ -42,7 +42,7 @@ export let ActionFailure = class ActionFailure {
|
|
|
42
42
|
this.status = status;
|
|
43
43
|
this.data = data;
|
|
44
44
|
}
|
|
45
|
-
}
|
|
45
|
+
}
|
|
46
46
|
|
|
47
47
|
/**
|
|
48
48
|
* This is a grotesque hack that, in dev, allows us to replace the implementations
|
|
@@ -57,7 +57,10 @@ export let ActionFailure = class ActionFailure {
|
|
|
57
57
|
* }} implementations
|
|
58
58
|
*/
|
|
59
59
|
export function replace_implementations(implementations) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
// @ts-expect-error
|
|
61
|
+
ActionFailure = implementations.ActionFailure; // eslint-disable-line no-class-assign
|
|
62
|
+
// @ts-expect-error
|
|
63
|
+
HttpError = implementations.HttpError; // eslint-disable-line no-class-assign
|
|
64
|
+
// @ts-expect-error
|
|
65
|
+
Redirect = implementations.Redirect; // eslint-disable-line no-class-assign
|
|
63
66
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
declare module '__SERVER__/internal.js' {
|
|
2
2
|
export const options: import('types').SSROptions;
|
|
3
3
|
export const get_hooks: () => Promise<{
|
|
4
|
-
handle?: import('
|
|
5
|
-
handleError?: import('
|
|
6
|
-
handleFetch?: import('
|
|
4
|
+
handle?: import('@sveltejs/kit').Handle;
|
|
5
|
+
handleError?: import('@sveltejs/kit').HandleServerError;
|
|
6
|
+
handleFetch?: import('@sveltejs/kit').HandleFetch;
|
|
7
7
|
}>;
|
|
8
8
|
}
|
|
@@ -37,11 +37,11 @@ export function get_cookies(request, url, trailing_slash) {
|
|
|
37
37
|
secure: url.hostname === 'localhost' && url.protocol === 'http:' ? false : true
|
|
38
38
|
};
|
|
39
39
|
|
|
40
|
-
/** @type {import('
|
|
40
|
+
/** @type {import('@sveltejs/kit').Cookies} */
|
|
41
41
|
const cookies = {
|
|
42
42
|
// The JSDoc param annotations appearing below for get, set and delete
|
|
43
43
|
// are necessary to expose the `cookie` library types to
|
|
44
|
-
// typescript users. `@type {import('
|
|
44
|
+
// typescript users. `@type {import('@sveltejs/kit').Cookies}` above is not
|
|
45
45
|
// sufficient to do so.
|
|
46
46
|
|
|
47
47
|
/**
|
|
@@ -174,7 +174,7 @@ export function get_cookies(request, url, trailing_slash) {
|
|
|
174
174
|
* @param {import('cookie').CookieSerializeOptions} opts
|
|
175
175
|
*/
|
|
176
176
|
function set_internal(name, value, opts) {
|
|
177
|
-
|
|
177
|
+
const path = opts.path ?? default_path;
|
|
178
178
|
|
|
179
179
|
new_cookies[name] = {
|
|
180
180
|
name,
|
|
@@ -11,10 +11,10 @@ import { create_async_iterator } from '../../../utils/streaming.js';
|
|
|
11
11
|
const encoder = new TextEncoder();
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
|
-
* @param {import('
|
|
14
|
+
* @param {import('@sveltejs/kit').RequestEvent} event
|
|
15
15
|
* @param {import('types').SSRRoute} route
|
|
16
16
|
* @param {import('types').SSROptions} options
|
|
17
|
-
* @param {import('
|
|
17
|
+
* @param {import('@sveltejs/kit').SSRManifest} manifest
|
|
18
18
|
* @param {import('types').SSRState} state
|
|
19
19
|
* @param {boolean[] | undefined} invalidated_data_nodes
|
|
20
20
|
* @param {import('types').TrailingSlash} trailing_slash
|
|
@@ -76,7 +76,8 @@ export async function render_data(
|
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
return data;
|
|
79
|
-
}
|
|
79
|
+
},
|
|
80
|
+
track_server_fetches: options.track_server_fetches
|
|
80
81
|
});
|
|
81
82
|
} catch (e) {
|
|
82
83
|
aborted = true;
|
|
@@ -182,7 +183,7 @@ export function redirect_json_response(redirect) {
|
|
|
182
183
|
/**
|
|
183
184
|
* If the serialized data contains promises, `chunks` will be an
|
|
184
185
|
* async iterable containing their resolutions
|
|
185
|
-
* @param {import('
|
|
186
|
+
* @param {import('@sveltejs/kit').RequestEvent} event
|
|
186
187
|
* @param {import('types').SSROptions} options
|
|
187
188
|
* @param {Array<import('types').ServerDataSkippedNode | import('types').ServerDataNode | import('types').ServerErrorNode | null | undefined>} nodes
|
|
188
189
|
* @returns {{ data: string, chunks: AsyncIterable<string> | null }}
|
|
@@ -3,7 +3,7 @@ import { Redirect } from '../control.js';
|
|
|
3
3
|
import { method_not_allowed } from './utils.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* @param {import('
|
|
6
|
+
* @param {import('@sveltejs/kit').RequestEvent} event
|
|
7
7
|
* @param {import('types').SSREndpoint} mod
|
|
8
8
|
* @param {import('types').SSRState} state
|
|
9
9
|
* @returns {Promise<Response>}
|
|
@@ -39,8 +39,8 @@ export async function render_endpoint(event, mod, state) {
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
try {
|
|
42
|
-
|
|
43
|
-
/** @type {import('
|
|
42
|
+
let response = await handler(
|
|
43
|
+
/** @type {import('@sveltejs/kit').RequestEvent<Record<string, any>>} */ (event)
|
|
44
44
|
);
|
|
45
45
|
|
|
46
46
|
if (!(response instanceof Response)) {
|
|
@@ -50,6 +50,13 @@ export async function render_endpoint(event, mod, state) {
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
if (state.prerendering) {
|
|
53
|
+
// the returned Response might have immutable Headers
|
|
54
|
+
// so we should clone them before trying to mutate them
|
|
55
|
+
response = new Response(response.body, {
|
|
56
|
+
status: response.status,
|
|
57
|
+
statusText: response.statusText,
|
|
58
|
+
headers: new Headers(response.headers)
|
|
59
|
+
});
|
|
53
60
|
response.headers.set('x-sveltekit-prerender', String(prerender));
|
|
54
61
|
}
|
|
55
62
|
|
|
@@ -67,7 +74,7 @@ export async function render_endpoint(event, mod, state) {
|
|
|
67
74
|
}
|
|
68
75
|
|
|
69
76
|
/**
|
|
70
|
-
* @param {import('
|
|
77
|
+
* @param {import('@sveltejs/kit').RequestEvent} event
|
|
71
78
|
*/
|
|
72
79
|
export function is_endpoint_request(event) {
|
|
73
80
|
const { method, headers } = event.request;
|
|
@@ -4,9 +4,9 @@ import * as paths from '__sveltekit/paths';
|
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* @param {{
|
|
7
|
-
* event: import('
|
|
7
|
+
* event: import('@sveltejs/kit').RequestEvent;
|
|
8
8
|
* options: import('types').SSROptions;
|
|
9
|
-
* manifest: import('
|
|
9
|
+
* manifest: import('@sveltejs/kit').SSRManifest;
|
|
10
10
|
* state: import('types').SSRState;
|
|
11
11
|
* get_cookie_header: (url: URL, header: string | null) => string;
|
|
12
12
|
* set_internal: (name: string, value: string, opts: import('cookie').CookieSerializeOptions) => void;
|
|
@@ -67,9 +67,6 @@ export function create_fetch({ event, options, manifest, state, get_cookie_heade
|
|
|
67
67
|
return fetch(request);
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
/** @type {Response} */
|
|
71
|
-
let response;
|
|
72
|
-
|
|
73
70
|
// handle fetch requests for static assets. e.g. prebaked data, etc.
|
|
74
71
|
// we need to support everything the browser's fetch supports
|
|
75
72
|
const prefix = paths.assets || paths.base;
|
|
@@ -121,7 +118,8 @@ export function create_fetch({ event, options, manifest, state, get_cookie_heade
|
|
|
121
118
|
);
|
|
122
119
|
}
|
|
123
120
|
|
|
124
|
-
|
|
121
|
+
/** @type {Response} */
|
|
122
|
+
const response = await respond(request, options, manifest, {
|
|
125
123
|
...state,
|
|
126
124
|
depth: state.depth + 1
|
|
127
125
|
});
|
|
@@ -7,10 +7,10 @@ export class Server {
|
|
|
7
7
|
/** @type {import('types').SSROptions} */
|
|
8
8
|
#options;
|
|
9
9
|
|
|
10
|
-
/** @type {import('
|
|
10
|
+
/** @type {import('@sveltejs/kit').SSRManifest} */
|
|
11
11
|
#manifest;
|
|
12
12
|
|
|
13
|
-
/** @param {import('
|
|
13
|
+
/** @param {import('@sveltejs/kit').SSRManifest} manifest */
|
|
14
14
|
constructor(manifest) {
|
|
15
15
|
/** @type {import('types').SSROptions} */
|
|
16
16
|
this.#options = options;
|
|
@@ -5,7 +5,7 @@ import { is_form_content_type, negotiate } from '../../../utils/http.js';
|
|
|
5
5
|
import { HttpError, Redirect, ActionFailure } from '../../control.js';
|
|
6
6
|
import { handle_error_and_jsonify } from '../utils.js';
|
|
7
7
|
|
|
8
|
-
/** @param {import('
|
|
8
|
+
/** @param {import('@sveltejs/kit').RequestEvent} event */
|
|
9
9
|
export function is_action_json_request(event) {
|
|
10
10
|
const accept = negotiate(event.request.headers.get('accept') ?? '*/*', [
|
|
11
11
|
'application/json',
|
|
@@ -16,7 +16,7 @@ export function is_action_json_request(event) {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
|
-
* @param {import('
|
|
19
|
+
* @param {import('@sveltejs/kit').RequestEvent} event
|
|
20
20
|
* @param {import('types').SSROptions} options
|
|
21
21
|
* @param {import('types').SSRNode['server'] | undefined} server
|
|
22
22
|
*/
|
|
@@ -92,12 +92,12 @@ export async function handle_action_json_request(event, options, server) {
|
|
|
92
92
|
*/
|
|
93
93
|
function check_incorrect_fail_use(error) {
|
|
94
94
|
return error instanceof ActionFailure
|
|
95
|
-
? new Error(
|
|
95
|
+
? new Error('Cannot "throw fail()". Use "return fail()"')
|
|
96
96
|
: error;
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
/**
|
|
100
|
-
* @param {import('
|
|
100
|
+
* @param {import('@sveltejs/kit').Redirect} redirect
|
|
101
101
|
*/
|
|
102
102
|
export function action_json_redirect(redirect) {
|
|
103
103
|
return action_json({
|
|
@@ -108,7 +108,7 @@ export function action_json_redirect(redirect) {
|
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
/**
|
|
111
|
-
* @param {import('
|
|
111
|
+
* @param {import('@sveltejs/kit').ActionResult} data
|
|
112
112
|
* @param {ResponseInit} [init]
|
|
113
113
|
*/
|
|
114
114
|
function action_json(data, init) {
|
|
@@ -116,16 +116,16 @@ function action_json(data, init) {
|
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
/**
|
|
119
|
-
* @param {import('
|
|
119
|
+
* @param {import('@sveltejs/kit').RequestEvent} event
|
|
120
120
|
*/
|
|
121
121
|
export function is_action_request(event) {
|
|
122
122
|
return event.request.method === 'POST';
|
|
123
123
|
}
|
|
124
124
|
|
|
125
125
|
/**
|
|
126
|
-
* @param {import('
|
|
126
|
+
* @param {import('@sveltejs/kit').RequestEvent} event
|
|
127
127
|
* @param {import('types').SSRNode['server'] | undefined} server
|
|
128
|
-
* @returns {Promise<import('
|
|
128
|
+
* @returns {Promise<import('@sveltejs/kit').ActionResult>}
|
|
129
129
|
*/
|
|
130
130
|
export async function handle_action_request(event, server) {
|
|
131
131
|
const actions = server?.actions;
|
|
@@ -185,18 +185,18 @@ export async function handle_action_request(event, server) {
|
|
|
185
185
|
}
|
|
186
186
|
|
|
187
187
|
/**
|
|
188
|
-
* @param {import('
|
|
188
|
+
* @param {import('@sveltejs/kit').Actions} actions
|
|
189
189
|
*/
|
|
190
190
|
function check_named_default_separate(actions) {
|
|
191
191
|
if (actions.default && Object.keys(actions).length > 1) {
|
|
192
192
|
throw new Error(
|
|
193
|
-
|
|
193
|
+
'When using named actions, the default action cannot be used. See the docs for more info: https://kit.svelte.dev/docs/form-actions#named-actions'
|
|
194
194
|
);
|
|
195
195
|
}
|
|
196
196
|
}
|
|
197
197
|
|
|
198
198
|
/**
|
|
199
|
-
* @param {import('
|
|
199
|
+
* @param {import('@sveltejs/kit').RequestEvent} event
|
|
200
200
|
* @param {NonNullable<import('types').SSRNode['server']['actions']>} actions
|
|
201
201
|
* @throws {Redirect | ActionFailure | HttpError | Error}
|
|
202
202
|
*/
|
|
@@ -231,12 +231,12 @@ async function call_action(event, actions) {
|
|
|
231
231
|
/** @param {any} data */
|
|
232
232
|
function validate_action_return(data) {
|
|
233
233
|
if (data instanceof Redirect) {
|
|
234
|
-
throw new Error(
|
|
234
|
+
throw new Error('Cannot `return redirect(...)` — use `throw redirect(...)` instead');
|
|
235
235
|
}
|
|
236
236
|
|
|
237
237
|
if (data instanceof HttpError) {
|
|
238
238
|
throw new Error(
|
|
239
|
-
|
|
239
|
+
'Cannot `return error(...)` — use `throw error(...)` or `return fail(...)` instead'
|
|
240
240
|
);
|
|
241
241
|
}
|
|
242
242
|
}
|
|
@@ -178,8 +178,13 @@ class BaseProvider {
|
|
|
178
178
|
|
|
179
179
|
class CspProvider extends BaseProvider {
|
|
180
180
|
get_meta() {
|
|
181
|
-
const content =
|
|
182
|
-
|
|
181
|
+
const content = this.get_header(true);
|
|
182
|
+
|
|
183
|
+
if (!content) {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return `<meta http-equiv="content-security-policy" content=${escape_html_attr(content)}>`;
|
|
183
188
|
}
|
|
184
189
|
}
|
|
185
190
|
|
|
@@ -22,10 +22,10 @@ import { get_data_json } from '../data/index.js';
|
|
|
22
22
|
const MAX_DEPTH = 10;
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
|
-
* @param {import('
|
|
25
|
+
* @param {import('@sveltejs/kit').RequestEvent} event
|
|
26
26
|
* @param {import('types').PageNodeIndexes} page
|
|
27
27
|
* @param {import('types').SSROptions} options
|
|
28
|
-
* @param {import('
|
|
28
|
+
* @param {import('@sveltejs/kit').SSRManifest} manifest
|
|
29
29
|
* @param {import('types').SSRState} state
|
|
30
30
|
* @param {import('types').RequiredResolveOptions} resolve_opts
|
|
31
31
|
* @returns {Promise<Response>}
|
|
@@ -54,7 +54,7 @@ export async function render_page(event, page, options, manifest, state, resolve
|
|
|
54
54
|
|
|
55
55
|
let status = 200;
|
|
56
56
|
|
|
57
|
-
/** @type {import('
|
|
57
|
+
/** @type {import('@sveltejs/kit').ActionResult | undefined} */
|
|
58
58
|
let action_result = undefined;
|
|
59
59
|
|
|
60
60
|
if (is_action_request(event)) {
|
|
@@ -118,7 +118,7 @@ export async function render_page(event, page, options, manifest, state, resolve
|
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
/** @type {Array<import('./types.js').Loaded | null>} */
|
|
121
|
-
|
|
121
|
+
const branch = [];
|
|
122
122
|
|
|
123
123
|
/** @type {Error | null} */
|
|
124
124
|
let load_error = null;
|
|
@@ -150,7 +150,8 @@ export async function render_page(event, page, options, manifest, state, resolve
|
|
|
150
150
|
if (parent) Object.assign(data, await parent.data);
|
|
151
151
|
}
|
|
152
152
|
return data;
|
|
153
|
-
}
|
|
153
|
+
},
|
|
154
|
+
track_server_fetches: options.track_server_fetches
|
|
154
155
|
});
|
|
155
156
|
} catch (e) {
|
|
156
157
|
load_error = /** @type {Error} */ (e);
|
|
@@ -6,14 +6,22 @@ import { validate_depends } from '../../shared.js';
|
|
|
6
6
|
/**
|
|
7
7
|
* Calls the user's server `load` function.
|
|
8
8
|
* @param {{
|
|
9
|
-
* event: import('
|
|
9
|
+
* event: import('@sveltejs/kit').RequestEvent;
|
|
10
10
|
* state: import('types').SSRState;
|
|
11
11
|
* node: import('types').SSRNode | undefined;
|
|
12
12
|
* parent: () => Promise<Record<string, any>>;
|
|
13
|
+
* track_server_fetches: boolean;
|
|
13
14
|
* }} opts
|
|
14
15
|
* @returns {Promise<import('types').ServerDataNode | null>}
|
|
15
16
|
*/
|
|
16
|
-
export async function load_server_data({
|
|
17
|
+
export async function load_server_data({
|
|
18
|
+
event,
|
|
19
|
+
state,
|
|
20
|
+
node,
|
|
21
|
+
parent,
|
|
22
|
+
// TODO 2.0: Remove this
|
|
23
|
+
track_server_fetches
|
|
24
|
+
}) {
|
|
17
25
|
if (!node?.server) return null;
|
|
18
26
|
|
|
19
27
|
let done = false;
|
|
@@ -51,7 +59,10 @@ export async function load_server_data({ event, state, node, parent }) {
|
|
|
51
59
|
);
|
|
52
60
|
}
|
|
53
61
|
|
|
54
|
-
|
|
62
|
+
// TODO 2.0: Remove this
|
|
63
|
+
if (track_server_fetches) {
|
|
64
|
+
uses.dependencies.add(url.href);
|
|
65
|
+
}
|
|
55
66
|
|
|
56
67
|
return event.fetch(info, init);
|
|
57
68
|
},
|
|
@@ -132,7 +143,7 @@ export async function load_server_data({ event, state, node, parent }) {
|
|
|
132
143
|
/**
|
|
133
144
|
* Calls the user's `load` function.
|
|
134
145
|
* @param {{
|
|
135
|
-
* event: import('
|
|
146
|
+
* event: import('@sveltejs/kit').RequestEvent;
|
|
136
147
|
* fetched: import('./types').Fetched[];
|
|
137
148
|
* node: import('types').SSRNode | undefined;
|
|
138
149
|
* parent: () => Promise<Record<string, any>>;
|
|
@@ -179,11 +190,11 @@ export async function load_data({
|
|
|
179
190
|
}
|
|
180
191
|
|
|
181
192
|
/**
|
|
182
|
-
* @param {Pick<import('
|
|
183
|
-
* @param {import(
|
|
184
|
-
* @param {import(
|
|
193
|
+
* @param {Pick<import('@sveltejs/kit').RequestEvent, 'fetch' | 'url' | 'request' | 'route'>} event
|
|
194
|
+
* @param {import('types').SSRState} state
|
|
195
|
+
* @param {import('./types').Fetched[]} fetched
|
|
185
196
|
* @param {boolean} csr
|
|
186
|
-
* @param {Pick<Required<import(
|
|
197
|
+
* @param {Pick<Required<import('@sveltejs/kit').ResolveOptions>, 'filterSerializedResponseHeaders'>} resolve_opts
|
|
187
198
|
*/
|
|
188
199
|
export function create_universal_fetch(event, state, fetched, csr, resolve_opts) {
|
|
189
200
|
/**
|
|
@@ -251,7 +262,7 @@ export function create_universal_fetch(event, state, fetched, csr, resolve_opts)
|
|
|
251
262
|
),
|
|
252
263
|
request_headers: init?.headers,
|
|
253
264
|
response_body: body,
|
|
254
|
-
response
|
|
265
|
+
response
|
|
255
266
|
});
|
|
256
267
|
}
|
|
257
268
|
|
|
@@ -28,14 +28,14 @@ const encoder = new TextEncoder();
|
|
|
28
28
|
* branch: Array<import('./types').Loaded>;
|
|
29
29
|
* fetched: Array<import('./types').Fetched>;
|
|
30
30
|
* options: import('types').SSROptions;
|
|
31
|
-
* manifest: import('
|
|
31
|
+
* manifest: import('@sveltejs/kit').SSRManifest;
|
|
32
32
|
* state: import('types').SSRState;
|
|
33
33
|
* page_config: { ssr: boolean; csr: boolean };
|
|
34
34
|
* status: number;
|
|
35
35
|
* error: App.Error | null;
|
|
36
|
-
* event: import('
|
|
36
|
+
* event: import('@sveltejs/kit').RequestEvent;
|
|
37
37
|
* resolve_opts: import('types').RequiredResolveOptions;
|
|
38
|
-
* action_result?: import('
|
|
38
|
+
* action_result?: import('@sveltejs/kit').ActionResult;
|
|
39
39
|
* }} opts
|
|
40
40
|
*/
|
|
41
41
|
export async function render_response({
|
|
@@ -157,7 +157,7 @@ export async function render_response({
|
|
|
157
157
|
);
|
|
158
158
|
} else if (!warned) {
|
|
159
159
|
console.warn(
|
|
160
|
-
|
|
160
|
+
'Avoid calling `fetch` eagerly during server side rendering — put your `fetch` calls inside `onMount` or a `load` function instead'
|
|
161
161
|
);
|
|
162
162
|
warned = true;
|
|
163
163
|
}
|
|
@@ -257,7 +257,7 @@ export async function render_response({
|
|
|
257
257
|
}
|
|
258
258
|
}
|
|
259
259
|
|
|
260
|
-
const global = __SVELTEKIT_DEV__ ?
|
|
260
|
+
const global = __SVELTEKIT_DEV__ ? '__sveltekit_dev' : `__sveltekit_${options.version_hash}`;
|
|
261
261
|
|
|
262
262
|
const { data, chunks } = get_data(
|
|
263
263
|
event,
|
|
@@ -298,7 +298,7 @@ export async function render_response({
|
|
|
298
298
|
].filter(Boolean);
|
|
299
299
|
|
|
300
300
|
if (chunks) {
|
|
301
|
-
blocks.push(
|
|
301
|
+
blocks.push('const deferred = new Map();');
|
|
302
302
|
|
|
303
303
|
properties.push(`defer: (id) => new Promise((fulfil, reject) => {
|
|
304
304
|
deferred.set(id, { fulfil, reject });
|
|
@@ -317,9 +317,9 @@ export async function render_response({
|
|
|
317
317
|
${properties.join(',\n\t\t\t\t\t\t')}
|
|
318
318
|
};`);
|
|
319
319
|
|
|
320
|
-
const args = [
|
|
320
|
+
const args = ['app', 'element'];
|
|
321
321
|
|
|
322
|
-
blocks.push(
|
|
322
|
+
blocks.push('const element = document.currentScript.parentElement;');
|
|
323
323
|
|
|
324
324
|
if (page_config.ssr) {
|
|
325
325
|
const serialized = { form: 'null', error: 'null' };
|
|
@@ -339,7 +339,7 @@ export async function render_response({
|
|
|
339
339
|
|
|
340
340
|
const hydrate = [
|
|
341
341
|
`node_ids: [${branch.map(({ node }) => node.index).join(', ')}]`,
|
|
342
|
-
|
|
342
|
+
'data',
|
|
343
343
|
`form: ${serialized.form}`,
|
|
344
344
|
`error: ${serialized.error}`
|
|
345
345
|
];
|
|
@@ -363,7 +363,7 @@ export async function render_response({
|
|
|
363
363
|
});`);
|
|
364
364
|
|
|
365
365
|
if (options.service_worker) {
|
|
366
|
-
const opts = __SVELTEKIT_DEV__ ?
|
|
366
|
+
const opts = __SVELTEKIT_DEV__ ? ", { type: 'module' }" : '';
|
|
367
367
|
|
|
368
368
|
// we use an anonymous function instead of an arrow function to support
|
|
369
369
|
// older browsers (https://github.com/sveltejs/kit/pull/5417)
|
|
@@ -490,7 +490,7 @@ export async function render_response({
|
|
|
490
490
|
/**
|
|
491
491
|
* If the serialized data contains promises, `chunks` will be an
|
|
492
492
|
* async iterable containing their resolutions
|
|
493
|
-
* @param {import('
|
|
493
|
+
* @param {import('@sveltejs/kit').RequestEvent} event
|
|
494
494
|
* @param {import('types').SSROptions} options
|
|
495
495
|
* @param {Array<import('types').ServerDataNode | null>} nodes
|
|
496
496
|
* @param {string} global
|
|
@@ -10,9 +10,9 @@ import { HttpError, Redirect } from '../../control.js';
|
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* @param {{
|
|
13
|
-
* event: import('
|
|
13
|
+
* event: import('@sveltejs/kit').RequestEvent;
|
|
14
14
|
* options: import('types').SSROptions;
|
|
15
|
-
* manifest: import('
|
|
15
|
+
* manifest: import('@sveltejs/kit').SSRManifest;
|
|
16
16
|
* state: import('types').SSRState;
|
|
17
17
|
* status: number;
|
|
18
18
|
* error: unknown;
|
|
@@ -44,7 +44,8 @@ export async function respond_with_error({
|
|
|
44
44
|
event,
|
|
45
45
|
state,
|
|
46
46
|
node: default_layout,
|
|
47
|
-
parent: async () => ({})
|
|
47
|
+
parent: async () => ({}),
|
|
48
|
+
track_server_fetches: options.track_server_fetches
|
|
48
49
|
});
|
|
49
50
|
|
|
50
51
|
const server_data = await server_data_promise;
|
|
@@ -45,13 +45,13 @@ const default_preload = ({ type }) => type === 'js' || type === 'css';
|
|
|
45
45
|
/**
|
|
46
46
|
* @param {Request} request
|
|
47
47
|
* @param {import('types').SSROptions} options
|
|
48
|
-
* @param {import('
|
|
48
|
+
* @param {import('@sveltejs/kit').SSRManifest} manifest
|
|
49
49
|
* @param {import('types').SSRState} state
|
|
50
50
|
* @returns {Promise<Response>}
|
|
51
51
|
*/
|
|
52
52
|
export async function respond(request, options, manifest, state) {
|
|
53
53
|
/** URL but stripped from the potential `/__data.json` suffix and its search param */
|
|
54
|
-
|
|
54
|
+
const url = new URL(request.url);
|
|
55
55
|
|
|
56
56
|
if (options.csrf_check_origin) {
|
|
57
57
|
const forbidden =
|
|
@@ -130,7 +130,7 @@ export async function respond(request, options, manifest, state) {
|
|
|
130
130
|
/** @type {Record<string, import('./page/types').Cookie>} */
|
|
131
131
|
let cookies_to_add = {};
|
|
132
132
|
|
|
133
|
-
/** @type {import('
|
|
133
|
+
/** @type {import('@sveltejs/kit').RequestEvent} */
|
|
134
134
|
const event = {
|
|
135
135
|
// @ts-expect-error `cookies` and `fetch` need to be created after the `event` itself
|
|
136
136
|
cookies: null,
|
|
@@ -155,7 +155,7 @@ export async function respond(request, options, manifest, state) {
|
|
|
155
155
|
|
|
156
156
|
if (lower === 'set-cookie') {
|
|
157
157
|
throw new Error(
|
|
158
|
-
|
|
158
|
+
'Use `event.cookies.set(name, value, options)` instead of `event.setHeaders` to set cookies'
|
|
159
159
|
);
|
|
160
160
|
} else if (lower in headers) {
|
|
161
161
|
throw new Error(`"${key}" header is already set`);
|
|
@@ -343,8 +343,8 @@ export async function respond(request, options, manifest, state) {
|
|
|
343
343
|
|
|
344
344
|
/**
|
|
345
345
|
*
|
|
346
|
-
* @param {import('
|
|
347
|
-
* @param {import('
|
|
346
|
+
* @param {import('@sveltejs/kit').RequestEvent} event
|
|
347
|
+
* @param {import('@sveltejs/kit').ResolveOptions} [opts]
|
|
348
348
|
*/
|
|
349
349
|
async function resolve(event, opts) {
|
|
350
350
|
try {
|