@sveltejs/kit 1.0.0-next.445 → 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
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,8 +60,8 @@
|
|
|
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
67
|
"import": "./src/exports/node/index.js"
|
|
@@ -43,22 +43,29 @@ 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) => {
|
|
49
51
|
if (route.page) {
|
|
50
52
|
const errors = route.page.errors.slice(1).map((n) => n ?? '');
|
|
51
|
-
const layouts = route.page.layouts.slice(1).map((n) =>
|
|
52
|
-
if (n == undefined) {
|
|
53
|
-
return '';
|
|
54
|
-
}
|
|
55
|
-
return get_node_id(manifest_data.nodes, n);
|
|
56
|
-
});
|
|
53
|
+
const layouts = route.page.layouts.slice(1).map((n) => n ?? '');
|
|
57
54
|
|
|
58
55
|
while (layouts.at(-1) === '') layouts.pop();
|
|
59
56
|
while (errors.at(-1) === '') errors.pop();
|
|
60
57
|
|
|
61
|
-
|
|
58
|
+
// Encode whether or not the route uses server data
|
|
59
|
+
// using the ones' complement, to save space
|
|
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
|
+
});
|
|
62
69
|
|
|
63
70
|
// only include non-root layout/error nodes if they exist
|
|
64
71
|
if (layouts.length > 0 || errors.length > 0) array.push(`[${layouts.join(',')}]`);
|
|
@@ -77,21 +84,11 @@ export function write_client_manifest(manifest_data, output) {
|
|
|
77
84
|
trim(`
|
|
78
85
|
export { matchers } from './client-matchers.js';
|
|
79
86
|
|
|
80
|
-
export const nodes = [
|
|
81
|
-
|
|
82
|
-
];
|
|
87
|
+
export const nodes = [${nodes}];
|
|
88
|
+
|
|
89
|
+
export const server_loads = [${[...layouts_with_server_load].join(',')}];
|
|
83
90
|
|
|
84
91
|
export const dictionary = ${dictionary};
|
|
85
92
|
`)
|
|
86
93
|
);
|
|
87
94
|
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Encode whether or not the route uses the server data
|
|
91
|
-
* using the ones' complement, to save space
|
|
92
|
-
* @param {import('types').PageNode[]} nodes
|
|
93
|
-
* @param {number} id
|
|
94
|
-
*/
|
|
95
|
-
function get_node_id(nodes, id) {
|
|
96
|
-
return `${nodes[id].server ? '~' : ''}${id}`;
|
|
97
|
-
}
|
|
@@ -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
17
|
* is parsed into an array of routes on startup. The numbers refer to the indices in `nodes`.
|
|
12
|
-
* If the number is negative, it means it does use a server load function and the complement is the node index.
|
|
18
|
+
* If the leaf number is negative, it means it does use a server load function and the complement is the node index.
|
|
13
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
|
}
|
|
@@ -7,14 +7,14 @@ import { parse } from './parse.js';
|
|
|
7
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';
|
|
10
|
+
import { nodes, server_loads, dictionary, matchers } from '__GENERATED__/client-manifest.js';
|
|
11
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];
|
|
@@ -2,11 +2,14 @@ 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
|
|
|
@@ -18,8 +21,8 @@ export function parse(nodes, dictionary, matchers) {
|
|
|
18
21
|
if (match) return exec(match, names, types, matchers);
|
|
19
22
|
},
|
|
20
23
|
errors: [1, ...(errors || [])].map((n) => nodes[n]),
|
|
21
|
-
layouts: [0, ...(layouts || [])].map(
|
|
22
|
-
leaf:
|
|
24
|
+
layouts: [0, ...(layouts || [])].map(create_layout_loader),
|
|
25
|
+
leaf: create_leaf_loader(leaf)
|
|
23
26
|
};
|
|
24
27
|
|
|
25
28
|
// bit of a hack, but ensures that layout/error node lists are the same
|
|
@@ -37,11 +40,21 @@ export function parse(nodes, dictionary, matchers) {
|
|
|
37
40
|
* @param {number} id
|
|
38
41
|
* @returns {[boolean, import('types').CSRPageNodeLoader]}
|
|
39
42
|
*/
|
|
40
|
-
function
|
|
43
|
+
function create_leaf_loader(id) {
|
|
41
44
|
// whether or not the route uses the server data is
|
|
42
45
|
// encoded using the ones' complement, to save space
|
|
43
46
|
const uses_server_data = id < 0;
|
|
44
47
|
if (uses_server_data) id = ~id;
|
|
45
48
|
return [uses_server_data, nodes[id]];
|
|
46
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
|
+
}
|
|
47
60
|
}
|