@sveltejs/kit 3.0.0-next.11 → 3.0.0-next.13
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 +10 -10
- package/src/cli.js +8 -8
- package/src/constants.js +1 -1
- package/src/core/config/options.js +43 -35
- package/src/core/env.js +25 -11
- package/src/core/postbuild/prerender.js +3 -3
- package/src/core/sync/sync.js +11 -14
- package/src/core/sync/utils.js +21 -1
- package/src/core/sync/{write_non_ambient.js → write_app_types.js} +24 -23
- package/src/core/sync/write_client_manifest.js +4 -12
- package/src/core/sync/write_env.js +6 -4
- package/src/core/sync/write_server.js +10 -15
- package/src/core/sync/write_tsconfig/index.js +257 -0
- package/src/core/sync/write_tsconfig/utils.js +162 -0
- package/src/core/sync/write_types/index.js +80 -88
- package/src/exports/index.js +23 -12
- package/src/exports/internal/server/index.js +3 -1
- package/src/exports/internal/shared.js +4 -12
- package/src/exports/public.d.ts +87 -62
- package/src/exports/vite/build/remote.js +10 -12
- package/src/exports/vite/dev/index.js +113 -88
- package/src/exports/vite/index.js +452 -237
- package/src/exports/vite/module_ids.js +3 -1
- package/src/exports/vite/utils.js +1 -10
- package/src/runner.js +13 -0
- package/src/runtime/app/forms.js +4 -0
- package/src/runtime/app/manifest/index.js +1 -0
- package/src/runtime/app/paths/client.js +30 -30
- package/src/runtime/app/paths/internal/client.js +26 -0
- package/src/runtime/app/paths/server.js +22 -9
- package/src/runtime/app/paths/types.d.ts +11 -19
- package/src/runtime/app/server/remote/command.js +12 -7
- package/src/runtime/app/server/remote/form.js +37 -26
- package/src/runtime/app/server/remote/prerender.js +22 -11
- package/src/runtime/app/server/remote/query.js +5 -4
- package/src/runtime/app/server/remote/requested.js +4 -4
- package/src/runtime/app/server/remote/shared.js +48 -30
- package/src/runtime/app/service-worker/index.js +24 -0
- package/src/runtime/app/state/client.js +3 -0
- package/src/runtime/app/state/index.js +3 -3
- package/src/runtime/app/state/server.js +3 -0
- package/src/runtime/client/client.js +627 -311
- package/src/runtime/client/constants.js +2 -6
- package/src/runtime/client/fetcher.js +27 -17
- package/src/runtime/client/remote-functions/form.svelte.js +82 -58
- package/src/runtime/client/remote-functions/prerender.svelte.js +1 -1
- package/src/runtime/client/remote-functions/query/index.js +2 -2
- package/src/runtime/client/remote-functions/query/instance.svelte.js +2 -2
- package/src/runtime/client/remote-functions/query-batch.svelte.js +3 -4
- package/src/runtime/client/remote-functions/query-live/instance.svelte.js +2 -2
- package/src/runtime/client/remote-functions/query-live/iterator.js +15 -10
- package/src/runtime/client/remote-functions/shared.svelte.js +15 -11
- package/src/runtime/client/state.svelte.js +54 -33
- package/src/runtime/client/types.d.ts +1 -2
- package/src/runtime/client/utils.js +21 -14
- package/src/runtime/components/root.svelte +4 -14
- package/src/runtime/form-utils.js +89 -54
- package/src/runtime/props.svelte.js +71 -0
- package/src/runtime/server/cookie.js +1 -1
- package/src/runtime/server/data/index.js +31 -28
- package/src/runtime/server/errors.js +1 -1
- package/src/runtime/server/fetch.js +4 -6
- package/src/runtime/server/page/actions.js +3 -3
- package/src/runtime/server/page/csp.js +86 -103
- package/src/runtime/server/page/index.js +1 -2
- package/src/runtime/server/page/load_data.js +15 -5
- package/src/runtime/server/page/render.js +46 -52
- package/src/runtime/server/page/respond_with_error.js +1 -3
- package/src/runtime/server/remote-functions.js +66 -35
- package/src/runtime/server/respond.js +56 -16
- package/src/runtime/server/utils.js +10 -0
- package/src/types/ambient-private.d.ts +9 -1
- package/src/types/ambient.d.ts +23 -28
- package/src/types/global-private.d.ts +12 -0
- package/src/types/internal.d.ts +15 -10
- package/src/types/private.d.ts +3 -12
- package/src/utils/url.js +12 -0
- package/src/version.js +1 -1
- package/types/index.d.ts +172 -155
- package/types/index.d.ts.map +5 -1
- package/src/core/sync/write_ambient.js +0 -18
- package/src/core/sync/write_tsconfig.js +0 -258
- package/src/runtime/types.d.ts +0 -8
- /package/src/core/sync/{write_tsconfig_test → write_tsconfig/test-app}/package.json +0 -0
|
@@ -117,7 +117,7 @@ export function create_fetch({ event, options, manifest, state, get_cookie_heade
|
|
|
117
117
|
return await fetch(request);
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
-
if (has_prerendered_path(manifest,
|
|
120
|
+
if (has_prerendered_path(manifest, decoded)) {
|
|
121
121
|
// The path of something prerendered could match a different route
|
|
122
122
|
// that is still in the manifest, leading to the wrong route being loaded.
|
|
123
123
|
// We therefore bail early here. The prerendered logic is different for
|
|
@@ -142,11 +142,9 @@ export function create_fetch({ event, options, manifest, state, get_cookie_heade
|
|
|
142
142
|
request.headers.set('accept', '*/*');
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
/** @type {string} */ (event.request.headers.get('accept-language'))
|
|
149
|
-
);
|
|
145
|
+
const accept_language = event.request.headers.get('accept-language');
|
|
146
|
+
if (accept_language && !request.headers.has('accept-language')) {
|
|
147
|
+
request.headers.set('accept-language', accept_language);
|
|
150
148
|
}
|
|
151
149
|
|
|
152
150
|
const response = await internal_fetch(request, options, manifest, state);
|
|
@@ -7,7 +7,7 @@ import { HttpError, Redirect, ActionFailure, SvelteKitError } from '@sveltejs/ki
|
|
|
7
7
|
import { with_request_store, merge_tracing } from '@sveltejs/kit/internal/server';
|
|
8
8
|
import { normalize_error } from '../../../utils/error.js';
|
|
9
9
|
import { is_form_content_type, negotiate } from '../../../utils/http.js';
|
|
10
|
-
import { create_replacer } from '../utils.js';
|
|
10
|
+
import { create_replacer, with_version_header } from '../utils.js';
|
|
11
11
|
import { handle_error_and_jsonify } from '../errors.js';
|
|
12
12
|
import { record_span } from '../../telemetry/record_span.js';
|
|
13
13
|
|
|
@@ -95,7 +95,7 @@ export async function handle_action_json_request(event, event_state, options, se
|
|
|
95
95
|
});
|
|
96
96
|
} else {
|
|
97
97
|
// no data returned — use 204 No Content (without a body, per the spec)
|
|
98
|
-
return new Response(null, { status: 204 });
|
|
98
|
+
return with_version_header(new Response(null, { status: 204 }));
|
|
99
99
|
}
|
|
100
100
|
} catch (e) {
|
|
101
101
|
const err = normalize_error(e);
|
|
@@ -148,7 +148,7 @@ export function action_json_redirect(redirect) {
|
|
|
148
148
|
* @param {ResponseInit} [init]
|
|
149
149
|
*/
|
|
150
150
|
function action_json(data, init) {
|
|
151
|
-
return json(data, init);
|
|
151
|
+
return with_version_header(json(data, init));
|
|
152
152
|
}
|
|
153
153
|
|
|
154
154
|
/**
|
|
@@ -53,19 +53,19 @@ class BaseProvider {
|
|
|
53
53
|
#directives;
|
|
54
54
|
|
|
55
55
|
/** @type {Set<import('types').Csp.Source>} */
|
|
56
|
-
#script_src;
|
|
56
|
+
#script_src = new Set();
|
|
57
57
|
|
|
58
58
|
/** @type {Set<import('types').Csp.Source>} */
|
|
59
|
-
#script_src_elem;
|
|
59
|
+
#script_src_elem = new Set();
|
|
60
60
|
|
|
61
61
|
/** @type {Set<import('types').Csp.Source>} */
|
|
62
|
-
#style_src;
|
|
62
|
+
#style_src = new Set();
|
|
63
63
|
|
|
64
64
|
/** @type {Set<import('types').Csp.Source>} */
|
|
65
|
-
#style_src_attr;
|
|
65
|
+
#style_src_attr = new Set();
|
|
66
66
|
|
|
67
67
|
/** @type {Set<import('types').Csp.Source>} */
|
|
68
|
-
#style_src_elem;
|
|
68
|
+
#style_src_elem = new Set();
|
|
69
69
|
|
|
70
70
|
/** @type {boolean} */
|
|
71
71
|
script_needs_nonce;
|
|
@@ -90,12 +90,6 @@ class BaseProvider {
|
|
|
90
90
|
|
|
91
91
|
const d = this.#directives;
|
|
92
92
|
|
|
93
|
-
this.#script_src = new Set();
|
|
94
|
-
this.#script_src_elem = new Set();
|
|
95
|
-
this.#style_src = new Set();
|
|
96
|
-
this.#style_src_attr = new Set();
|
|
97
|
-
this.#style_src_elem = new Set();
|
|
98
|
-
|
|
99
93
|
const effective_script_src = d['script-src'] || d['default-src'];
|
|
100
94
|
const script_src_elem = d['script-src-elem'];
|
|
101
95
|
const effective_style_src = d['style-src'] || d['default-src'];
|
|
@@ -117,32 +111,25 @@ class BaseProvider {
|
|
|
117
111
|
|
|
118
112
|
// ...and add unsafe-inline so we can inject <style> elements
|
|
119
113
|
// Note that 'unsafe-inline' is ignored if either a hash or nonce value is present in the source list, so we remove those during dev when injecting unsafe-inline
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
d['style-src-elem'] = [
|
|
140
|
-
...style_src_elem.filter(
|
|
141
|
-
(value) => !(value.startsWith('sha256-') || value.startsWith('nonce-'))
|
|
142
|
-
),
|
|
143
|
-
'unsafe-inline'
|
|
144
|
-
];
|
|
145
|
-
}
|
|
114
|
+
/**
|
|
115
|
+
* @template {'style-src' | 'style-src-attr' | 'style-src-elem'} K
|
|
116
|
+
* @param {K} key
|
|
117
|
+
* @param {import('types').CspDirectives[K]} directive
|
|
118
|
+
*/
|
|
119
|
+
const add_unsafe_inline = (key, directive) => {
|
|
120
|
+
if (directive && !directive.includes('unsafe-inline')) {
|
|
121
|
+
d[key] = /** @type {import('types').CspDirectives[K]} */ ([
|
|
122
|
+
...directive.filter(
|
|
123
|
+
(value) => !(value.startsWith('sha256-') || value.startsWith('nonce-'))
|
|
124
|
+
),
|
|
125
|
+
'unsafe-inline'
|
|
126
|
+
]);
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
add_unsafe_inline('style-src', effective_style_src);
|
|
131
|
+
add_unsafe_inline('style-src-attr', style_src_attr);
|
|
132
|
+
add_unsafe_inline('style-src-elem', style_src_elem);
|
|
146
133
|
}
|
|
147
134
|
|
|
148
135
|
/** @param {(import('types').Csp.Source | import('types').Csp.ActionSource)[] | undefined} directive */
|
|
@@ -175,13 +162,16 @@ class BaseProvider {
|
|
|
175
162
|
this.#nonce = nonce;
|
|
176
163
|
}
|
|
177
164
|
|
|
178
|
-
/**
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
165
|
+
/**
|
|
166
|
+
* @param {string} content
|
|
167
|
+
* @returns {`nonce-${string}` | `sha256-${string}`}
|
|
168
|
+
*/
|
|
169
|
+
#get_source(content) {
|
|
170
|
+
return this.#use_hashes ? `sha256-${sha256(content)}` : `nonce-${this.#nonce}`;
|
|
171
|
+
}
|
|
184
172
|
|
|
173
|
+
/** @param {`nonce-${string}` | `sha256-${string}`} source */
|
|
174
|
+
#add_script_source(source) {
|
|
185
175
|
if (this.#script_src_needs_csp) {
|
|
186
176
|
this.#script_src.add(source);
|
|
187
177
|
}
|
|
@@ -191,15 +181,17 @@ class BaseProvider {
|
|
|
191
181
|
}
|
|
192
182
|
}
|
|
193
183
|
|
|
184
|
+
/** @param {string} content */
|
|
185
|
+
add_script(content) {
|
|
186
|
+
if (!this.#script_needs_csp) return;
|
|
187
|
+
|
|
188
|
+
this.#add_script_source(this.#get_source(content));
|
|
189
|
+
}
|
|
190
|
+
|
|
194
191
|
/** @param {`sha256-${string}`[]} hashes */
|
|
195
192
|
add_script_hashes(hashes) {
|
|
196
193
|
for (const hash of hashes) {
|
|
197
|
-
|
|
198
|
-
this.#script_src.add(hash);
|
|
199
|
-
}
|
|
200
|
-
if (this.#script_src_elem_needs_csp) {
|
|
201
|
-
this.#script_src_elem.add(hash);
|
|
202
|
-
}
|
|
194
|
+
this.#add_script_source(hash);
|
|
203
195
|
}
|
|
204
196
|
}
|
|
205
197
|
|
|
@@ -207,8 +199,7 @@ class BaseProvider {
|
|
|
207
199
|
add_style(content) {
|
|
208
200
|
if (!this.#style_needs_csp) return;
|
|
209
201
|
|
|
210
|
-
|
|
211
|
-
const source = this.#use_hashes ? `sha256-${sha256(content)}` : `nonce-${this.#nonce}`;
|
|
202
|
+
const source = this.#get_source(content);
|
|
212
203
|
|
|
213
204
|
if (this.#style_src_needs_csp) {
|
|
214
205
|
this.#style_src.add(source);
|
|
@@ -251,40 +242,34 @@ class BaseProvider {
|
|
|
251
242
|
|
|
252
243
|
const directives = { ...this.#directives };
|
|
253
244
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
]
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
]
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
if (this.#script_src_elem.size > 0) {
|
|
283
|
-
directives['script-src-elem'] = [
|
|
284
|
-
...(directives['script-src-elem'] || []),
|
|
285
|
-
...this.#script_src_elem
|
|
286
|
-
];
|
|
287
|
-
}
|
|
245
|
+
/**
|
|
246
|
+
* @template {'style-src' | 'style-src-attr' | 'style-src-elem' | 'script-src' | 'script-src-elem'} K
|
|
247
|
+
* @param {K} key
|
|
248
|
+
* @param {Set<import('types').Csp.Source>} sources
|
|
249
|
+
* @param {import('types').CspDirectives[K]} [base]
|
|
250
|
+
*/
|
|
251
|
+
const merge_sources = (key, sources, base) => {
|
|
252
|
+
if (sources.size > 0) {
|
|
253
|
+
directives[key] = /** @type {import('types').CspDirectives[K]} */ ([
|
|
254
|
+
...(base || []),
|
|
255
|
+
...sources
|
|
256
|
+
]);
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
merge_sources(
|
|
261
|
+
'style-src',
|
|
262
|
+
this.#style_src,
|
|
263
|
+
directives['style-src'] || directives['default-src']
|
|
264
|
+
);
|
|
265
|
+
merge_sources('style-src-attr', this.#style_src_attr, directives['style-src-attr']);
|
|
266
|
+
merge_sources('style-src-elem', this.#style_src_elem, directives['style-src-elem']);
|
|
267
|
+
merge_sources(
|
|
268
|
+
'script-src',
|
|
269
|
+
this.#script_src,
|
|
270
|
+
directives['script-src'] || directives['default-src']
|
|
271
|
+
);
|
|
272
|
+
merge_sources('script-src-elem', this.#script_src_elem, directives['script-src-elem']);
|
|
288
273
|
|
|
289
274
|
for (const key in directives) {
|
|
290
275
|
if (is_meta && (key === 'frame-ancestors' || key === 'report-uri' || key === 'sandbox')) {
|
|
@@ -300,13 +285,11 @@ class BaseProvider {
|
|
|
300
285
|
|
|
301
286
|
const directive = [key];
|
|
302
287
|
if (Array.isArray(value)) {
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
}
|
|
309
|
-
});
|
|
288
|
+
for (const source of value) {
|
|
289
|
+
directive.push(
|
|
290
|
+
quoted.has(source) || crypto_pattern.test(source) ? `'${source}'` : source
|
|
291
|
+
);
|
|
292
|
+
}
|
|
310
293
|
}
|
|
311
294
|
|
|
312
295
|
header.push(directive.join(' '));
|
|
@@ -337,17 +320,17 @@ class CspReportOnlyProvider extends BaseProvider {
|
|
|
337
320
|
constructor(use_hashes, directives, nonce) {
|
|
338
321
|
super(use_hashes, directives, nonce);
|
|
339
322
|
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
323
|
+
// If we're generating content-security-policy-report-only,
|
|
324
|
+
// if there are any directives, we need a report-uri or report-to (or both)
|
|
325
|
+
// else it's just an expensive noop.
|
|
326
|
+
if (
|
|
327
|
+
Object.values(directives).some((v) => !!v) &&
|
|
328
|
+
!directives['report-to']?.length &&
|
|
329
|
+
!directives['report-uri']?.length
|
|
330
|
+
) {
|
|
331
|
+
throw Error(
|
|
332
|
+
'`content-security-policy-report-only` must be specified with either the `report-to` or `report-uri` directives, or both'
|
|
333
|
+
);
|
|
351
334
|
}
|
|
352
335
|
}
|
|
353
336
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/** @import { ActionResult, RequestEvent, SSRManifest } from '@sveltejs/kit' */
|
|
3
3
|
/** @import { PageNodeIndexes, RequestState, RequiredResolveOptions, ServerDataNode, SSRNode, SSROptions, SSRState } from 'types' */
|
|
4
4
|
import { text } from '@sveltejs/kit';
|
|
5
|
-
import {
|
|
5
|
+
import { Redirect } from '@sveltejs/kit/internal';
|
|
6
6
|
import { compact } from '../../../utils/array.js';
|
|
7
7
|
import { get_status, normalize_error } from '../../../utils/error.js';
|
|
8
8
|
import { noop } from '../../../utils/functions.js';
|
|
@@ -386,7 +386,6 @@ export async function render_page(
|
|
|
386
386
|
options,
|
|
387
387
|
manifest,
|
|
388
388
|
state,
|
|
389
|
-
status: e instanceof HttpError ? e.status : 500,
|
|
390
389
|
error: e,
|
|
391
390
|
resolve_opts
|
|
392
391
|
});
|
|
@@ -334,14 +334,24 @@ export function create_universal_fetch(event, state, fetched, csr, resolve_opts)
|
|
|
334
334
|
);
|
|
335
335
|
}
|
|
336
336
|
|
|
337
|
+
const request_body =
|
|
338
|
+
input instanceof Request && cloned_body
|
|
339
|
+
? await stream_to_string(cloned_body)
|
|
340
|
+
: init?.body;
|
|
341
|
+
|
|
342
|
+
if (
|
|
343
|
+
request_body &&
|
|
344
|
+
typeof request_body !== 'string' &&
|
|
345
|
+
!ArrayBuffer.isView(request_body)
|
|
346
|
+
) {
|
|
347
|
+
// requests whose body can't be hashed aren't serialized — the browser repeats the fetch
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
|
|
337
351
|
fetched.push({
|
|
338
352
|
url: same_origin ? url.href.slice(event.url.origin.length) : url.href,
|
|
339
353
|
method: event.request.method,
|
|
340
|
-
request_body: /** @type {string | ArrayBufferView | undefined} */ (
|
|
341
|
-
input instanceof Request && cloned_body
|
|
342
|
-
? await stream_to_string(cloned_body)
|
|
343
|
-
: init?.body
|
|
344
|
-
),
|
|
354
|
+
request_body: /** @type {string | ArrayBufferView | null | undefined} */ (request_body),
|
|
345
355
|
request_headers: cloned_headers,
|
|
346
356
|
response_body: body,
|
|
347
357
|
response,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @import {
|
|
1
|
+
/** @import { Component } from 'svelte'; */
|
|
2
2
|
import * as devalue from 'devalue';
|
|
3
3
|
import { DEV } from 'esm-env';
|
|
4
4
|
import { isRedirect, text } from '@sveltejs/kit';
|
|
@@ -20,6 +20,7 @@ import * as env from '__sveltekit/env';
|
|
|
20
20
|
import { collect_remote_data } from '../remote-functions.js';
|
|
21
21
|
import Root from '../../components/root.svelte';
|
|
22
22
|
import { render } from 'svelte/server';
|
|
23
|
+
import { Props, RenderNode } from '../../props.svelte.js';
|
|
23
24
|
|
|
24
25
|
// TODO rename this function/module
|
|
25
26
|
|
|
@@ -134,25 +135,29 @@ export async function render_response({
|
|
|
134
135
|
}
|
|
135
136
|
|
|
136
137
|
if (page_config.ssr) {
|
|
137
|
-
|
|
138
|
-
const props = {
|
|
139
|
-
components: [],
|
|
140
|
-
resetters: [],
|
|
141
|
-
form: form_value,
|
|
142
|
-
tree: /** @type {RenderNode} */ ({}),
|
|
138
|
+
const page = {
|
|
143
139
|
error,
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
state: {}
|
|
153
|
-
}
|
|
140
|
+
params: /** @type {Record<string, any>} */ (event.params),
|
|
141
|
+
route: event.route,
|
|
142
|
+
status,
|
|
143
|
+
url: event.url,
|
|
144
|
+
data: {},
|
|
145
|
+
form: form_value,
|
|
146
|
+
shallow: null,
|
|
147
|
+
state: {}
|
|
154
148
|
};
|
|
155
149
|
|
|
150
|
+
const props = new Props({
|
|
151
|
+
page,
|
|
152
|
+
tree: new RenderNode(
|
|
153
|
+
// TODO tidy up
|
|
154
|
+
/** @type {Component} */ (await branch[0].node.component?.()),
|
|
155
|
+
/** @type {Component} */ (error_components?.[1])
|
|
156
|
+
),
|
|
157
|
+
form: form_value,
|
|
158
|
+
error: error ?? undefined
|
|
159
|
+
});
|
|
160
|
+
|
|
156
161
|
let current_node = props.tree;
|
|
157
162
|
let data = props.page.data;
|
|
158
163
|
|
|
@@ -161,16 +166,14 @@ export async function render_response({
|
|
|
161
166
|
|
|
162
167
|
data = { ...data, ...node.data };
|
|
163
168
|
|
|
164
|
-
// TODO this is undefined sometimes... where does the default error component come from?
|
|
165
|
-
const error = error_components?.slice(0, i + 1).findLast((x) => x);
|
|
166
|
-
|
|
167
|
-
current_node.error = error;
|
|
168
|
-
current_node.component = await node.node.component?.();
|
|
169
169
|
current_node.data = data;
|
|
170
170
|
|
|
171
171
|
if (i < branch.length - 1) {
|
|
172
|
-
current_node.child =
|
|
173
|
-
|
|
172
|
+
current_node = current_node.child = new RenderNode(
|
|
173
|
+
// TODO tidy up
|
|
174
|
+
/** @type {Component} */ (await branch[i + 1].node.component?.()),
|
|
175
|
+
/** @type {Component} */ (error_components?.slice(0, i + 2).findLast((x) => x))
|
|
176
|
+
);
|
|
174
177
|
}
|
|
175
178
|
}
|
|
176
179
|
|
|
@@ -304,6 +307,19 @@ export async function render_response({
|
|
|
304
307
|
head.add_style(style, attributes);
|
|
305
308
|
}
|
|
306
309
|
|
|
310
|
+
/**
|
|
311
|
+
* see the `output.linkHeaderPreload` option for details on why we have multiple options here
|
|
312
|
+
* @param {string} path
|
|
313
|
+
* @param {string[]} attributes
|
|
314
|
+
*/
|
|
315
|
+
const add_preload = (path, attributes) => {
|
|
316
|
+
if (options.link_header_preload && !state.prerendering) {
|
|
317
|
+
link_headers.add(`<${encodeURI(path)}>; ${attributes.join('; ')}; nopush`);
|
|
318
|
+
} else {
|
|
319
|
+
head.add_link_tag(path, attributes);
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
|
|
307
323
|
for (const dep of stylesheets) {
|
|
308
324
|
const path = prefixed(dep);
|
|
309
325
|
|
|
@@ -328,18 +344,7 @@ export async function render_response({
|
|
|
328
344
|
if (resolve_opts.preload({ type: 'font', path })) {
|
|
329
345
|
const ext = dep.slice(dep.lastIndexOf('.') + 1);
|
|
330
346
|
|
|
331
|
-
|
|
332
|
-
link_headers.add(
|
|
333
|
-
`<${encodeURI(path)}>; rel="preload"; as="font"; type="font/${ext}"; crossorigin; nopush`
|
|
334
|
-
);
|
|
335
|
-
} else {
|
|
336
|
-
head.add_link_tag(path, [
|
|
337
|
-
'rel="preload"',
|
|
338
|
-
'as="font"',
|
|
339
|
-
`type="font/${ext}"`,
|
|
340
|
-
'crossorigin'
|
|
341
|
-
]);
|
|
342
|
-
}
|
|
347
|
+
add_preload(path, ['rel="preload"', 'as="font"', `type="font/${ext}"`, 'crossorigin']);
|
|
343
348
|
}
|
|
344
349
|
}
|
|
345
350
|
|
|
@@ -368,23 +373,12 @@ export async function render_response({
|
|
|
368
373
|
}
|
|
369
374
|
|
|
370
375
|
if (!client.inline) {
|
|
371
|
-
const
|
|
372
|
-
|
|
373
|
-
);
|
|
374
|
-
|
|
375
|
-
/** @type {(path: string) => void} */
|
|
376
|
-
let add_preload;
|
|
376
|
+
for (const dep of modulepreloads) {
|
|
377
|
+
const path = prefixed(dep);
|
|
377
378
|
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
link_headers.add(`<${encodeURI(path)}>; rel="modulepreload"; nopush`);
|
|
382
|
-
} else {
|
|
383
|
-
add_preload = (path) => head.add_link_tag(path, ['rel="modulepreload"']);
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
for (const path of included_modulepreloads) {
|
|
387
|
-
add_preload(path);
|
|
379
|
+
if (resolve_opts.preload({ type: 'js', path })) {
|
|
380
|
+
add_preload(path, ['rel="modulepreload"']);
|
|
381
|
+
}
|
|
388
382
|
}
|
|
389
383
|
}
|
|
390
384
|
|
|
@@ -17,7 +17,6 @@ import { server_data_serializer } from './data_serializer.js';
|
|
|
17
17
|
* options: import('types').SSROptions;
|
|
18
18
|
* manifest: import('@sveltejs/kit').SSRManifest;
|
|
19
19
|
* state: import('types').SSRState;
|
|
20
|
-
* status: number;
|
|
21
20
|
* error: unknown;
|
|
22
21
|
* resolve_opts: import('types').RequiredResolveOptions;
|
|
23
22
|
* }} opts
|
|
@@ -28,14 +27,13 @@ export async function respond_with_error({
|
|
|
28
27
|
options,
|
|
29
28
|
manifest,
|
|
30
29
|
state,
|
|
31
|
-
status,
|
|
32
30
|
error,
|
|
33
31
|
resolve_opts
|
|
34
32
|
}) {
|
|
35
33
|
// reroute to the fallback page to prevent an infinite chain of requests.
|
|
36
34
|
if (event.request.headers.get('x-sveltekit-error')) {
|
|
37
35
|
const transformed = await handle_error_and_jsonify(event, event_state, options, error);
|
|
38
|
-
return static_error_page(options, status, transformed.message);
|
|
36
|
+
return static_error_page(options, transformed.status, transformed.message);
|
|
39
37
|
}
|
|
40
38
|
|
|
41
39
|
/** @type {import('./types.js').Fetched[]} */
|