@sveltejs/kit 1.0.0-next.443 → 1.0.0-next.446
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 +7 -7
- package/src/core/prerender/prerender.js +1 -1
- package/src/core/sync/write_ambient.js +1 -1
- package/src/core/sync/write_client_manifest.js +16 -14
- package/src/core/sync/write_root.js +2 -2
- package/src/exports/hooks/index.js +1 -0
- package/src/{hooks.js → exports/hooks/sequence.js} +0 -0
- package/src/{index → exports}/index.js +1 -1
- package/src/{node → exports/node}/index.js +0 -0
- package/src/{node → exports/node}/polyfills.js +0 -0
- package/src/{vite → exports/vite}/build/build_server.js +4 -4
- package/src/{vite → exports/vite}/build/build_service_worker.js +1 -1
- package/src/{vite → exports/vite}/build/utils.js +0 -0
- package/src/{vite → exports/vite}/dev/index.js +9 -9
- package/src/{vite → exports/vite}/index.js +8 -8
- package/src/{vite → exports/vite}/preview/index.js +3 -3
- package/src/{vite → exports/vite}/types.d.ts +0 -0
- package/src/{vite → exports/vite}/utils.js +2 -2
- package/src/runtime/app/env.js +1 -11
- package/src/runtime/app/environment.js +11 -0
- package/src/runtime/app/stores.js +1 -1
- package/src/runtime/client/ambient.d.ts +10 -4
- package/src/runtime/client/client.js +37 -23
- package/src/runtime/client/parse.js +28 -9
- package/src/runtime/client/types.d.ts +2 -2
- package/src/{index/private.js → runtime/control.js} +0 -0
- package/src/runtime/server/endpoint.js +1 -1
- package/src/runtime/server/index.js +2 -2
- package/src/runtime/server/page/index.js +2 -2
- package/src/runtime/server/page/render.js +1 -1
- package/src/runtime/server/page/types.d.ts +1 -1
- package/src/runtime/server/utils.js +1 -1
- package/src/utils/error.js +1 -1
- package/types/ambient.d.ts +2 -2
- package/types/index.d.ts +1 -1
- package/types/internal.d.ts +7 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sveltejs/kit",
|
|
3
|
-
"version": "1.0.0-next.
|
|
3
|
+
"version": "1.0.0-next.446",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/sveltejs/kit",
|
|
@@ -60,20 +60,20 @@
|
|
|
60
60
|
"exports": {
|
|
61
61
|
"./package.json": "./package.json",
|
|
62
62
|
".": {
|
|
63
|
-
"
|
|
64
|
-
"
|
|
63
|
+
"types": "./types/index.d.ts",
|
|
64
|
+
"import": "./src/exports/index.js"
|
|
65
65
|
},
|
|
66
66
|
"./node": {
|
|
67
|
-
"import": "./src/node/index.js"
|
|
67
|
+
"import": "./src/exports/node/index.js"
|
|
68
68
|
},
|
|
69
69
|
"./node/polyfills": {
|
|
70
|
-
"import": "./src/node/polyfills.js"
|
|
70
|
+
"import": "./src/exports/node/polyfills.js"
|
|
71
71
|
},
|
|
72
72
|
"./hooks": {
|
|
73
|
-
"import": "./src/hooks.js"
|
|
73
|
+
"import": "./src/exports/hooks/index.js"
|
|
74
74
|
},
|
|
75
75
|
"./vite": {
|
|
76
|
-
"import": "./src/vite/index.js"
|
|
76
|
+
"import": "./src/exports/vite/index.js"
|
|
77
77
|
}
|
|
78
78
|
},
|
|
79
79
|
"types": "types/index.d.ts",
|
|
@@ -2,7 +2,7 @@ import { readFileSync, writeFileSync } from 'fs';
|
|
|
2
2
|
import { dirname, join } from 'path';
|
|
3
3
|
import { pathToFileURL, URL } from 'url';
|
|
4
4
|
import { mkdirp, posixify, walk } from '../../utils/filesystem.js';
|
|
5
|
-
import { installPolyfills } from '../../node/polyfills.js';
|
|
5
|
+
import { installPolyfills } from '../../exports/node/polyfills.js';
|
|
6
6
|
import { is_root_relative, resolve } from '../../utils/url.js';
|
|
7
7
|
import { queue } from './queue.js';
|
|
8
8
|
import { crawl } from './crawl.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
|
-
import { get_env } from '../../vite/utils.js';
|
|
2
|
+
import { get_env } from '../../exports/vite/utils.js';
|
|
3
3
|
import { GENERATED_COMMENT } from '../constants.js';
|
|
4
4
|
import { create_types } from '../env.js';
|
|
5
5
|
import { write_if_changed } from './utils.js';
|
|
@@ -43,6 +43,8 @@ export function write_client_manifest(manifest_data, output) {
|
|
|
43
43
|
})
|
|
44
44
|
.join(',\n\t');
|
|
45
45
|
|
|
46
|
+
const layouts_with_server_load = new Set();
|
|
47
|
+
|
|
46
48
|
const dictionary = `{
|
|
47
49
|
${manifest_data.routes
|
|
48
50
|
.map((route) => {
|
|
@@ -53,18 +55,17 @@ export function write_client_manifest(manifest_data, output) {
|
|
|
53
55
|
while (layouts.at(-1) === '') layouts.pop();
|
|
54
56
|
while (errors.at(-1) === '') errors.pop();
|
|
55
57
|
|
|
56
|
-
|
|
57
|
-
let current_node = route.leaf;
|
|
58
|
-
|
|
59
|
-
let uses_server_data = false;
|
|
60
|
-
while (current_node && !uses_server_data) {
|
|
61
|
-
uses_server_data = !!current_node?.server;
|
|
62
|
-
current_node = current_node?.parent ?? null;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// encode whether or not the route uses the server data
|
|
58
|
+
// Encode whether or not the route uses server data
|
|
66
59
|
// using the ones' complement, to save space
|
|
67
|
-
const array = [`${
|
|
60
|
+
const array = [`${route.leaf?.server ? '~' : ''}${route.page.leaf}`];
|
|
61
|
+
// Encode whether or not the layout uses server data.
|
|
62
|
+
// It's a different method compared to pages because layouts
|
|
63
|
+
// are reused across pages, so we safe space by doing it this way.
|
|
64
|
+
route.page.layouts.forEach((layout) => {
|
|
65
|
+
if (layout != undefined && manifest_data.nodes[layout].server) {
|
|
66
|
+
layouts_with_server_load.add(layout);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
68
69
|
|
|
69
70
|
// only include non-root layout/error nodes if they exist
|
|
70
71
|
if (layouts.length > 0 || errors.length > 0) array.push(`[${layouts.join(',')}]`);
|
|
@@ -77,14 +78,15 @@ export function write_client_manifest(manifest_data, output) {
|
|
|
77
78
|
.join(',\n\t\t')}
|
|
78
79
|
}`.replace(/^\t/gm, '');
|
|
79
80
|
|
|
81
|
+
// String representation of __GENERATED__/client-manifest.js
|
|
80
82
|
write_if_changed(
|
|
81
83
|
`${output}/client-manifest.js`,
|
|
82
84
|
trim(`
|
|
83
85
|
export { matchers } from './client-matchers.js';
|
|
84
86
|
|
|
85
|
-
export const nodes = [
|
|
86
|
-
|
|
87
|
-
];
|
|
87
|
+
export const nodes = [${nodes}];
|
|
88
|
+
|
|
89
|
+
export const server_loads = [${[...layouts_with_server_load].join(',')}];
|
|
88
90
|
|
|
89
91
|
export const dictionary = ${dictionary};
|
|
90
92
|
`)
|
|
@@ -21,7 +21,7 @@ export function write_root(manifest_data, output) {
|
|
|
21
21
|
|
|
22
22
|
let l = max_depth;
|
|
23
23
|
|
|
24
|
-
let pyramid = `<svelte:component this={components[${l}]} data={data_${l}}/>`;
|
|
24
|
+
let pyramid = `<svelte:component this={components[${l}]} data={data_${l}} {errors}/>`;
|
|
25
25
|
|
|
26
26
|
while (l--) {
|
|
27
27
|
pyramid = `
|
|
@@ -43,7 +43,7 @@ export function write_root(manifest_data, output) {
|
|
|
43
43
|
<!-- This file is generated by @sveltejs/kit — do not edit it! -->
|
|
44
44
|
<script>
|
|
45
45
|
import { setContext, afterUpdate, onMount } from 'svelte';
|
|
46
|
-
import { browser } from '$app/
|
|
46
|
+
import { browser } from '$app/environment';
|
|
47
47
|
|
|
48
48
|
// stores
|
|
49
49
|
export let stores;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { sequence } from './sequence.js';
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import path from 'path';
|
|
3
|
-
import { mkdirp, posixify } from '
|
|
3
|
+
import { mkdirp, posixify } from '../../../utils/filesystem.js';
|
|
4
4
|
import { get_vite_config, merge_vite_configs, resolve_entry } from '../utils.js';
|
|
5
|
-
import { load_template } from '
|
|
6
|
-
import { runtime_directory } from '
|
|
5
|
+
import { load_template } from '../../../core/config/index.js';
|
|
6
|
+
import { runtime_directory } from '../../../core/utils.js';
|
|
7
7
|
import { create_build, find_deps, get_default_build_config, is_http_method } from './utils.js';
|
|
8
|
-
import { s } from '
|
|
8
|
+
import { s } from '../../../utils/misc.js';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* @param {{
|
|
File without changes
|
|
@@ -3,16 +3,16 @@ import colors from 'kleur';
|
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import sirv from 'sirv';
|
|
5
5
|
import { URL } from 'url';
|
|
6
|
-
import { getRequest, setResponse } from '
|
|
7
|
-
import { installPolyfills } from '
|
|
8
|
-
import { coalesce_to_error } from '
|
|
9
|
-
import { posixify } from '
|
|
10
|
-
import { load_template } from '
|
|
11
|
-
import { SVELTE_KIT_ASSETS } from '
|
|
12
|
-
import * as sync from '
|
|
13
|
-
import { get_mime_lookup, runtime_base, runtime_prefix } from '
|
|
6
|
+
import { getRequest, setResponse } from '../../../exports/node/index.js';
|
|
7
|
+
import { installPolyfills } from '../../../exports/node/polyfills.js';
|
|
8
|
+
import { coalesce_to_error } from '../../../utils/error.js';
|
|
9
|
+
import { posixify } from '../../../utils/filesystem.js';
|
|
10
|
+
import { load_template } from '../../../core/config/index.js';
|
|
11
|
+
import { SVELTE_KIT_ASSETS } from '../../../core/constants.js';
|
|
12
|
+
import * as sync from '../../../core/sync/sync.js';
|
|
13
|
+
import { get_mime_lookup, runtime_base, runtime_prefix } from '../../../core/utils.js';
|
|
14
14
|
import { get_env, prevent_illegal_vite_imports, resolve_entry } from '../utils.js';
|
|
15
|
-
import { compact } from '
|
|
15
|
+
import { compact } from '../../../utils/array.js';
|
|
16
16
|
|
|
17
17
|
// Vite doesn't expose this so we just copy the list for now
|
|
18
18
|
// https://github.com/vitejs/vite/blob/3edd1af56e980aef56641a5a51cf2932bb580d41/packages/vite/src/node/plugins/css.ts#L96
|
|
@@ -4,19 +4,19 @@ import path from 'node:path';
|
|
|
4
4
|
import colors from 'kleur';
|
|
5
5
|
import { svelte } from '@sveltejs/vite-plugin-svelte';
|
|
6
6
|
import * as vite from 'vite';
|
|
7
|
-
import { mkdirp, posixify, rimraf } from '
|
|
8
|
-
import * as sync from '
|
|
7
|
+
import { mkdirp, posixify, rimraf } from '../../utils/filesystem.js';
|
|
8
|
+
import * as sync from '../../core/sync/sync.js';
|
|
9
9
|
import { build_server } from './build/build_server.js';
|
|
10
10
|
import { build_service_worker } from './build/build_service_worker.js';
|
|
11
|
-
import { load_config } from '
|
|
11
|
+
import { load_config } from '../../core/config/index.js';
|
|
12
12
|
import { dev } from './dev/index.js';
|
|
13
|
-
import { generate_manifest } from '
|
|
14
|
-
import { runtime_directory, logger } from '
|
|
13
|
+
import { generate_manifest } from '../../core/generate_manifest/index.js';
|
|
14
|
+
import { runtime_directory, logger } from '../../core/utils.js';
|
|
15
15
|
import { find_deps, get_default_build_config } from './build/utils.js';
|
|
16
16
|
import { preview } from './preview/index.js';
|
|
17
17
|
import { get_aliases, resolve_entry, prevent_illegal_rollup_imports, get_env } from './utils.js';
|
|
18
18
|
import { fileURLToPath } from 'node:url';
|
|
19
|
-
import { create_static_module, create_dynamic_module } from '
|
|
19
|
+
import { create_static_module, create_dynamic_module } from '../../core/env.js';
|
|
20
20
|
|
|
21
21
|
const cwd = process.cwd();
|
|
22
22
|
|
|
@@ -405,7 +405,7 @@ function kit() {
|
|
|
405
405
|
const results_path = `${svelte_config.kit.outDir}/generated/prerendered.json`;
|
|
406
406
|
|
|
407
407
|
// do prerendering in a subprocess so any dangling stuff gets killed upon completion
|
|
408
|
-
const script = fileURLToPath(new URL('
|
|
408
|
+
const script = fileURLToPath(new URL('../../core/prerender/prerender.js', import.meta.url));
|
|
409
409
|
|
|
410
410
|
const child = fork(
|
|
411
411
|
script,
|
|
@@ -465,7 +465,7 @@ function kit() {
|
|
|
465
465
|
}
|
|
466
466
|
|
|
467
467
|
if (svelte_config.kit.adapter) {
|
|
468
|
-
const { adapt } = await import('
|
|
468
|
+
const { adapt } = await import('../../core/adapt/index.js');
|
|
469
469
|
await adapt(svelte_config, build_data, prerendered, { log });
|
|
470
470
|
} else {
|
|
471
471
|
console.log(colors.bold().yellow('\nNo adapter specified'));
|
|
@@ -2,9 +2,9 @@ import fs from 'fs';
|
|
|
2
2
|
import { join } from 'path';
|
|
3
3
|
import sirv from 'sirv';
|
|
4
4
|
import { pathToFileURL } from 'url';
|
|
5
|
-
import { getRequest, setResponse } from '
|
|
6
|
-
import { installPolyfills } from '
|
|
7
|
-
import { SVELTE_KIT_ASSETS } from '
|
|
5
|
+
import { getRequest, setResponse } from '../../../exports/node/index.js';
|
|
6
|
+
import { installPolyfills } from '../../../exports/node/polyfills.js';
|
|
7
|
+
import { SVELTE_KIT_ASSETS } from '../../../core/constants.js';
|
|
8
8
|
import { loadEnv } from 'vite';
|
|
9
9
|
|
|
10
10
|
/** @typedef {import('http').IncomingMessage} Req */
|
|
File without changes
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { loadConfigFromFile, loadEnv, normalizePath } from 'vite';
|
|
4
|
-
import { runtime_directory } from '
|
|
5
|
-
import { posixify } from '
|
|
4
|
+
import { runtime_directory } from '../../core/utils.js';
|
|
5
|
+
import { posixify } from '../../utils/filesystem.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* @param {import('vite').ResolvedConfig} config
|
package/src/runtime/app/env.js
CHANGED
|
@@ -1,11 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* @type {import('$app/env').browser}
|
|
3
|
-
*/
|
|
4
|
-
export const browser = !import.meta.env.SSR;
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @type {import('$app/env').dev}
|
|
8
|
-
*/
|
|
9
|
-
export const dev = __SVELTEKIT_DEV__;
|
|
10
|
-
|
|
11
|
-
export { prerendering } from '../env.js';
|
|
1
|
+
throw new Error('$app/env has been renamed to $app/environment');
|
|
@@ -6,13 +6,19 @@ declare module '__GENERATED__/client-manifest.js' {
|
|
|
6
6
|
*/
|
|
7
7
|
export const nodes: CSRPageNodeLoader[];
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* A list of all layout node ids that have a server load function.
|
|
11
|
+
* Pages are not present because it's shorter to encode it on the leaf itself.
|
|
12
|
+
*/
|
|
13
|
+
export const server_loads: number[];
|
|
14
|
+
|
|
9
15
|
/**
|
|
10
16
|
* A map of `[routeId: string]: [leaf, layouts, errors]` tuples, which
|
|
11
|
-
* is parsed into an array of routes on startup. The numbers refer to the
|
|
12
|
-
*
|
|
13
|
-
* they are always number 0 and 1 and always apply.
|
|
17
|
+
* is parsed into an array of routes on startup. The numbers refer to the indices in `nodes`.
|
|
18
|
+
* If the leaf number is negative, it means it does use a server load function and the complement is the node index.
|
|
19
|
+
* The route layout and error nodes are not referenced, they are always number 0 and 1 and always apply.
|
|
14
20
|
*/
|
|
15
|
-
export const dictionary: Record<string, [leaf: number, layouts
|
|
21
|
+
export const dictionary: Record<string, [leaf: number, layouts: number[], errors?: number[]]>;
|
|
16
22
|
|
|
17
23
|
export const matchers: Record<string, ParamMatcher>;
|
|
18
24
|
}
|
|
@@ -4,17 +4,17 @@ import { make_trackable, decode_params, normalize_path } from '../../utils/url.j
|
|
|
4
4
|
import { find_anchor, get_base_uri, get_href, scroll_state } from './utils.js';
|
|
5
5
|
import { lock_fetch, unlock_fetch, initial_fetch, native_fetch } from './fetcher.js';
|
|
6
6
|
import { parse } from './parse.js';
|
|
7
|
-
import { error } from '../../
|
|
7
|
+
import { error } from '../../exports/index.js';
|
|
8
8
|
|
|
9
9
|
import Root from '__GENERATED__/root.svelte';
|
|
10
|
-
import { nodes, dictionary, matchers } from '__GENERATED__/client-manifest.js';
|
|
11
|
-
import { HttpError, Redirect } from '
|
|
10
|
+
import { nodes, server_loads, dictionary, matchers } from '__GENERATED__/client-manifest.js';
|
|
11
|
+
import { HttpError, Redirect } from '../control.js';
|
|
12
12
|
import { stores } from './singletons.js';
|
|
13
13
|
|
|
14
14
|
const SCROLL_KEY = 'sveltekit:scroll';
|
|
15
15
|
const INDEX_KEY = 'sveltekit:index';
|
|
16
16
|
|
|
17
|
-
const routes = parse(nodes, dictionary, matchers);
|
|
17
|
+
const routes = parse(nodes, server_loads, dictionary, matchers);
|
|
18
18
|
|
|
19
19
|
const default_layout_loader = nodes[0];
|
|
20
20
|
const default_error_loader = nodes[1];
|
|
@@ -424,21 +424,37 @@ export function create_client({ target, base, trailing_slash }) {
|
|
|
424
424
|
};
|
|
425
425
|
|
|
426
426
|
let data = {};
|
|
427
|
-
let data_changed =
|
|
427
|
+
let data_changed = !page;
|
|
428
428
|
for (let i = 0; i < filtered.length; i += 1) {
|
|
429
|
-
|
|
429
|
+
const node = filtered[i];
|
|
430
|
+
data = { ...data, ...node.data };
|
|
431
|
+
|
|
430
432
|
// Only set props if the node actually updated. This prevents needless rerenders.
|
|
431
|
-
if (data_changed || !current.branch.some((
|
|
433
|
+
if (data_changed || !current.branch.some((previous) => previous === node)) {
|
|
432
434
|
result.props[`data_${i}`] = data;
|
|
433
|
-
data_changed =
|
|
435
|
+
data_changed = data_changed || Object.keys(node.data ?? {}).length > 0;
|
|
434
436
|
}
|
|
435
437
|
}
|
|
438
|
+
if (!data_changed) {
|
|
439
|
+
// If nothing was added, and the object entries are the same length, this means
|
|
440
|
+
// that nothing was removed either and therefore the data is the same as the previous one.
|
|
441
|
+
// This would be more readable with a separate boolean but that would cost us some bytes.
|
|
442
|
+
data_changed = Object.keys(page.data).length !== Object.keys(data).length;
|
|
443
|
+
}
|
|
436
444
|
|
|
437
445
|
const page_changed =
|
|
438
446
|
!current.url || url.href !== current.url.href || current.error !== error || data_changed;
|
|
439
447
|
|
|
440
448
|
if (page_changed) {
|
|
441
|
-
result.props.page = {
|
|
449
|
+
result.props.page = {
|
|
450
|
+
error,
|
|
451
|
+
params,
|
|
452
|
+
routeId,
|
|
453
|
+
status,
|
|
454
|
+
url,
|
|
455
|
+
// The whole page store is updated, but this way the object reference stays the same
|
|
456
|
+
data: data_changed ? data : page.data
|
|
457
|
+
};
|
|
442
458
|
|
|
443
459
|
// TODO remove this for 1.0
|
|
444
460
|
/**
|
|
@@ -675,14 +691,13 @@ export function create_client({ target, base, trailing_slash }) {
|
|
|
675
691
|
params: Object.keys(params).filter((key) => current.params[key] !== params[key])
|
|
676
692
|
};
|
|
677
693
|
|
|
694
|
+
const loaders = [...layouts, leaf];
|
|
695
|
+
|
|
678
696
|
// preload modules to avoid waterfall, but handle rejections
|
|
679
697
|
// so they don't get reported to Sentry et al (we don't need
|
|
680
698
|
// to act on the failures at this point)
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
const loaders = [...layouts, leaf];
|
|
684
|
-
|
|
685
|
-
// To avoid waterfalls when someone awaits a parent, compute as much as possible here already
|
|
699
|
+
errors.forEach((loader) => loader?.().catch(() => {}));
|
|
700
|
+
loaders.forEach((loader) => loader?.[1]().catch(() => {}));
|
|
686
701
|
|
|
687
702
|
/** @type {import('types').ServerData | null} */
|
|
688
703
|
let server_data = null;
|
|
@@ -690,15 +705,15 @@ export function create_client({ target, base, trailing_slash }) {
|
|
|
690
705
|
const invalid_server_nodes = loaders.reduce((acc, loader, i) => {
|
|
691
706
|
const previous = current.branch[i];
|
|
692
707
|
const invalid =
|
|
693
|
-
loader &&
|
|
694
|
-
(previous?.loader !== loader ||
|
|
708
|
+
!!loader?.[0] &&
|
|
709
|
+
(previous?.loader !== loader[1] ||
|
|
695
710
|
has_changed(changed, acc.some(Boolean), previous.server?.uses));
|
|
696
711
|
|
|
697
712
|
acc.push(invalid);
|
|
698
713
|
return acc;
|
|
699
714
|
}, /** @type {boolean[]} */ ([]));
|
|
700
715
|
|
|
701
|
-
if (
|
|
716
|
+
if (invalid_server_nodes.some(Boolean)) {
|
|
702
717
|
try {
|
|
703
718
|
const res = await native_fetch(
|
|
704
719
|
`${url.pathname}${url.pathname.endsWith('/') ? '' : '/'}__data.json${url.search}`,
|
|
@@ -741,7 +756,7 @@ export function create_client({ target, base, trailing_slash }) {
|
|
|
741
756
|
// re-use data from previous load if it's still valid
|
|
742
757
|
const valid =
|
|
743
758
|
can_reuse_server_data &&
|
|
744
|
-
loader === previous?.loader &&
|
|
759
|
+
loader[1] === previous?.loader &&
|
|
745
760
|
!has_changed(changed, parent_changed, previous.shared?.uses);
|
|
746
761
|
if (valid) return previous;
|
|
747
762
|
|
|
@@ -757,7 +772,7 @@ export function create_client({ target, base, trailing_slash }) {
|
|
|
757
772
|
}
|
|
758
773
|
|
|
759
774
|
return load_node({
|
|
760
|
-
loader,
|
|
775
|
+
loader: loader[1],
|
|
761
776
|
url,
|
|
762
777
|
params,
|
|
763
778
|
routeId: route.id,
|
|
@@ -801,11 +816,10 @@ export function create_client({ target, base, trailing_slash }) {
|
|
|
801
816
|
|
|
802
817
|
let j = i;
|
|
803
818
|
while (!branch[j]) j -= 1;
|
|
804
|
-
|
|
805
819
|
try {
|
|
806
820
|
error_loaded = {
|
|
807
|
-
node: await errors[i](),
|
|
808
|
-
loader: errors[i],
|
|
821
|
+
node: await /** @type {import('types').CSRPageNodeLoader } */ (errors[i])(),
|
|
822
|
+
loader: /** @type {import('types').CSRPageNodeLoader } */ (errors[i]),
|
|
809
823
|
data: {},
|
|
810
824
|
server: null,
|
|
811
825
|
shared: null
|
|
@@ -1087,7 +1101,7 @@ export function create_client({ target, base, trailing_slash }) {
|
|
|
1087
1101
|
: routes;
|
|
1088
1102
|
|
|
1089
1103
|
const promises = matching.map((r) => {
|
|
1090
|
-
return Promise.all([...r.layouts, r.leaf].map((load) => load?.()));
|
|
1104
|
+
return Promise.all([...r.layouts, r.leaf].map((load) => load?.[1]()));
|
|
1091
1105
|
});
|
|
1092
1106
|
|
|
1093
1107
|
await Promise.all(promises);
|
|
@@ -2,19 +2,17 @@ import { exec, parse_route_id } from '../../utils/routing.js';
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @param {import('types').CSRPageNodeLoader[]} nodes
|
|
5
|
+
* @param {number[]} server_loads
|
|
5
6
|
* @param {typeof import('__GENERATED__/client-manifest.js').dictionary} dictionary
|
|
6
7
|
* @param {Record<string, (param: string) => boolean>} matchers
|
|
7
8
|
* @returns {import('types').CSRRoute[]}
|
|
8
9
|
*/
|
|
9
|
-
export function parse(nodes, dictionary, matchers) {
|
|
10
|
+
export function parse(nodes, server_loads, dictionary, matchers) {
|
|
11
|
+
const layouts_with_server_load = new Set(server_loads);
|
|
12
|
+
|
|
10
13
|
return Object.entries(dictionary).map(([id, [leaf, layouts, errors]]) => {
|
|
11
14
|
const { pattern, names, types } = parse_route_id(id);
|
|
12
15
|
|
|
13
|
-
// whether or not the route uses the server data is
|
|
14
|
-
// encoded using the ones' complement, to save space
|
|
15
|
-
const uses_server_data = leaf < 0;
|
|
16
|
-
if (uses_server_data) leaf = ~leaf;
|
|
17
|
-
|
|
18
16
|
const route = {
|
|
19
17
|
id,
|
|
20
18
|
/** @param {string} path */
|
|
@@ -23,9 +21,8 @@ export function parse(nodes, dictionary, matchers) {
|
|
|
23
21
|
if (match) return exec(match, names, types, matchers);
|
|
24
22
|
},
|
|
25
23
|
errors: [1, ...(errors || [])].map((n) => nodes[n]),
|
|
26
|
-
layouts: [0, ...(layouts || [])].map(
|
|
27
|
-
leaf:
|
|
28
|
-
uses_server_data
|
|
24
|
+
layouts: [0, ...(layouts || [])].map(create_layout_loader),
|
|
25
|
+
leaf: create_leaf_loader(leaf)
|
|
29
26
|
};
|
|
30
27
|
|
|
31
28
|
// bit of a hack, but ensures that layout/error node lists are the same
|
|
@@ -38,4 +35,26 @@ export function parse(nodes, dictionary, matchers) {
|
|
|
38
35
|
|
|
39
36
|
return route;
|
|
40
37
|
});
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @param {number} id
|
|
41
|
+
* @returns {[boolean, import('types').CSRPageNodeLoader]}
|
|
42
|
+
*/
|
|
43
|
+
function create_leaf_loader(id) {
|
|
44
|
+
// whether or not the route uses the server data is
|
|
45
|
+
// encoded using the ones' complement, to save space
|
|
46
|
+
const uses_server_data = id < 0;
|
|
47
|
+
if (uses_server_data) id = ~id;
|
|
48
|
+
return [uses_server_data, nodes[id]];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @param {number | undefined} id
|
|
53
|
+
* @returns {[boolean, import('types').CSRPageNodeLoader] | undefined}
|
|
54
|
+
*/
|
|
55
|
+
function create_layout_loader(id) {
|
|
56
|
+
// whether or not the layout uses the server data is
|
|
57
|
+
// encoded in the layouts array, to save space
|
|
58
|
+
return id === undefined ? id : [layouts_with_server_load.has(id), nodes[id]];
|
|
59
|
+
}
|
|
41
60
|
}
|
|
@@ -6,8 +6,8 @@ import {
|
|
|
6
6
|
prefetch,
|
|
7
7
|
prefetchRoutes
|
|
8
8
|
} from '$app/navigation';
|
|
9
|
-
import { CSRPageNode, CSRPageNodeLoader, CSRRoute,
|
|
10
|
-
import { HttpError } from '
|
|
9
|
+
import { CSRPageNode, CSRPageNodeLoader, CSRRoute, Uses } from 'types';
|
|
10
|
+
import { HttpError } from '../control.js';
|
|
11
11
|
import { SerializedHttpError } from '../server/page/types.js';
|
|
12
12
|
|
|
13
13
|
export interface Client {
|
|
File without changes
|
|
@@ -7,9 +7,9 @@ import { serialize_error, GENERIC_ERROR, error_to_pojo } from './utils.js';
|
|
|
7
7
|
import { decode_params, disable_search, normalize_path } from '../../utils/url.js';
|
|
8
8
|
import { exec } from '../../utils/routing.js';
|
|
9
9
|
import { negotiate } from '../../utils/http.js';
|
|
10
|
-
import { HttpError, Redirect } from '
|
|
10
|
+
import { HttpError, Redirect } from '../control.js';
|
|
11
11
|
import { load_server_data } from './page/load_data.js';
|
|
12
|
-
import { json } from '../../
|
|
12
|
+
import { json } from '../../exports/index.js';
|
|
13
13
|
import { once } from '../../utils/functions.js';
|
|
14
14
|
|
|
15
15
|
/* global __SVELTEKIT_ADAPTER_NAME__ */
|
|
@@ -3,8 +3,8 @@ import { render_response } from './render.js';
|
|
|
3
3
|
import { respond_with_error } from './respond_with_error.js';
|
|
4
4
|
import { method_not_allowed, error_to_pojo, allowed_methods } from '../utils.js';
|
|
5
5
|
import { create_fetch } from './fetch.js';
|
|
6
|
-
import { HttpError, Redirect } from '
|
|
7
|
-
import { error, json } from '../../../
|
|
6
|
+
import { HttpError, Redirect } from '../../control.js';
|
|
7
|
+
import { error, json } from '../../../exports/index.js';
|
|
8
8
|
import { compact } from '../../../utils/array.js';
|
|
9
9
|
import { normalize_error } from '../../../utils/error.js';
|
|
10
10
|
import { load_data, load_server_data } from './load_data.js';
|
|
@@ -6,7 +6,7 @@ import { render_json_payload_script } from '../../../utils/escape.js';
|
|
|
6
6
|
import { s } from '../../../utils/misc.js';
|
|
7
7
|
import { Csp } from './csp.js';
|
|
8
8
|
import { serialize_error } from '../utils.js';
|
|
9
|
-
import { HttpError } from '
|
|
9
|
+
import { HttpError } from '../../control.js';
|
|
10
10
|
|
|
11
11
|
// TODO rename this function/module
|
|
12
12
|
|
package/src/utils/error.js
CHANGED
package/types/ambient.d.ts
CHANGED
|
@@ -74,10 +74,10 @@ declare namespace App {
|
|
|
74
74
|
|
|
75
75
|
/**
|
|
76
76
|
* ```ts
|
|
77
|
-
* import { browser, dev, prerendering } from '$app/
|
|
77
|
+
* import { browser, dev, prerendering } from '$app/environment';
|
|
78
78
|
* ```
|
|
79
79
|
*/
|
|
80
|
-
declare module '$app/
|
|
80
|
+
declare module '$app/environment' {
|
|
81
81
|
/**
|
|
82
82
|
* `true` if the app is running in the browser.
|
|
83
83
|
*/
|
package/types/index.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
TrailingSlash
|
|
18
18
|
} from './private.js';
|
|
19
19
|
import { SSRNodeLoader, SSRRoute, ValidatedConfig } from './internal.js';
|
|
20
|
-
import { HttpError, Redirect } from '../src/
|
|
20
|
+
import { HttpError, Redirect } from '../src/runtime/control.js';
|
|
21
21
|
|
|
22
22
|
export interface Adapter {
|
|
23
23
|
name: string;
|
package/types/internal.d.ts
CHANGED
|
@@ -71,13 +71,16 @@ export interface CSRPageNode {
|
|
|
71
71
|
|
|
72
72
|
export type CSRPageNodeLoader = () => Promise<CSRPageNode>;
|
|
73
73
|
|
|
74
|
+
/**
|
|
75
|
+
* Definition of a client side route.
|
|
76
|
+
* The boolean in the tuples indicates whether the route has a server load.
|
|
77
|
+
*/
|
|
74
78
|
export type CSRRoute = {
|
|
75
79
|
id: string;
|
|
76
80
|
exec: (path: string) => undefined | Record<string, string>;
|
|
77
|
-
errors: CSRPageNodeLoader
|
|
78
|
-
layouts: CSRPageNodeLoader
|
|
79
|
-
leaf: CSRPageNodeLoader;
|
|
80
|
-
uses_server_data: boolean;
|
|
81
|
+
errors: Array<CSRPageNodeLoader | undefined>;
|
|
82
|
+
layouts: Array<[boolean, CSRPageNodeLoader] | undefined>;
|
|
83
|
+
leaf: [boolean, CSRPageNodeLoader];
|
|
81
84
|
};
|
|
82
85
|
|
|
83
86
|
export type GetParams = (match: RegExpExecArray) => Record<string, string>;
|