@sveltejs/kit 3.0.0-next.2 → 3.0.0-next.21
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 +62 -36
- package/src/cli.js +15 -12
- package/src/constants.js +6 -1
- package/src/core/adapt/builder.js +66 -72
- package/src/core/adapt/index.js +17 -6
- package/src/core/config/index.js +134 -80
- package/src/core/config/options.js +295 -273
- package/src/core/config/types.d.ts +1 -1
- package/src/core/env.js +146 -16
- package/src/core/generate_manifest/index.js +18 -15
- package/src/core/postbuild/analyse.js +8 -20
- package/src/core/postbuild/crawl.js +22 -6
- package/src/core/postbuild/entities.js +8 -2
- package/src/core/postbuild/fallback.js +4 -2
- package/src/core/postbuild/prerender.js +222 -70
- package/src/core/postbuild/queue.js +2 -1
- package/src/core/sync/create_manifest_data/conflict.js +1 -1
- package/src/core/sync/create_manifest_data/index.js +82 -62
- package/src/core/sync/sync.js +40 -31
- package/src/core/sync/ts.js +1 -1
- package/src/core/sync/utils.js +22 -2
- package/src/core/sync/{write_non_ambient.js → write_app_types.js} +107 -58
- package/src/core/sync/write_client_manifest.js +14 -29
- package/src/core/sync/write_env.js +7 -5
- package/src/core/sync/write_server.js +37 -45
- package/src/core/sync/write_tsconfig/index.js +274 -0
- package/src/core/sync/write_tsconfig/test-app/package.json +7 -0
- package/src/core/sync/write_tsconfig/utils.js +77 -0
- package/src/core/sync/write_tsconfig/validate.js +128 -0
- package/src/core/sync/write_types/index.js +127 -123
- package/src/core/utils.js +30 -5
- package/src/exports/env/index.js +77 -0
- package/src/exports/env/public.d.ts +55 -0
- package/src/exports/hooks/index.js +3 -9
- package/src/exports/hooks/public.d.ts +195 -0
- package/src/exports/hooks/sequence.js +9 -6
- package/src/exports/index.js +52 -29
- package/src/exports/internal/client.js +5 -0
- package/src/exports/internal/env.js +8 -5
- package/src/exports/internal/index.js +1 -90
- package/src/exports/internal/{event.js → server/event.js} +2 -3
- package/src/exports/internal/server/index.js +37 -0
- package/src/exports/internal/server/telemetry.js +95 -0
- package/src/exports/internal/shared.js +90 -0
- package/src/exports/node/index.js +64 -22
- package/src/exports/params/index.js +70 -0
- package/src/exports/params/public.d.ts +63 -0
- package/src/exports/public.d.ts +50 -1733
- package/src/exports/remote/index.js +11 -0
- package/src/exports/remote/public.d.ts +519 -0
- package/src/exports/url.js +86 -0
- package/src/exports/vite/build/build_server.js +54 -65
- package/src/exports/vite/build/remote.js +24 -19
- package/src/exports/vite/build/utils.js +0 -8
- package/src/exports/vite/dev/index.js +218 -146
- package/src/exports/vite/index.js +1590 -858
- package/src/exports/vite/module_ids.js +2 -2
- package/src/exports/vite/preview/index.js +40 -32
- package/src/exports/vite/public.d.ts +588 -0
- package/src/exports/vite/utils.js +84 -46
- package/src/pathname.js +55 -0
- package/src/runner.js +15 -0
- package/src/runtime/app/env/internal.js +4 -4
- package/src/runtime/app/env/types.d.ts +1 -1
- package/src/runtime/app/environment/index.js +3 -3
- package/src/runtime/app/{forms.js → forms/index.js} +73 -42
- package/src/runtime/app/forms/public.d.ts +2 -0
- package/src/runtime/app/forms/types.d.ts +56 -0
- package/src/runtime/app/internal/transport.js +53 -0
- package/src/runtime/app/manifest/index.js +1 -0
- package/src/runtime/app/{navigation.js → navigation/index.js} +2 -1
- package/src/runtime/app/navigation/public.d.ts +237 -0
- package/src/runtime/app/paths/client.js +37 -37
- package/src/runtime/app/paths/index.js +1 -1
- package/src/runtime/app/paths/internal/client.js +34 -2
- package/src/runtime/app/paths/internal/server.js +6 -23
- package/src/runtime/app/paths/internal.d.ts +3 -0
- package/src/runtime/app/paths/public.d.ts +1 -29
- package/src/runtime/app/paths/server.js +36 -17
- package/src/runtime/app/paths/types.d.ts +11 -19
- package/src/runtime/app/server/index.js +2 -2
- package/src/runtime/app/server/public.d.ts +201 -0
- package/src/runtime/app/server/remote/command.js +13 -11
- package/src/runtime/app/server/remote/form.js +61 -39
- package/src/runtime/app/server/remote/prerender.js +45 -45
- package/src/runtime/app/server/remote/query.js +106 -108
- package/src/runtime/app/server/remote/requested.js +27 -19
- package/src/runtime/app/server/remote/shared.js +76 -76
- package/src/runtime/app/service-worker/index.js +24 -0
- package/src/runtime/app/state/client.js +4 -2
- package/src/runtime/app/state/index.js +7 -5
- package/src/runtime/app/state/public.d.ts +72 -0
- package/src/runtime/app/state/server.js +3 -0
- package/src/runtime/app/stores.js +15 -78
- package/src/runtime/client/bundle.js +1 -1
- package/src/runtime/client/client-entry.js +3 -0
- package/src/runtime/client/client.js +1336 -648
- package/src/runtime/client/constants.js +3 -6
- package/src/runtime/client/entry.js +24 -3
- package/src/runtime/client/fetcher.js +25 -25
- package/src/runtime/client/ndjson.js +1 -1
- package/src/runtime/client/parse.js +1 -1
- package/src/runtime/client/payload.js +17 -0
- package/src/runtime/client/remote-functions/cache.svelte.js +3 -1
- package/src/runtime/client/remote-functions/command.svelte.js +37 -61
- package/src/runtime/client/remote-functions/form.svelte.js +267 -178
- package/src/runtime/client/remote-functions/prerender.svelte.js +32 -11
- package/src/runtime/client/remote-functions/query/index.js +10 -17
- package/src/runtime/client/remote-functions/query/instance.svelte.js +64 -18
- package/src/runtime/client/remote-functions/query/proxy.js +5 -5
- package/src/runtime/client/remote-functions/query-batch.svelte.js +61 -70
- package/src/runtime/client/remote-functions/query-live/index.js +1 -1
- package/src/runtime/client/remote-functions/query-live/instance.svelte.js +63 -21
- package/src/runtime/client/remote-functions/query-live/iterator.js +15 -12
- package/src/runtime/client/remote-functions/query-live/proxy.js +2 -12
- package/src/runtime/client/remote-functions/shared.svelte.js +90 -65
- package/src/runtime/client/snapshots.js +147 -0
- package/src/runtime/client/state.svelte.js +94 -55
- package/src/runtime/client/stream.js +3 -2
- package/src/runtime/client/types.d.ts +13 -9
- package/src/runtime/client/utils.js +22 -110
- package/src/runtime/components/root.svelte +56 -0
- package/src/runtime/env/dynamic/private.js +7 -0
- package/src/runtime/env/dynamic/public.js +7 -0
- package/src/runtime/env/static/private.js +6 -0
- package/src/runtime/env/static/public.js +6 -0
- package/src/runtime/form-utils.js +172 -61
- package/src/runtime/pathname.js +20 -32
- package/src/runtime/props.svelte.js +72 -0
- package/src/runtime/server/constants.js +0 -3
- package/src/runtime/server/cookie.js +72 -55
- package/src/runtime/server/csrf.js +65 -0
- package/src/runtime/server/data/index.js +49 -53
- package/src/runtime/server/dev.js +22 -0
- package/src/runtime/server/endpoint.js +6 -7
- package/src/runtime/server/env_module.js +0 -5
- package/src/runtime/server/errors.js +160 -0
- package/src/runtime/server/fetch.js +32 -39
- package/src/runtime/server/index.js +90 -64
- package/src/runtime/server/internal.js +71 -0
- package/src/runtime/server/page/actions.js +85 -64
- package/src/runtime/server/page/crypto.js +2 -2
- package/src/runtime/server/page/csp.js +88 -104
- package/src/runtime/server/page/data_serializer.js +24 -25
- package/src/runtime/server/page/index.js +36 -53
- package/src/runtime/server/page/load_data.js +50 -57
- package/src/runtime/server/page/render.js +173 -239
- package/src/runtime/server/page/respond_with_error.js +17 -31
- package/src/runtime/server/page/serialize_data.js +2 -13
- package/src/runtime/server/page/server_routing.js +85 -26
- package/src/runtime/server/remote-functions.js +640 -0
- package/src/runtime/server/respond.js +190 -131
- package/src/runtime/server/sourcemaps.js +183 -0
- package/src/runtime/server/state.js +53 -0
- package/src/runtime/server/utils.js +13 -155
- package/src/runtime/shared.js +20 -40
- package/src/runtime/utils.js +3 -0
- package/src/types/ambient-private.d.ts +11 -1
- package/src/types/ambient.d.ts +87 -36
- package/src/types/global-private.d.ts +25 -25
- package/src/types/internal.d.ts +163 -157
- package/src/types/private.d.ts +41 -1
- package/src/utils/error.js +28 -4
- package/src/utils/escape.js +9 -25
- package/src/utils/features.js +1 -1
- package/src/utils/filesystem.js +1 -23
- package/src/utils/fork.js +7 -2
- package/src/utils/hash.js +21 -0
- package/src/utils/http.js +8 -7
- package/src/utils/import.js +9 -2
- package/src/utils/imports.js +83 -0
- package/src/utils/mime.js +9 -0
- package/src/utils/page_nodes.js +6 -7
- package/src/utils/params.js +67 -0
- package/src/utils/regex.js +9 -0
- package/src/utils/routing.js +145 -73
- package/src/utils/shared-iterator.js +5 -0
- package/src/utils/streaming.js +14 -4
- package/src/utils/url.js +33 -2
- package/src/version.js +1 -1
- package/types/index.d.ts +2616 -2433
- package/types/index.d.ts.map +120 -106
- package/src/core/sync/write_ambient.js +0 -18
- package/src/core/sync/write_root.js +0 -148
- package/src/core/sync/write_tsconfig.js +0 -250
- package/src/exports/internal/server.js +0 -22
- package/src/exports/node/polyfills.js +0 -30
- package/src/runtime/server/app.js +0 -9
- package/src/runtime/server/remote.js +0 -457
- package/src/runtime/shared-server.js +0 -7
- package/src/runtime/telemetry/otel.js +0 -21
- package/src/runtime/telemetry/record_span.js +0 -65
- package/src/types/synthetic/$lib.md +0 -5
- /package/src/exports/internal/{remote-functions.js → server/remote-functions.js} +0 -0
- /package/src/{runtime/telemetry/noop.js → telemetry.js} +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Redirect } from '@sveltejs/kit/internal';
|
|
2
2
|
import { render_response } from './render.js';
|
|
3
3
|
import { load_data, load_server_data } from './load_data.js';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { redirect_response } from '../utils.js';
|
|
5
|
+
import { handle_error_and_jsonify, static_error_page } from '../errors.js';
|
|
6
6
|
import { PageNodes } from '../../../utils/page_nodes.js';
|
|
7
7
|
import { server_data_serializer } from './data_serializer.js';
|
|
8
8
|
|
|
@@ -12,48 +12,38 @@ import { server_data_serializer } from './data_serializer.js';
|
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* @param {{
|
|
15
|
-
* event: import('
|
|
16
|
-
*
|
|
15
|
+
* event: import('$app/server').RequestEvent;
|
|
16
|
+
* state: import('types').RequestState;
|
|
17
17
|
* options: import('types').SSROptions;
|
|
18
18
|
* manifest: import('@sveltejs/kit').SSRManifest;
|
|
19
|
-
* state: import('types').SSRState;
|
|
20
|
-
* status: number;
|
|
21
19
|
* error: unknown;
|
|
22
20
|
* resolve_opts: import('types').RequiredResolveOptions;
|
|
23
21
|
* }} opts
|
|
24
22
|
*/
|
|
25
|
-
export async function respond_with_error({
|
|
26
|
-
event,
|
|
27
|
-
event_state,
|
|
28
|
-
options,
|
|
29
|
-
manifest,
|
|
30
|
-
state,
|
|
31
|
-
status,
|
|
32
|
-
error,
|
|
33
|
-
resolve_opts
|
|
34
|
-
}) {
|
|
23
|
+
export async function respond_with_error({ event, state, options, manifest, error, resolve_opts }) {
|
|
35
24
|
// reroute to the fallback page to prevent an infinite chain of requests.
|
|
36
25
|
if (event.request.headers.get('x-sveltekit-error')) {
|
|
37
|
-
|
|
26
|
+
const transformed = await handle_error_and_jsonify(event, state, options, error);
|
|
27
|
+
return static_error_page(options, transformed.status, transformed.message);
|
|
38
28
|
}
|
|
39
29
|
|
|
40
30
|
/** @type {import('./types.js').Fetched[]} */
|
|
41
31
|
const fetched = [];
|
|
42
|
-
|
|
43
32
|
try {
|
|
44
33
|
const branch = [];
|
|
45
34
|
const default_layout = await manifest._.nodes[0](); // 0 is always the root layout
|
|
46
35
|
const nodes = new PageNodes([default_layout]);
|
|
47
36
|
const ssr = nodes.ssr();
|
|
48
37
|
const csr = nodes.csr();
|
|
49
|
-
const data_serializer = server_data_serializer(event,
|
|
38
|
+
const data_serializer = server_data_serializer(event, state, options);
|
|
39
|
+
// Do this here first in case the awaits below before rendering themselves error
|
|
40
|
+
const transformed = await handle_error_and_jsonify(event, state, options, error);
|
|
50
41
|
|
|
51
42
|
if (ssr) {
|
|
52
43
|
state.error = true;
|
|
53
44
|
|
|
54
45
|
const server_data_promise = load_server_data({
|
|
55
46
|
event,
|
|
56
|
-
event_state,
|
|
57
47
|
state,
|
|
58
48
|
node: default_layout,
|
|
59
49
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
@@ -65,14 +55,13 @@ export async function respond_with_error({
|
|
|
65
55
|
|
|
66
56
|
const data = await load_data({
|
|
67
57
|
event,
|
|
68
|
-
|
|
58
|
+
state,
|
|
69
59
|
fetched,
|
|
70
60
|
node: default_layout,
|
|
71
61
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
72
62
|
parent: async () => ({}),
|
|
73
63
|
resolve_opts,
|
|
74
64
|
server_data_promise,
|
|
75
|
-
state,
|
|
76
65
|
csr
|
|
77
66
|
});
|
|
78
67
|
|
|
@@ -93,18 +82,17 @@ export async function respond_with_error({
|
|
|
93
82
|
return await render_response({
|
|
94
83
|
options,
|
|
95
84
|
manifest,
|
|
96
|
-
state,
|
|
97
85
|
page_config: {
|
|
98
86
|
ssr,
|
|
99
87
|
csr
|
|
100
88
|
},
|
|
101
|
-
status,
|
|
102
|
-
error:
|
|
89
|
+
status: transformed.status,
|
|
90
|
+
error: transformed,
|
|
103
91
|
branch,
|
|
104
92
|
error_components: [],
|
|
105
93
|
fetched,
|
|
106
94
|
event,
|
|
107
|
-
|
|
95
|
+
state,
|
|
108
96
|
resolve_opts,
|
|
109
97
|
data_serializer
|
|
110
98
|
});
|
|
@@ -115,10 +103,8 @@ export async function respond_with_error({
|
|
|
115
103
|
return redirect_response(e.status, e.location);
|
|
116
104
|
}
|
|
117
105
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
(await handle_error_and_jsonify(event, event_state, options, e)).message
|
|
122
|
-
);
|
|
106
|
+
const transformed = await handle_error_and_jsonify(event, state, options, e);
|
|
107
|
+
|
|
108
|
+
return static_error_page(options, transformed.status, transformed.message);
|
|
123
109
|
}
|
|
124
110
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { escape_html } from '../../../utils/escape.js';
|
|
2
|
-
import {
|
|
2
|
+
import { hash_request } from '../../../utils/hash.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Inside a script element, only `</script` and `<!--` hold special meaning to the HTML parser.
|
|
@@ -78,18 +78,7 @@ export function serialize_data(fetched, filter, prerendering = false) {
|
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
if (fetched.request_headers || fetched.request_body) {
|
|
81
|
-
|
|
82
|
-
const values = [];
|
|
83
|
-
|
|
84
|
-
if (fetched.request_headers) {
|
|
85
|
-
values.push([...new Headers(fetched.request_headers)].join(','));
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (fetched.request_body) {
|
|
89
|
-
values.push(fetched.request_body);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
attrs.push(`data-hash="${hash(...values)}"`);
|
|
81
|
+
attrs.push(`data-hash="${hash_request(fetched.request_headers, fetched.request_body)}"`);
|
|
93
82
|
}
|
|
94
83
|
|
|
95
84
|
// Compute the time the response should be cached, taking into account max-age and age.
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
/** @import { SSRManifest } from '@sveltejs/kit' */
|
|
2
|
+
import { base, assets } from '#app/paths';
|
|
3
|
+
import { relative } from '$app/paths/internal/server';
|
|
2
4
|
import { text } from '@sveltejs/kit';
|
|
3
5
|
import { s } from '../../../utils/misc.js';
|
|
4
6
|
import { find_route } from '../../../utils/routing.js';
|
|
@@ -7,19 +9,19 @@ import { get_relative_path } from '../../utils.js';
|
|
|
7
9
|
/**
|
|
8
10
|
* @param {import('types').SSRClientRoute} route
|
|
9
11
|
* @param {URL} url
|
|
10
|
-
* @param {
|
|
12
|
+
* @param {NonNullable<SSRManifest['_']['client']>} client
|
|
11
13
|
* @returns {string}
|
|
12
14
|
*/
|
|
13
|
-
export function generate_route_object(route, url,
|
|
15
|
+
export function generate_route_object(route, url, client) {
|
|
14
16
|
const { errors, layouts, leaf } = route;
|
|
15
17
|
|
|
16
18
|
const nodes = [...errors, ...layouts.map((l) => l?.[1]), leaf[1]]
|
|
17
19
|
.filter((n) => typeof n === 'number')
|
|
18
|
-
.map((n) => `'${n}': () => ${create_client_import(
|
|
20
|
+
.map((n) => `'${n}': () => ${create_client_import(client.nodes?.[n], url)}`)
|
|
19
21
|
.join(',\n\t\t');
|
|
20
22
|
|
|
21
23
|
// stringified version of
|
|
22
|
-
|
|
24
|
+
/* @type {import('types').CSRRouteServer} */
|
|
23
25
|
return [
|
|
24
26
|
`{\n\tid: ${s(route.id)}`,
|
|
25
27
|
`errors: ${s(route.errors)}`,
|
|
@@ -60,41 +62,98 @@ function create_client_import(import_path, url) {
|
|
|
60
62
|
/**
|
|
61
63
|
* @param {string} resolved_path
|
|
62
64
|
* @param {URL} url
|
|
63
|
-
* @param {
|
|
65
|
+
* @param {SSRManifest} manifest
|
|
64
66
|
* @returns {Promise<Response>}
|
|
65
67
|
*/
|
|
66
68
|
export async function resolve_route(resolved_path, url, manifest) {
|
|
67
|
-
if (!manifest._.client
|
|
69
|
+
if (!manifest._.client?.routes) {
|
|
68
70
|
return text('Server-side route resolution disabled', { status: 400 });
|
|
69
71
|
}
|
|
70
72
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
+
try {
|
|
74
|
+
const matchers = await manifest._.matchers();
|
|
75
|
+
const result = find_route(resolved_path, manifest._.client.routes, matchers);
|
|
76
|
+
|
|
77
|
+
return create_server_routing_response(
|
|
78
|
+
result?.route ?? null,
|
|
79
|
+
result?.params ?? {},
|
|
80
|
+
url,
|
|
81
|
+
manifest._.client
|
|
82
|
+
).response;
|
|
83
|
+
} catch {
|
|
84
|
+
return text('Error resolving route', { status: 500 });
|
|
85
|
+
}
|
|
86
|
+
}
|
|
73
87
|
|
|
74
|
-
|
|
75
|
-
|
|
88
|
+
/**
|
|
89
|
+
* Resolve a route-ID resolution request (`/_app/routes/<id>/__route.js`) to a
|
|
90
|
+
* JS module containing the route's node loaders. Params are always `{}` since
|
|
91
|
+
* this endpoint exists to support `preloadCode(routeId)`, which doesn't need them.
|
|
92
|
+
*
|
|
93
|
+
* The module has one of three shapes, which the client uses to tell three cases apart:
|
|
94
|
+
*
|
|
95
|
+
* - `export const route = {...}` — a page route, with loaders to import
|
|
96
|
+
* - `export const endpoint_only = true` — a real route with no `+page`, so there is
|
|
97
|
+
* nothing to preload, but the client can cache that fact and stop asking
|
|
98
|
+
* - an empty module — no such route
|
|
99
|
+
*
|
|
100
|
+
* @param {string} route_id
|
|
101
|
+
* @param {URL} url
|
|
102
|
+
* @param {SSRManifest} manifest
|
|
103
|
+
* @returns {Response}
|
|
104
|
+
*/
|
|
105
|
+
export function resolve_route_by_id(route_id, url, manifest) {
|
|
106
|
+
if (!manifest._.client?.routes) {
|
|
107
|
+
return text('Server-side route resolution disabled', { status: 400 });
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
try {
|
|
111
|
+
const route = manifest._.client.routes.find((r) => r.id === route_id);
|
|
112
|
+
|
|
113
|
+
if (route) {
|
|
114
|
+
return create_server_routing_response(route, null, url, manifest._.client).response;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// `client.routes` only contains routes with a `+page`, so a miss above doesn't mean the
|
|
118
|
+
// route doesn't exist — it might be a `+server.js`-only route. `_.routes` includes those
|
|
119
|
+
// (with `page: null`), so we can distinguish "exists but has no code" from "unknown".
|
|
120
|
+
if (manifest._.routes.some((r) => r.id === route_id && !r.page)) {
|
|
121
|
+
return text('export const endpoint_only = true;', { headers: js_headers() });
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return create_server_routing_response(null, null, url, manifest._.client).response;
|
|
125
|
+
} catch {
|
|
126
|
+
return text('Error resolving route', { status: 500 });
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function js_headers() {
|
|
131
|
+
return new Headers({
|
|
132
|
+
'content-type': 'application/javascript; charset=utf-8'
|
|
133
|
+
});
|
|
76
134
|
}
|
|
77
135
|
|
|
78
136
|
/**
|
|
79
137
|
* @param {import('types').SSRClientRoute | null} route
|
|
80
|
-
* @param {Partial<Record<string, string>>} params
|
|
138
|
+
* @param {Partial<Record<string, string>> | null} params
|
|
81
139
|
* @param {URL} url
|
|
82
|
-
* @param {
|
|
140
|
+
* @param {NonNullable<SSRManifest['_']['client']>} client
|
|
83
141
|
* @returns {{response: Response, body: string}}
|
|
84
142
|
*/
|
|
85
|
-
export function create_server_routing_response(route, params, url,
|
|
86
|
-
const headers =
|
|
87
|
-
|
|
88
|
-
});
|
|
143
|
+
export function create_server_routing_response(route, params, url, client) {
|
|
144
|
+
const headers = js_headers();
|
|
145
|
+
let body = '';
|
|
89
146
|
|
|
90
147
|
if (route) {
|
|
91
|
-
const csr_route = generate_route_object(route, url,
|
|
92
|
-
|
|
148
|
+
const csr_route = generate_route_object(route, url, client);
|
|
149
|
+
body = `${create_css_import(route, url, client)}export const route = ${csr_route};`;
|
|
93
150
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
151
|
+
if (params !== null) {
|
|
152
|
+
body += `\nexport const params = ${JSON.stringify(params)}`;
|
|
153
|
+
}
|
|
97
154
|
}
|
|
155
|
+
|
|
156
|
+
return { response: text(body, { headers }), body };
|
|
98
157
|
}
|
|
99
158
|
|
|
100
159
|
/**
|
|
@@ -105,17 +164,17 @@ export function create_server_routing_response(route, params, url, manifest) {
|
|
|
105
164
|
*
|
|
106
165
|
* @param {import('types').SSRClientRoute} route
|
|
107
166
|
* @param {URL} url
|
|
108
|
-
* @param {
|
|
167
|
+
* @param {NonNullable<SSRManifest['_']['client']>} client
|
|
109
168
|
* @returns {string}
|
|
110
169
|
*/
|
|
111
|
-
function create_css_import(route, url,
|
|
170
|
+
function create_css_import(route, url, client) {
|
|
112
171
|
const { errors, layouts, leaf } = route;
|
|
113
172
|
|
|
114
173
|
let css = '';
|
|
115
174
|
|
|
116
175
|
for (const node of [...errors, ...layouts.map((l) => l?.[1]), leaf[1]]) {
|
|
117
176
|
if (typeof node !== 'number') continue;
|
|
118
|
-
const node_css =
|
|
177
|
+
const node_css = client.css?.[node];
|
|
119
178
|
for (const css_path of node_css ?? []) {
|
|
120
179
|
css += `'${assets || base}/${css_path}',`;
|
|
121
180
|
}
|
|
@@ -123,5 +182,5 @@ function create_css_import(route, url, manifest) {
|
|
|
123
182
|
|
|
124
183
|
if (!css) return '';
|
|
125
184
|
|
|
126
|
-
return `${create_client_import(
|
|
185
|
+
return `${create_client_import(client.start, url)}.then(x => x.load_css([${css}]));\n`;
|
|
127
186
|
}
|