@sveltejs/kit 1.27.4 → 1.27.6
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 +3 -4
- package/src/core/config/default-error.html +13 -3
- package/src/core/config/options.js +1 -1
- package/src/core/sync/create_manifest_data/index.js +1 -1
- package/src/core/sync/write_root.js +42 -13
- package/src/core/sync/write_tsconfig.js +5 -3
- package/src/exports/public.d.ts +8 -8
- package/src/exports/vite/build/build_server.js +1 -1
- package/src/exports/vite/graph_analysis/index.js +1 -1
- package/src/exports/vite/index.js +4 -4
- package/src/exports/vite/preview/index.js +1 -4
- package/src/runtime/client/client.js +54 -47
- package/src/runtime/client/parse.js +1 -1
- package/src/runtime/client/singletons.js +2 -2
- package/src/runtime/client/start.js +2 -2
- package/src/runtime/client/types.d.ts +2 -2
- package/src/runtime/client/utils.js +4 -2
- package/src/runtime/components/layout.svelte +1 -1
- package/src/runtime/server/cookie.js +2 -2
- package/src/runtime/server/page/csp.js +2 -2
- package/src/runtime/server/page/index.js +2 -2
- package/src/runtime/server/page/load_data.js +6 -6
- package/src/runtime/server/page/render.js +2 -2
- package/src/runtime/server/page/respond_with_error.js +1 -1
- package/src/runtime/server/respond.js +3 -3
- package/src/types/internal.d.ts +1 -1
- package/src/version.js +1 -1
- package/types/index.d.ts +8 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sveltejs/kit",
|
|
3
|
-
"version": "1.27.
|
|
3
|
+
"version": "1.27.6",
|
|
4
4
|
"description": "The fastest way to build Svelte apps",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -32,7 +32,6 @@
|
|
|
32
32
|
"@types/sade": "^1.7.4",
|
|
33
33
|
"@types/set-cookie-parser": "^2.4.2",
|
|
34
34
|
"dts-buddy": "^0.2.4",
|
|
35
|
-
"marked": "^9.0.0",
|
|
36
35
|
"rollup": "^3.29.4",
|
|
37
36
|
"svelte": "^4.2.2",
|
|
38
37
|
"svelte-preprocess": "^5.0.4",
|
|
@@ -84,10 +83,10 @@
|
|
|
84
83
|
"node": "^16.14 || >=18"
|
|
85
84
|
},
|
|
86
85
|
"scripts": {
|
|
87
|
-
"lint": "prettier --
|
|
86
|
+
"lint": "prettier --config ../../.prettierrc --check .",
|
|
88
87
|
"check": "tsc",
|
|
89
88
|
"check:all": "tsc && pnpm -r --filter=\"./**\" check",
|
|
90
|
-
"format": "prettier --
|
|
89
|
+
"format": "prettier --config ../../.prettierrc --write .",
|
|
91
90
|
"test": "pnpm test:unit && pnpm test:integration",
|
|
92
91
|
"test:integration": "pnpm -r --workspace-concurrency 1 --filter=\"./test/**\" test",
|
|
93
92
|
"test:cross-platform:dev": "pnpm -r --workspace-concurrency 1 --filter=\"./test/**\" test:cross-platform:dev",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<!
|
|
1
|
+
<!doctype html>
|
|
2
2
|
<html lang="en">
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="utf-8" />
|
|
@@ -11,8 +11,18 @@
|
|
|
11
11
|
--divider: #ccc;
|
|
12
12
|
background: var(--bg);
|
|
13
13
|
color: var(--fg);
|
|
14
|
-
font-family:
|
|
15
|
-
|
|
14
|
+
font-family:
|
|
15
|
+
system-ui,
|
|
16
|
+
-apple-system,
|
|
17
|
+
BlinkMacSystemFont,
|
|
18
|
+
'Segoe UI',
|
|
19
|
+
Roboto,
|
|
20
|
+
Oxygen,
|
|
21
|
+
Ubuntu,
|
|
22
|
+
Cantarell,
|
|
23
|
+
'Open Sans',
|
|
24
|
+
'Helvetica Neue',
|
|
25
|
+
sans-serif;
|
|
16
26
|
display: flex;
|
|
17
27
|
align-items: center;
|
|
18
28
|
justify-content: center;
|
|
@@ -444,7 +444,7 @@ function create_routes_and_nodes(cwd, config, fallback) {
|
|
|
444
444
|
* @param {string} file
|
|
445
445
|
* @param {string[]} component_extensions
|
|
446
446
|
* @param {string[]} module_extensions
|
|
447
|
-
* @returns {import('./types').RouteFile}
|
|
447
|
+
* @returns {import('./types.js').RouteFile}
|
|
448
448
|
*/
|
|
449
449
|
function analyze(project_relative, file, component_extensions, module_extensions) {
|
|
450
450
|
const component_extension = component_extensions.find((ext) => file.endsWith(ext));
|
|
@@ -40,28 +40,57 @@ export function write_root(manifest_data, output) {
|
|
|
40
40
|
dedent`
|
|
41
41
|
<!-- This file is generated by @sveltejs/kit — do not edit it! -->
|
|
42
42
|
<script>
|
|
43
|
-
import { setContext, afterUpdate, onMount, tick } from 'svelte';
|
|
43
|
+
import { setContext, ${isSvelte5Plus() ? '' : 'afterUpdate, '}onMount, tick } from 'svelte';
|
|
44
44
|
import { browser } from '$app/environment';
|
|
45
45
|
|
|
46
46
|
// stores
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
47
|
+
${
|
|
48
|
+
isSvelte5Plus()
|
|
49
|
+
? dedent`
|
|
50
|
+
let { stores, page, constructors, components = [], form, ${levels
|
|
51
|
+
.map((l) => `data_${l} = null`)
|
|
52
|
+
.join(', ')} } = $props();
|
|
53
|
+
`
|
|
54
|
+
: dedent`
|
|
55
|
+
export let stores;
|
|
56
|
+
export let page;
|
|
57
|
+
|
|
58
|
+
export let constructors;
|
|
59
|
+
export let components = [];
|
|
60
|
+
export let form;
|
|
61
|
+
${levels.map((l) => `export let data_${l} = null;`).join('\n')}
|
|
62
|
+
`
|
|
63
|
+
}
|
|
54
64
|
|
|
55
65
|
if (!browser) {
|
|
56
66
|
setContext('__svelte__', stores);
|
|
57
67
|
}
|
|
58
68
|
|
|
59
|
-
|
|
60
|
-
|
|
69
|
+
${
|
|
70
|
+
isSvelte5Plus()
|
|
71
|
+
? dedent`
|
|
72
|
+
if (browser) {
|
|
73
|
+
$effect.pre(() => stores.page.set(page));
|
|
74
|
+
} else {
|
|
75
|
+
stores.page.set(page);
|
|
76
|
+
}
|
|
77
|
+
`
|
|
78
|
+
: '$: stores.page.set(page);'
|
|
79
|
+
}
|
|
80
|
+
${
|
|
81
|
+
isSvelte5Plus()
|
|
82
|
+
? dedent`
|
|
83
|
+
$effect(() => {
|
|
84
|
+
stores;page;constructors;components;form;${levels.map((l) => `data_${l}`).join(';')};
|
|
85
|
+
stores.page.notify();
|
|
86
|
+
});
|
|
87
|
+
`
|
|
88
|
+
: 'afterUpdate(stores.page.notify);'
|
|
89
|
+
}
|
|
61
90
|
|
|
62
|
-
let mounted = false;
|
|
63
|
-
let navigated = false;
|
|
64
|
-
let title = null;
|
|
91
|
+
let mounted = ${isSvelte5Plus() ? '$state(false)' : 'false'};
|
|
92
|
+
let navigated = ${isSvelte5Plus() ? '$state(false)' : 'false'};
|
|
93
|
+
let title = ${isSvelte5Plus() ? '$state(null)' : 'null'};
|
|
65
94
|
|
|
66
95
|
onMount(() => {
|
|
67
96
|
const unsubscribe = stores.page.subscribe(() => {
|
|
@@ -88,6 +88,7 @@ export function get_tsconfig(kit, include_base_url) {
|
|
|
88
88
|
const include = new Set([
|
|
89
89
|
'ambient.d.ts',
|
|
90
90
|
'./types/**/$types.d.ts',
|
|
91
|
+
config_relative('vite.config.js'),
|
|
91
92
|
config_relative('vite.config.ts')
|
|
92
93
|
]);
|
|
93
94
|
// TODO(v2): find a better way to include all src files. We can't just use routes/lib only because
|
|
@@ -138,8 +139,9 @@ export function get_tsconfig(kit, include_base_url) {
|
|
|
138
139
|
// This is required for svelte-package to work as expected
|
|
139
140
|
// Can be overwritten
|
|
140
141
|
lib: ['esnext', 'DOM', 'DOM.Iterable'],
|
|
141
|
-
moduleResolution: 'node',
|
|
142
|
+
moduleResolution: 'node', // TODO change to "bundler" in SvelteKit v2
|
|
142
143
|
module: 'esnext',
|
|
144
|
+
noEmit: true, // prevent tsconfig error "overwriting input files" - Vite handles the build and ignores this
|
|
143
145
|
target: 'esnext',
|
|
144
146
|
|
|
145
147
|
// TODO(v2): use the new flag verbatimModuleSyntax instead (requires support by Vite/Esbuild)
|
|
@@ -180,8 +182,8 @@ function validate_user_config(kit, cwd, out, config) {
|
|
|
180
182
|
typeof extend === 'string'
|
|
181
183
|
? path.resolve(cwd, extend) === out
|
|
182
184
|
: Array.isArray(extend)
|
|
183
|
-
|
|
184
|
-
|
|
185
|
+
? extend.some((e) => path.resolve(cwd, e) === out)
|
|
186
|
+
: false;
|
|
185
187
|
|
|
186
188
|
const options = config.options.compilerOptions || {};
|
|
187
189
|
|
package/src/exports/public.d.ts
CHANGED
|
@@ -42,12 +42,12 @@ export interface Adapter {
|
|
|
42
42
|
type AwaitedPropertiesUnion<input extends Record<string, any> | void> = input extends void
|
|
43
43
|
? undefined // needs to be undefined, because void will break intellisense
|
|
44
44
|
: input extends Record<string, any>
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
45
|
+
? {
|
|
46
|
+
[key in keyof input]: Awaited<input[key]>;
|
|
47
|
+
}
|
|
48
|
+
: {} extends input // handles the any case
|
|
49
|
+
? input
|
|
50
|
+
: unknown;
|
|
51
51
|
|
|
52
52
|
export type AwaitedProperties<input extends Record<string, any> | void> =
|
|
53
53
|
AwaitedPropertiesUnion<input> extends Record<string, any>
|
|
@@ -70,8 +70,8 @@ type OptionalUnion<
|
|
|
70
70
|
type UnpackValidationError<T> = T extends ActionFailure<infer X>
|
|
71
71
|
? X
|
|
72
72
|
: T extends void
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
? undefined // needs to be undefined, because void will corrupt union type
|
|
74
|
+
: T;
|
|
75
75
|
|
|
76
76
|
/**
|
|
77
77
|
* This object is passed to the `adapt` function of adapters.
|
|
@@ -10,7 +10,7 @@ import { normalizePath } from 'vite';
|
|
|
10
10
|
* @param {import('types').ManifestData} manifest_data
|
|
11
11
|
* @param {import('vite').Manifest} server_manifest
|
|
12
12
|
* @param {import('vite').Manifest | null} client_manifest
|
|
13
|
-
* @param {import('
|
|
13
|
+
* @param {import('vite').Rollup.OutputAsset[] | null} css
|
|
14
14
|
*/
|
|
15
15
|
export function build_server_nodes(out, kit, manifest_data, server_manifest, client_manifest, css) {
|
|
16
16
|
mkdirp(`${out}/server/nodes`);
|
|
@@ -25,7 +25,7 @@ export function is_illegal(id, dirs) {
|
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* Creates a guard that checks that no id imports a module that is not allowed to be imported into client-side code.
|
|
28
|
-
* @param {import('
|
|
28
|
+
* @param {import('vite').Rollup.PluginContext} context
|
|
29
29
|
* @param {{ cwd: string; lib: string }} paths
|
|
30
30
|
*/
|
|
31
31
|
export function module_guard(context, { cwd, lib }) {
|
|
@@ -30,7 +30,7 @@ export { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
|
|
|
30
30
|
|
|
31
31
|
const cwd = process.cwd();
|
|
32
32
|
|
|
33
|
-
/** @type {import('./types').EnforcedConfig} */
|
|
33
|
+
/** @type {import('./types.js').EnforcedConfig} */
|
|
34
34
|
const enforced_config = {
|
|
35
35
|
appType: true,
|
|
36
36
|
base: true,
|
|
@@ -702,7 +702,7 @@ function kit({ svelte_config }) {
|
|
|
702
702
|
|
|
703
703
|
secondary_build_started = true;
|
|
704
704
|
|
|
705
|
-
const { output } = /** @type {import('
|
|
705
|
+
const { output } = /** @type {import('vite').Rollup.RollupOutput} */ (
|
|
706
706
|
await vite.build({
|
|
707
707
|
configFile: vite_config.configFile,
|
|
708
708
|
// CLI args
|
|
@@ -742,7 +742,7 @@ function kit({ svelte_config }) {
|
|
|
742
742
|
};
|
|
743
743
|
|
|
744
744
|
const css = output.filter(
|
|
745
|
-
/** @type {(value: any) => value is import('
|
|
745
|
+
/** @type {(value: any) => value is import('vite').Rollup.OutputAsset} */
|
|
746
746
|
(value) => value.type === 'asset' && value.fileName.endsWith('.css')
|
|
747
747
|
);
|
|
748
748
|
|
|
@@ -863,7 +863,7 @@ function warn_overridden_config(config, resolved_config) {
|
|
|
863
863
|
/**
|
|
864
864
|
* @param {Record<string, any>} config
|
|
865
865
|
* @param {Record<string, any>} resolved_config
|
|
866
|
-
* @param {import('./types').EnforcedConfig} enforced_config
|
|
866
|
+
* @param {import('./types.js').EnforcedConfig} enforced_config
|
|
867
867
|
* @param {string} path
|
|
868
868
|
* @param {string[]} out used locally to compute the return value
|
|
869
869
|
*/
|
|
@@ -15,10 +15,7 @@ import { not_found } from '../utils.js';
|
|
|
15
15
|
/** @typedef {(req: Req, res: Res, next: () => void) => void} Handler */
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
|
-
* @param {{
|
|
19
|
-
* middlewares: import('connect').Server;
|
|
20
|
-
* httpServer: import('http').Server;
|
|
21
|
-
* }} vite
|
|
18
|
+
* @param {{ middlewares: import('connect').Server }} vite
|
|
22
19
|
* @param {import('vite').ResolvedConfig} vite_config
|
|
23
20
|
* @param {import('types').ValidatedConfig} svelte_config
|
|
24
21
|
*/
|
|
@@ -22,7 +22,8 @@ import {
|
|
|
22
22
|
get_link_info,
|
|
23
23
|
get_router_options,
|
|
24
24
|
is_external_url,
|
|
25
|
-
scroll_state
|
|
25
|
+
scroll_state,
|
|
26
|
+
origin
|
|
26
27
|
} from './utils.js';
|
|
27
28
|
|
|
28
29
|
import { base } from '__sveltekit/paths';
|
|
@@ -55,9 +56,20 @@ function update_scroll_positions(index) {
|
|
|
55
56
|
}
|
|
56
57
|
|
|
57
58
|
/**
|
|
58
|
-
*
|
|
59
|
+
* Loads `href` the old-fashioned way, with a full page reload.
|
|
60
|
+
* Returns a `Promise` that never resolves (to prevent any
|
|
61
|
+
* subsequent work, e.g. history manipulation, from happening)
|
|
62
|
+
* @param {URL} url
|
|
63
|
+
*/
|
|
64
|
+
function native_navigation(url) {
|
|
65
|
+
location.href = url.href;
|
|
66
|
+
return new Promise(() => {});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @param {import('./types.js').SvelteKitApp} app
|
|
59
71
|
* @param {HTMLElement} target
|
|
60
|
-
* @returns {import('./types').Client}
|
|
72
|
+
* @returns {import('./types.js').Client}
|
|
61
73
|
*/
|
|
62
74
|
export function create_client(app, target) {
|
|
63
75
|
const routes = parse(app);
|
|
@@ -82,7 +94,7 @@ export function create_client(app, target) {
|
|
|
82
94
|
*/
|
|
83
95
|
const components = [];
|
|
84
96
|
|
|
85
|
-
/** @type {{id: string, promise: Promise<import('./types').NavigationResult>} | null} */
|
|
97
|
+
/** @type {{id: string, promise: Promise<import('./types.js').NavigationResult>} | null} */
|
|
86
98
|
let load_cache = null;
|
|
87
99
|
|
|
88
100
|
const callbacks = {
|
|
@@ -96,7 +108,7 @@ export function create_client(app, target) {
|
|
|
96
108
|
after_navigate: []
|
|
97
109
|
};
|
|
98
110
|
|
|
99
|
-
/** @type {import('./types').NavigationState} */
|
|
111
|
+
/** @type {import('./types.js').NavigationState} */
|
|
100
112
|
let current = {
|
|
101
113
|
branch: [],
|
|
102
114
|
error: null,
|
|
@@ -247,7 +259,7 @@ export function create_client(app, target) {
|
|
|
247
259
|
});
|
|
248
260
|
}
|
|
249
261
|
|
|
250
|
-
/** @param {import('./types').NavigationIntent} intent */
|
|
262
|
+
/** @param {import('./types.js').NavigationIntent} intent */
|
|
251
263
|
async function preload_data(intent) {
|
|
252
264
|
load_cache = {
|
|
253
265
|
id: intent.id,
|
|
@@ -274,7 +286,7 @@ export function create_client(app, target) {
|
|
|
274
286
|
await Promise.all(promises);
|
|
275
287
|
}
|
|
276
288
|
|
|
277
|
-
/** @param {import('./types').NavigationFinished} result */
|
|
289
|
+
/** @param {import('./types.js').NavigationFinished} result */
|
|
278
290
|
function initialize(result) {
|
|
279
291
|
if (DEV && result.state.error && document.querySelector('vite-error-overlay')) return;
|
|
280
292
|
|
|
@@ -315,7 +327,7 @@ export function create_client(app, target) {
|
|
|
315
327
|
* @param {{
|
|
316
328
|
* url: URL;
|
|
317
329
|
* params: Record<string, string>;
|
|
318
|
-
* branch: Array<import('./types').BranchNode | undefined>;
|
|
330
|
+
* branch: Array<import('./types.js').BranchNode | undefined>;
|
|
319
331
|
* status: number;
|
|
320
332
|
* error: App.Error | null;
|
|
321
333
|
* route: import('types').CSRRoute | null;
|
|
@@ -340,7 +352,7 @@ export function create_client(app, target) {
|
|
|
340
352
|
// eslint-disable-next-line
|
|
341
353
|
url.search = url.search; // turn `/?` into `/`
|
|
342
354
|
|
|
343
|
-
/** @type {import('./types').NavigationFinished} */
|
|
355
|
+
/** @type {import('./types.js').NavigationFinished} */
|
|
344
356
|
const result = {
|
|
345
357
|
type: 'loaded',
|
|
346
358
|
state: {
|
|
@@ -417,9 +429,9 @@ export function create_client(app, target) {
|
|
|
417
429
|
* url: URL;
|
|
418
430
|
* params: Record<string, string>;
|
|
419
431
|
* route: { id: string | null };
|
|
420
|
-
* server_data_node: import('./types').DataNode | null;
|
|
432
|
+
* server_data_node: import('./types.js').DataNode | null;
|
|
421
433
|
* }} options
|
|
422
|
-
* @returns {Promise<import('./types').BranchNode>}
|
|
434
|
+
* @returns {Promise<import('./types.js').BranchNode>}
|
|
423
435
|
*/
|
|
424
436
|
async function load_node({ loader, parent, url, params, route, server_data_node }) {
|
|
425
437
|
/** @type {Record<string, any> | null} */
|
|
@@ -534,10 +546,10 @@ export function create_client(app, target) {
|
|
|
534
546
|
typeof data !== 'object'
|
|
535
547
|
? `a ${typeof data}`
|
|
536
548
|
: data instanceof Response
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
549
|
+
? 'a Response object'
|
|
550
|
+
: Array.isArray(data)
|
|
551
|
+
? 'an array'
|
|
552
|
+
: 'a non-plain object'
|
|
541
553
|
}, but must return a plain object at the top level (i.e. \`return {...}\`)`
|
|
542
554
|
);
|
|
543
555
|
}
|
|
@@ -589,8 +601,8 @@ export function create_client(app, target) {
|
|
|
589
601
|
|
|
590
602
|
/**
|
|
591
603
|
* @param {import('types').ServerDataNode | import('types').ServerDataSkippedNode | null} node
|
|
592
|
-
* @param {import('./types').DataNode | null} [previous]
|
|
593
|
-
* @returns {import('./types').DataNode | null}
|
|
604
|
+
* @param {import('./types.js').DataNode | null} [previous]
|
|
605
|
+
* @returns {import('./types.js').DataNode | null}
|
|
594
606
|
*/
|
|
595
607
|
function create_data_node(node, previous) {
|
|
596
608
|
if (node?.type === 'data') return node;
|
|
@@ -599,8 +611,8 @@ export function create_client(app, target) {
|
|
|
599
611
|
}
|
|
600
612
|
|
|
601
613
|
/**
|
|
602
|
-
* @param {import('./types').NavigationIntent} intent
|
|
603
|
-
* @returns {Promise<import('./types').NavigationResult>}
|
|
614
|
+
* @param {import('./types.js').NavigationIntent} intent
|
|
615
|
+
* @returns {Promise<import('./types.js').NavigationResult>}
|
|
604
616
|
*/
|
|
605
617
|
async function load_route({ id, invalidating, url, params, route }) {
|
|
606
618
|
if (load_cache?.id === id) {
|
|
@@ -664,7 +676,7 @@ export function create_client(app, target) {
|
|
|
664
676
|
const branch_promises = loaders.map(async (loader, i) => {
|
|
665
677
|
if (!loader) return;
|
|
666
678
|
|
|
667
|
-
/** @type {import('./types').BranchNode | undefined} */
|
|
679
|
+
/** @type {import('./types.js').BranchNode | undefined} */
|
|
668
680
|
const previous = current.branch[i];
|
|
669
681
|
|
|
670
682
|
const server_data_node = server_data_nodes?.[i];
|
|
@@ -707,7 +719,7 @@ export function create_client(app, target) {
|
|
|
707
719
|
// if we don't do this, rejections will be unhandled
|
|
708
720
|
for (const p of branch_promises) p.catch(() => {});
|
|
709
721
|
|
|
710
|
-
/** @type {Array<import('./types').BranchNode | undefined>} */
|
|
722
|
+
/** @type {Array<import('./types.js').BranchNode | undefined>} */
|
|
711
723
|
const branch = [];
|
|
712
724
|
|
|
713
725
|
for (let i = 0; i < loaders.length; i += 1) {
|
|
@@ -781,9 +793,9 @@ export function create_client(app, target) {
|
|
|
781
793
|
|
|
782
794
|
/**
|
|
783
795
|
* @param {number} i Start index to backtrack from
|
|
784
|
-
* @param {Array<import('./types').BranchNode | undefined>} branch Branch to backtrack
|
|
796
|
+
* @param {Array<import('./types.js').BranchNode | undefined>} branch Branch to backtrack
|
|
785
797
|
* @param {Array<import('types').CSRPageNodeLoader | undefined>} errors All error pages for this branch
|
|
786
|
-
* @returns {Promise<{idx: number; node: import('./types').BranchNode} | undefined>}
|
|
798
|
+
* @returns {Promise<{idx: number; node: import('./types.js').BranchNode} | undefined>}
|
|
787
799
|
*/
|
|
788
800
|
async function load_nearest_error_page(i, branch, errors) {
|
|
789
801
|
while (i--) {
|
|
@@ -815,7 +827,7 @@ export function create_client(app, target) {
|
|
|
815
827
|
* url: URL;
|
|
816
828
|
* route: { id: string | null }
|
|
817
829
|
* }} opts
|
|
818
|
-
* @returns {Promise<import('./types').NavigationFinished>}
|
|
830
|
+
* @returns {Promise<import('./types.js').NavigationFinished>}
|
|
819
831
|
*/
|
|
820
832
|
async function load_root_error_page({ status, error, url, route }) {
|
|
821
833
|
/** @type {Record<string, string>} */
|
|
@@ -843,7 +855,7 @@ export function create_client(app, target) {
|
|
|
843
855
|
} catch {
|
|
844
856
|
// at this point we have no choice but to fall back to the server, if it wouldn't
|
|
845
857
|
// bring us right back here, turning this into an endless loop
|
|
846
|
-
if (url.origin !==
|
|
858
|
+
if (url.origin !== origin || url.pathname !== location.pathname || hydrated) {
|
|
847
859
|
await native_navigation(url);
|
|
848
860
|
}
|
|
849
861
|
}
|
|
@@ -858,7 +870,7 @@ export function create_client(app, target) {
|
|
|
858
870
|
server_data_node: create_data_node(server_data_node)
|
|
859
871
|
});
|
|
860
872
|
|
|
861
|
-
/** @type {import('./types').BranchNode} */
|
|
873
|
+
/** @type {import('./types.js').BranchNode} */
|
|
862
874
|
const root_error = {
|
|
863
875
|
node: await default_error_loader(),
|
|
864
876
|
loader: default_error_loader,
|
|
@@ -891,7 +903,7 @@ export function create_client(app, target) {
|
|
|
891
903
|
|
|
892
904
|
if (params) {
|
|
893
905
|
const id = url.pathname + url.search;
|
|
894
|
-
/** @type {import('./types').NavigationIntent} */
|
|
906
|
+
/** @type {import('./types.js').NavigationIntent} */
|
|
895
907
|
const intent = { id, invalidating, route, params: decode_params(params), url };
|
|
896
908
|
return intent;
|
|
897
909
|
}
|
|
@@ -907,7 +919,7 @@ export function create_client(app, target) {
|
|
|
907
919
|
* @param {{
|
|
908
920
|
* url: URL;
|
|
909
921
|
* type: import('@sveltejs/kit').Navigation["type"];
|
|
910
|
-
* intent?: import('./types').NavigationIntent;
|
|
922
|
+
* intent?: import('./types.js').NavigationIntent;
|
|
911
923
|
* delta?: number;
|
|
912
924
|
* }} opts
|
|
913
925
|
*/
|
|
@@ -1170,10 +1182,10 @@ export function create_client(app, target) {
|
|
|
1170
1182
|
* @param {{ id: string | null }} route
|
|
1171
1183
|
* @param {App.Error} error
|
|
1172
1184
|
* @param {number} status
|
|
1173
|
-
* @returns {Promise<import('./types').NavigationFinished>}
|
|
1185
|
+
* @returns {Promise<import('./types.js').NavigationFinished>}
|
|
1174
1186
|
*/
|
|
1175
1187
|
async function server_fallback(url, route, error, status) {
|
|
1176
|
-
if (url.origin ===
|
|
1188
|
+
if (url.origin === origin && url.pathname === location.pathname && !hydrated) {
|
|
1177
1189
|
// We would reload the same page we're currently on, which isn't hydrated,
|
|
1178
1190
|
// which means no SSR, which means we would end up in an endless loop
|
|
1179
1191
|
return await load_root_error_page({
|
|
@@ -1195,17 +1207,6 @@ export function create_client(app, target) {
|
|
|
1195
1207
|
return await native_navigation(url);
|
|
1196
1208
|
}
|
|
1197
1209
|
|
|
1198
|
-
/**
|
|
1199
|
-
* Loads `href` the old-fashioned way, with a full page reload.
|
|
1200
|
-
* Returns a `Promise` that never resolves (to prevent any
|
|
1201
|
-
* subsequent work, e.g. history manipulation, from happening)
|
|
1202
|
-
* @param {URL} url
|
|
1203
|
-
*/
|
|
1204
|
-
function native_navigation(url) {
|
|
1205
|
-
location.href = url.href;
|
|
1206
|
-
return new Promise(() => {});
|
|
1207
|
-
}
|
|
1208
|
-
|
|
1209
1210
|
if (import.meta.hot) {
|
|
1210
1211
|
import.meta.hot.on('vite:beforeUpdate', () => {
|
|
1211
1212
|
if (current.error) location.reload();
|
|
@@ -1765,7 +1766,7 @@ export function create_client(app, target) {
|
|
|
1765
1766
|
({ params = {}, route = { id: null } } = get_navigation_intent(url, false) || {});
|
|
1766
1767
|
}
|
|
1767
1768
|
|
|
1768
|
-
/** @type {import('./types').NavigationFinished | undefined} */
|
|
1769
|
+
/** @type {import('./types.js').NavigationFinished | undefined} */
|
|
1769
1770
|
let result;
|
|
1770
1771
|
|
|
1771
1772
|
try {
|
|
@@ -1792,7 +1793,7 @@ export function create_client(app, target) {
|
|
|
1792
1793
|
});
|
|
1793
1794
|
});
|
|
1794
1795
|
|
|
1795
|
-
/** @type {Array<import('./types').BranchNode | undefined>} */
|
|
1796
|
+
/** @type {Array<import('./types.js').BranchNode | undefined>} */
|
|
1796
1797
|
const branch = await Promise.all(branch_promises);
|
|
1797
1798
|
|
|
1798
1799
|
const parsed_route = routes.find(({ id }) => id === route.id);
|
|
@@ -1841,7 +1842,7 @@ export function create_client(app, target) {
|
|
|
1841
1842
|
/**
|
|
1842
1843
|
* @param {URL} url
|
|
1843
1844
|
* @param {boolean[]} invalid
|
|
1844
|
-
* @returns {Promise<import('types').ServerNodesResponse |import('types').ServerRedirectNode>}
|
|
1845
|
+
* @returns {Promise<import('types').ServerNodesResponse | import('types').ServerRedirectNode>}
|
|
1845
1846
|
*/
|
|
1846
1847
|
async function load_data(url, invalid) {
|
|
1847
1848
|
const data_url = new URL(url);
|
|
@@ -1856,13 +1857,19 @@ async function load_data(url, invalid) {
|
|
|
1856
1857
|
|
|
1857
1858
|
const res = await native_fetch(data_url.href);
|
|
1858
1859
|
|
|
1860
|
+
// if `__data.json` doesn't exist or the server has an internal error,
|
|
1861
|
+
// fallback to native navigation so we avoid parsing the HTML error page as a JSON
|
|
1862
|
+
if (res.headers.get('content-type')?.includes('text/html')) {
|
|
1863
|
+
await native_navigation(url);
|
|
1864
|
+
}
|
|
1865
|
+
|
|
1859
1866
|
if (!res.ok) {
|
|
1860
1867
|
// error message is a JSON-stringified string which devalue can't handle at the top level
|
|
1861
1868
|
// turn it into a HttpError to not call handleError on the client again (was already handled on the server)
|
|
1862
1869
|
throw new HttpError(res.status, await res.json());
|
|
1863
1870
|
}
|
|
1864
1871
|
|
|
1865
|
-
// TODO: fix eslint error
|
|
1872
|
+
// TODO: fix eslint error / figure out if it actually applies to our situation
|
|
1866
1873
|
// eslint-disable-next-line
|
|
1867
1874
|
return new Promise(async (resolve) => {
|
|
1868
1875
|
/**
|
|
@@ -2018,8 +2025,8 @@ function reset_focus() {
|
|
|
2018
2025
|
}
|
|
2019
2026
|
|
|
2020
2027
|
/**
|
|
2021
|
-
* @param {import('./types').NavigationState} current
|
|
2022
|
-
* @param {import('./types').NavigationIntent | undefined} intent
|
|
2028
|
+
* @param {import('./types.js').NavigationState} current
|
|
2029
|
+
* @param {import('./types.js').NavigationIntent | undefined} intent
|
|
2023
2030
|
* @param {URL | null} url
|
|
2024
2031
|
* @param {Exclude<import('@sveltejs/kit').NavigationType, 'enter'>} type
|
|
2025
2032
|
*/
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { exec, parse_route_id } from '../../utils/routing.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* @param {import('./types').SvelteKitApp} app
|
|
4
|
+
* @param {import('./types.js').SvelteKitApp} app
|
|
5
5
|
* @returns {import('types').CSRRoute[]}
|
|
6
6
|
*/
|
|
7
7
|
export function parse({ nodes, server_loads, dictionary, matchers }) {
|
|
@@ -2,12 +2,12 @@ import { writable } from 'svelte/store';
|
|
|
2
2
|
import { create_updated_store, notifiable_store } from './utils.js';
|
|
3
3
|
import { BROWSER } from 'esm-env';
|
|
4
4
|
|
|
5
|
-
/** @type {import('./types').Client} */
|
|
5
|
+
/** @type {import('./types.js').Client} */
|
|
6
6
|
export let client;
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* @param {{
|
|
10
|
-
* client: import('./types').Client;
|
|
10
|
+
* client: import('./types.js').Client;
|
|
11
11
|
* }} opts
|
|
12
12
|
*/
|
|
13
13
|
export function init(opts) {
|
|
@@ -3,9 +3,9 @@ import { create_client } from './client.js';
|
|
|
3
3
|
import { init } from './singletons.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* @param {import('./types').SvelteKitApp} app
|
|
6
|
+
* @param {import('./types.js').SvelteKitApp} app
|
|
7
7
|
* @param {HTMLElement} target
|
|
8
|
-
* @param {Parameters<import('./types').Client['_hydrate']>[0]} [hydrate]
|
|
8
|
+
* @param {Parameters<import('./types.js').Client['_hydrate']>[0]} [hydrate]
|
|
9
9
|
*/
|
|
10
10
|
export async function start(app, target, hydrate) {
|
|
11
11
|
if (DEV && target === document.body) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { applyAction } from '../app/forms';
|
|
1
|
+
import { applyAction } from '../app/forms.js';
|
|
2
2
|
import {
|
|
3
3
|
afterNavigate,
|
|
4
4
|
beforeNavigate,
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
invalidateAll,
|
|
9
9
|
preloadCode,
|
|
10
10
|
preloadData
|
|
11
|
-
} from '../app/navigation';
|
|
11
|
+
} from '../app/navigation.js';
|
|
12
12
|
import { SvelteComponent } from 'svelte';
|
|
13
13
|
import { ClientHooks, CSRPageNode, CSRPageNodeLoader, CSRRoute, TrailingSlash, Uses } from 'types';
|
|
14
14
|
import { Page, ParamMatcher } from '@sveltejs/kit';
|
|
@@ -6,6 +6,8 @@ import { PRELOAD_PRIORITIES } from './constants.js';
|
|
|
6
6
|
|
|
7
7
|
/* global __SVELTEKIT_APP_VERSION_FILE__, __SVELTEKIT_APP_VERSION_POLL_INTERVAL__ */
|
|
8
8
|
|
|
9
|
+
export const origin = BROWSER ? location.origin : '';
|
|
10
|
+
|
|
9
11
|
/** @param {HTMLDocument} doc */
|
|
10
12
|
export function get_base_uri(doc) {
|
|
11
13
|
let baseURI = doc.baseURI;
|
|
@@ -135,7 +137,7 @@ export function get_link_info(a, base) {
|
|
|
135
137
|
is_external_url(url, base) ||
|
|
136
138
|
(a.getAttribute('rel') || '').split(/\s+/).includes('external');
|
|
137
139
|
|
|
138
|
-
const download = url?.origin ===
|
|
140
|
+
const download = url?.origin === origin && a.hasAttribute('download');
|
|
139
141
|
|
|
140
142
|
return { url, external, target, download };
|
|
141
143
|
}
|
|
@@ -290,5 +292,5 @@ export function create_updated_store() {
|
|
|
290
292
|
* @param {string} base
|
|
291
293
|
*/
|
|
292
294
|
export function is_external_url(url, base) {
|
|
293
|
-
return url.origin !==
|
|
295
|
+
return url.origin !== origin || !url.pathname.startsWith(base);
|
|
294
296
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
<slot
|
|
1
|
+
<slot />
|
|
@@ -27,7 +27,7 @@ export function get_cookies(request, url, trailing_slash) {
|
|
|
27
27
|
// Emulate browser-behavior: if the cookie is set at '/foo/bar', its path is '/foo'
|
|
28
28
|
const default_path = normalized_url.split('/').slice(0, -1).join('/') || '/';
|
|
29
29
|
|
|
30
|
-
/** @type {Record<string, import('./page/types').Cookie>} */
|
|
30
|
+
/** @type {Record<string, import('./page/types.js').Cookie>} */
|
|
31
31
|
const new_cookies = {};
|
|
32
32
|
|
|
33
33
|
/** @type {import('cookie').CookieSerializeOptions} */
|
|
@@ -232,7 +232,7 @@ export function path_matches(path, constraint) {
|
|
|
232
232
|
|
|
233
233
|
/**
|
|
234
234
|
* @param {Headers} headers
|
|
235
|
-
* @param {import('./page/types').Cookie[]} cookies
|
|
235
|
+
* @param {import('./page/types.js').Cookie[]} cookies
|
|
236
236
|
*/
|
|
237
237
|
export function add_cookies_to_headers(headers, cookies) {
|
|
238
238
|
for (const new_cookie of cookies) {
|
|
@@ -223,8 +223,8 @@ export class Csp {
|
|
|
223
223
|
report_only_provider;
|
|
224
224
|
|
|
225
225
|
/**
|
|
226
|
-
* @param {import('./types').CspConfig} config
|
|
227
|
-
* @param {import('./types').CspOpts} opts
|
|
226
|
+
* @param {import('./types.js').CspConfig} config
|
|
227
|
+
* @param {import('./types.js').CspOpts} opts
|
|
228
228
|
*/
|
|
229
229
|
constructor({ mode, directives, reportOnly }, { prerender }) {
|
|
230
230
|
const use_hashes = mode === 'hash' || (mode === 'auto' && prerender);
|
|
@@ -96,7 +96,7 @@ export async function render_page(event, page, options, manifest, state, resolve
|
|
|
96
96
|
// inherit the prerender option of the page
|
|
97
97
|
state.prerender_default = should_prerender;
|
|
98
98
|
|
|
99
|
-
/** @type {import('./types').Fetched[]} */
|
|
99
|
+
/** @type {import('./types.js').Fetched[]} */
|
|
100
100
|
const fetched = [];
|
|
101
101
|
|
|
102
102
|
if (get_option(nodes, 'ssr') === false && !state.prerendering) {
|
|
@@ -291,7 +291,7 @@ export async function render_page(event, page, options, manifest, state, resolve
|
|
|
291
291
|
resolve_opts,
|
|
292
292
|
page_config: {
|
|
293
293
|
csr: get_option(nodes, 'csr') ?? true,
|
|
294
|
-
ssr: true
|
|
294
|
+
ssr: get_option(nodes, 'ssr') ?? true
|
|
295
295
|
},
|
|
296
296
|
status,
|
|
297
297
|
error: null,
|
|
@@ -144,7 +144,7 @@ export async function load_server_data({
|
|
|
144
144
|
* Calls the user's `load` function.
|
|
145
145
|
* @param {{
|
|
146
146
|
* event: import('@sveltejs/kit').RequestEvent;
|
|
147
|
-
* fetched: import('./types').Fetched[];
|
|
147
|
+
* fetched: import('./types.js').Fetched[];
|
|
148
148
|
* node: import('types').SSRNode | undefined;
|
|
149
149
|
* parent: () => Promise<Record<string, any>>;
|
|
150
150
|
* resolve_opts: import('types').RequiredResolveOptions;
|
|
@@ -192,7 +192,7 @@ export async function load_data({
|
|
|
192
192
|
/**
|
|
193
193
|
* @param {Pick<import('@sveltejs/kit').RequestEvent, 'fetch' | 'url' | 'request' | 'route'>} event
|
|
194
194
|
* @param {import('types').SSRState} state
|
|
195
|
-
* @param {import('./types').Fetched[]} fetched
|
|
195
|
+
* @param {import('./types.js').Fetched[]} fetched
|
|
196
196
|
* @param {boolean} csr
|
|
197
197
|
* @param {Pick<Required<import('@sveltejs/kit').ResolveOptions>, 'filterSerializedResponseHeaders'>} resolve_opts
|
|
198
198
|
*/
|
|
@@ -359,10 +359,10 @@ function validate_load_response(data, routeId) {
|
|
|
359
359
|
typeof data !== 'object'
|
|
360
360
|
? `a ${typeof data}`
|
|
361
361
|
: data instanceof Response
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
362
|
+
? 'a Response object'
|
|
363
|
+
: Array.isArray(data)
|
|
364
|
+
? 'an array'
|
|
365
|
+
: 'a non-plain object'
|
|
366
366
|
}, but must return a plain object at the top level (i.e. \`return {...}\`)`
|
|
367
367
|
);
|
|
368
368
|
}
|
|
@@ -26,8 +26,8 @@ const encoder = new TextEncoder();
|
|
|
26
26
|
/**
|
|
27
27
|
* Creates the HTML response.
|
|
28
28
|
* @param {{
|
|
29
|
-
* branch: Array<import('./types').Loaded>;
|
|
30
|
-
* fetched: Array<import('./types').Fetched>;
|
|
29
|
+
* branch: Array<import('./types.js').Loaded>;
|
|
30
|
+
* fetched: Array<import('./types.js').Fetched>;
|
|
31
31
|
* options: import('types').SSROptions;
|
|
32
32
|
* manifest: import('@sveltejs/kit').SSRManifest;
|
|
33
33
|
* state: import('types').SSRState;
|
|
@@ -33,7 +33,7 @@ export async function respond_with_error({
|
|
|
33
33
|
return static_error_page(options, status, /** @type {Error} */ (error).message);
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
/** @type {import('./types').Fetched[]} */
|
|
36
|
+
/** @type {import('./types.js').Fetched[]} */
|
|
37
37
|
const fetched = [];
|
|
38
38
|
|
|
39
39
|
try {
|
|
@@ -134,7 +134,7 @@ export async function respond(request, options, manifest, state) {
|
|
|
134
134
|
/** @type {Record<string, string>} */
|
|
135
135
|
const headers = {};
|
|
136
136
|
|
|
137
|
-
/** @type {Record<string, import('./page/types').Cookie>} */
|
|
137
|
+
/** @type {Record<string, import('./page/types.js').Cookie>} */
|
|
138
138
|
let cookies_to_add = {};
|
|
139
139
|
|
|
140
140
|
/** @type {import('@sveltejs/kit').RequestEvent} */
|
|
@@ -341,8 +341,8 @@ export async function respond(request, options, manifest, state) {
|
|
|
341
341
|
const response = is_data_request
|
|
342
342
|
? redirect_json_response(e)
|
|
343
343
|
: route?.page && is_action_json_request(event)
|
|
344
|
-
|
|
345
|
-
|
|
344
|
+
? action_json_redirect(e)
|
|
345
|
+
: redirect_response(e.status, e.location);
|
|
346
346
|
add_cookies_to_headers(response.headers, Object.values(cookies_to_add));
|
|
347
347
|
return response;
|
|
348
348
|
}
|
package/src/types/internal.d.ts
CHANGED
package/src/version.js
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -22,12 +22,12 @@ declare module '@sveltejs/kit' {
|
|
|
22
22
|
type AwaitedPropertiesUnion<input extends Record<string, any> | void> = input extends void
|
|
23
23
|
? undefined // needs to be undefined, because void will break intellisense
|
|
24
24
|
: input extends Record<string, any>
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
? {
|
|
26
|
+
[key in keyof input]: Awaited<input[key]>;
|
|
27
|
+
}
|
|
28
|
+
: {} extends input // handles the any case
|
|
29
|
+
? input
|
|
30
|
+
: unknown;
|
|
31
31
|
|
|
32
32
|
export type AwaitedProperties<input extends Record<string, any> | void> =
|
|
33
33
|
AwaitedPropertiesUnion<input> extends Record<string, any>
|
|
@@ -50,8 +50,8 @@ declare module '@sveltejs/kit' {
|
|
|
50
50
|
type UnpackValidationError<T> = T extends ActionFailure<infer X>
|
|
51
51
|
? X
|
|
52
52
|
: T extends void
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
? undefined // needs to be undefined, because void will corrupt union type
|
|
54
|
+
: T;
|
|
55
55
|
|
|
56
56
|
/**
|
|
57
57
|
* This object is passed to the `adapt` function of adapters.
|