@sveltejs/kit 2.63.0 → 3.0.0-next.1
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 +17 -22
- package/src/cli.js +19 -16
- package/src/core/adapt/builder.js +25 -77
- package/src/core/adapt/index.js +6 -4
- package/src/core/config/index.js +12 -84
- package/src/core/config/options.js +36 -46
- package/src/core/env.js +5 -130
- package/src/core/generate_manifest/find_server_assets.js +3 -2
- package/src/core/generate_manifest/index.js +11 -3
- package/src/core/postbuild/analyse.js +19 -16
- package/src/core/postbuild/fallback.js +0 -3
- package/src/core/postbuild/prerender.js +18 -17
- package/src/core/postbuild/queue.js +3 -4
- package/src/core/sync/create_manifest_data/index.js +16 -18
- package/src/core/sync/sync.js +30 -25
- package/src/core/sync/utils.js +0 -15
- package/src/core/sync/write_ambient.js +3 -54
- package/src/core/sync/write_client_manifest.js +8 -9
- package/src/core/sync/write_env.js +5 -1
- package/src/core/sync/write_non_ambient.js +7 -7
- package/src/core/sync/write_root.js +40 -88
- package/src/core/sync/write_server.js +16 -23
- package/src/core/sync/write_tsconfig.js +28 -24
- package/src/core/sync/write_types/index.js +31 -25
- package/src/core/utils.js +14 -11
- package/src/exports/index.js +8 -21
- package/src/exports/node/index.js +8 -13
- package/src/exports/public.d.ts +35 -76
- package/src/exports/vite/build/build_server.js +14 -11
- package/src/exports/vite/build/remote.js +6 -7
- package/src/exports/vite/build/utils.js +7 -5
- package/src/exports/vite/dev/index.js +30 -31
- package/src/exports/vite/index.js +938 -732
- package/src/exports/vite/module_ids.js +1 -6
- package/src/exports/vite/options.js +17 -0
- package/src/exports/vite/preview/index.js +3 -5
- package/src/exports/vite/static_analysis/index.js +11 -5
- package/src/exports/vite/utils.js +9 -45
- package/src/runtime/app/env/internal.js +3 -0
- package/src/runtime/app/env/public/client.js +0 -6
- package/src/runtime/app/env/public/server.js +0 -6
- package/src/runtime/app/environment/index.js +3 -7
- package/src/runtime/app/server/index.js +4 -2
- package/src/runtime/app/server/remote/form.js +0 -51
- package/src/runtime/app/server/remote/query.js +0 -7
- package/src/runtime/app/server/remote/shared.js +4 -3
- package/src/runtime/app/state/client.js +1 -12
- package/src/runtime/client/client.js +1 -1
- package/src/runtime/client/constants.js +0 -1
- package/src/runtime/client/remote-functions/form.svelte.js +0 -31
- package/src/runtime/client/remote-functions/query/index.js +2 -2
- package/src/runtime/client/remote-functions/query/instance.svelte.js +1 -2
- package/src/runtime/client/remote-functions/query-batch.svelte.js +2 -2
- package/src/runtime/client/remote-functions/query-live/instance.svelte.js +5 -8
- package/src/runtime/client/utils.js +8 -10
- package/src/runtime/components/{svelte-5/layout.svelte → layout.svelte} +1 -1
- package/src/runtime/form-utils.js +4 -41
- package/src/runtime/server/cookie.js +21 -37
- package/src/runtime/server/env_module.js +1 -3
- package/src/runtime/server/fetch.js +6 -10
- package/src/runtime/server/index.js +3 -9
- package/src/runtime/server/page/render.js +32 -44
- package/src/runtime/server/page/types.d.ts +4 -2
- package/src/runtime/server/respond.js +2 -2
- package/src/runtime/server/utils.js +2 -4
- package/src/runtime/shared-server.js +0 -22
- package/src/runtime/shared.js +0 -15
- package/src/types/global-private.d.ts +5 -1
- package/src/types/internal.d.ts +3 -8
- package/src/utils/css.js +3 -19
- package/src/utils/filesystem.js +1 -30
- package/src/utils/http.js +0 -21
- package/src/utils/import.js +7 -6
- package/src/utils/os.js +7 -0
- package/src/utils/path.js +23 -0
- package/src/utils/shared-iterator.js +3 -0
- package/src/utils/streaming.js +2 -4
- package/src/utils/url.js +1 -1
- package/src/utils/vite.js +28 -0
- package/src/version.js +1 -1
- package/types/index.d.ts +45 -138
- package/types/index.d.ts.map +1 -8
- package/src/exports/vite/build/build_service_worker.js +0 -165
- package/src/runtime/app/environment/types.d.ts +0 -19
- package/src/runtime/components/svelte-4/error.svelte +0 -6
- package/src/runtime/components/svelte-4/layout.svelte +0 -1
- package/src/runtime/env/dynamic/private.js +0 -1
- package/src/runtime/env/dynamic/public.js +0 -1
- package/src/types/synthetic/$env+dynamic+private.md +0 -43
- package/src/types/synthetic/$env+dynamic+public.md +0 -46
- package/src/types/synthetic/$env+static+private.md +0 -31
- package/src/types/synthetic/$env+static+public.md +0 -31
- package/src/utils/env.js +0 -13
- package/src/utils/promise.js +0 -29
- /package/src/runtime/components/{svelte-5/error.svelte → error.svelte} +0 -0
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/** @import { RemoteForm } from '@sveltejs/kit' */
|
|
2
1
|
/** @import { BinaryFormMeta, InternalRemoteFormIssue } from 'types' */
|
|
3
2
|
/** @import { StandardSchemaV1 } from '@standard-schema/spec' */
|
|
4
3
|
|
|
@@ -146,7 +145,10 @@ export async function deserialize_binary_form(request) {
|
|
|
146
145
|
throw deserialize_error('no body');
|
|
147
146
|
}
|
|
148
147
|
|
|
149
|
-
|
|
148
|
+
// TODO: remove this workaround once we upgrade to TS 6.0
|
|
149
|
+
const reader = /** @type {ReadableStreamDefaultReader<Uint8Array<ArrayBuffer>>} */ (
|
|
150
|
+
request.body.getReader()
|
|
151
|
+
);
|
|
150
152
|
|
|
151
153
|
/** @type {Array<Promise<Uint8Array<ArrayBuffer> | undefined>>} */
|
|
152
154
|
const chunks = [];
|
|
@@ -858,42 +860,3 @@ export function build_path_string(path) {
|
|
|
858
860
|
|
|
859
861
|
return result;
|
|
860
862
|
}
|
|
861
|
-
|
|
862
|
-
/**
|
|
863
|
-
* @param {RemoteForm<any, any>} instance
|
|
864
|
-
* @deprecated remove in 3.0
|
|
865
|
-
*/
|
|
866
|
-
export function throw_on_old_property_access(instance) {
|
|
867
|
-
Object.defineProperty(instance, 'field', {
|
|
868
|
-
value: (/** @type {string} */ name) => {
|
|
869
|
-
const new_name = name.endsWith('[]') ? name.slice(0, -2) : name;
|
|
870
|
-
throw new Error(
|
|
871
|
-
`\`form.field\` has been removed: Instead of \`<input name={form.field('${name}')} />\` do \`<input {...form.fields.${new_name}.as(type)} />\``
|
|
872
|
-
);
|
|
873
|
-
}
|
|
874
|
-
});
|
|
875
|
-
|
|
876
|
-
for (const property of ['input', 'issues']) {
|
|
877
|
-
Object.defineProperty(instance, property, {
|
|
878
|
-
get() {
|
|
879
|
-
const new_name = property === 'issues' ? 'issues' : 'value';
|
|
880
|
-
return new Proxy(
|
|
881
|
-
{},
|
|
882
|
-
{
|
|
883
|
-
get(_, prop) {
|
|
884
|
-
const prop_string = typeof prop === 'string' ? prop : String(prop);
|
|
885
|
-
const old =
|
|
886
|
-
prop_string.includes('[') || prop_string.includes('.')
|
|
887
|
-
? `['${prop_string}']`
|
|
888
|
-
: `.${prop_string}`;
|
|
889
|
-
const replacement = `.${prop_string}.${new_name}()`;
|
|
890
|
-
throw new Error(
|
|
891
|
-
`\`form.${property}\` has been removed: Instead of \`form.${property}${old}\` write \`form.fields${replacement}\``
|
|
892
|
-
);
|
|
893
|
-
}
|
|
894
|
-
}
|
|
895
|
-
);
|
|
896
|
-
}
|
|
897
|
-
});
|
|
898
|
-
}
|
|
899
|
-
}
|
|
@@ -4,9 +4,6 @@ import { normalize_path, resolve } from '../../utils/url.js';
|
|
|
4
4
|
import { add_data_suffix } from '../pathname.js';
|
|
5
5
|
import { text_encoder } from '../utils.js';
|
|
6
6
|
|
|
7
|
-
// eslint-disable-next-line no-control-regex -- control characters are invalid in cookie names
|
|
8
|
-
const INVALID_COOKIE_CHARACTER_REGEX = /[\x00-\x1F\x7F()<>@,;:"/[\]?={} \t]/;
|
|
9
|
-
|
|
10
7
|
/**
|
|
11
8
|
* Tracks all cookies set during dev mode so we can emit warnings
|
|
12
9
|
* when we detect that there's likely cookie misusage due to wrong paths
|
|
@@ -20,14 +17,6 @@ const cookie_paths = {};
|
|
|
20
17
|
*/
|
|
21
18
|
const MAX_COOKIE_SIZE = 4129;
|
|
22
19
|
|
|
23
|
-
// TODO 3.0 remove this check
|
|
24
|
-
/** @param {import('./page/types.js').Cookie['options']} options */
|
|
25
|
-
function validate_options(options) {
|
|
26
|
-
if (options?.path === undefined) {
|
|
27
|
-
throw new Error('You must specify a `path` when setting, deleting or serializing cookies');
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
20
|
/**
|
|
32
21
|
* Generates a unique key for a cookie based on its domain, path, and name in
|
|
33
22
|
* the format: `<domain>/<path>?<name>`.
|
|
@@ -49,7 +38,9 @@ function generate_cookie_key(domain, path, name) {
|
|
|
49
38
|
*/
|
|
50
39
|
export function get_cookies(request, url) {
|
|
51
40
|
const header = request.headers.get('cookie') ?? '';
|
|
52
|
-
const initial_cookies =
|
|
41
|
+
const initial_cookies = /** @type {Record<string, string>} */ (
|
|
42
|
+
parse(header, { decode: (value) => value })
|
|
43
|
+
);
|
|
53
44
|
|
|
54
45
|
/** @type {string | undefined} */
|
|
55
46
|
let normalized_url;
|
|
@@ -57,9 +48,10 @@ export function get_cookies(request, url) {
|
|
|
57
48
|
/** @type {Map<string, import('./page/types.js').Cookie>} */
|
|
58
49
|
const new_cookies = new Map();
|
|
59
50
|
|
|
60
|
-
/** @type {import('cookie').
|
|
51
|
+
/** @type {import('cookie').SerializeOptions} */
|
|
61
52
|
const defaults = {
|
|
62
53
|
httpOnly: true,
|
|
54
|
+
path: '/',
|
|
63
55
|
sameSite: 'lax',
|
|
64
56
|
secure: url.hostname === 'localhost' && url.protocol === 'http:' ? false : true
|
|
65
57
|
};
|
|
@@ -73,7 +65,7 @@ export function get_cookies(request, url) {
|
|
|
73
65
|
|
|
74
66
|
/**
|
|
75
67
|
* @param {string} name
|
|
76
|
-
* @param {import('cookie').
|
|
68
|
+
* @param {import('cookie').ParseOptions} [opts]
|
|
77
69
|
*/
|
|
78
70
|
get(name, opts) {
|
|
79
71
|
// Look for the most specific matching cookie from new_cookies
|
|
@@ -115,7 +107,7 @@ export function get_cookies(request, url) {
|
|
|
115
107
|
},
|
|
116
108
|
|
|
117
109
|
/**
|
|
118
|
-
* @param {import('cookie').
|
|
110
|
+
* @param {import('cookie').ParseOptions} [opts]
|
|
119
111
|
*/
|
|
120
112
|
getAll(opts) {
|
|
121
113
|
const cookies = parse(header, { decode: opts?.decode });
|
|
@@ -142,47 +134,37 @@ export function get_cookies(request, url) {
|
|
|
142
134
|
cookies[c.name] = c.value;
|
|
143
135
|
}
|
|
144
136
|
|
|
145
|
-
return
|
|
137
|
+
return /** @type {Array<{ name: string; value: string }>} */ (
|
|
138
|
+
Object.entries(cookies)
|
|
139
|
+
.filter(([, value]) => value != null)
|
|
140
|
+
.map(([name, value]) => ({ name, value }))
|
|
141
|
+
);
|
|
146
142
|
},
|
|
147
143
|
|
|
148
144
|
/**
|
|
149
145
|
* @param {string} name
|
|
150
146
|
* @param {string} value
|
|
151
|
-
* @param {import('
|
|
147
|
+
* @param {import('cookie').SerializeOptions} options
|
|
152
148
|
*/
|
|
153
149
|
set(name, value, options) {
|
|
154
|
-
// TODO: remove this check in 3.0
|
|
155
|
-
const illegal_characters = name.match(INVALID_COOKIE_CHARACTER_REGEX);
|
|
156
|
-
if (illegal_characters) {
|
|
157
|
-
console.warn(
|
|
158
|
-
`The cookie name "${name}" will be invalid in SvelteKit 3.0 as it contains ${illegal_characters.join(
|
|
159
|
-
' and '
|
|
160
|
-
)}. See RFC 2616 for more details https://datatracker.ietf.org/doc/html/rfc2616#section-2.2`
|
|
161
|
-
);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
validate_options(options);
|
|
165
150
|
set_internal(name, value, { ...defaults, ...options });
|
|
166
151
|
},
|
|
167
152
|
|
|
168
153
|
/**
|
|
169
154
|
* @param {string} name
|
|
170
|
-
*
|
|
155
|
+
* @param {import('cookie').SerializeOptions} options
|
|
171
156
|
*/
|
|
172
157
|
delete(name, options) {
|
|
173
|
-
validate_options(options);
|
|
174
158
|
cookies.set(name, '', { ...options, maxAge: 0 });
|
|
175
159
|
},
|
|
176
160
|
|
|
177
161
|
/**
|
|
178
162
|
* @param {string} name
|
|
179
163
|
* @param {string} value
|
|
180
|
-
*
|
|
164
|
+
* @param {import('cookie').SerializeOptions} options
|
|
181
165
|
*/
|
|
182
166
|
serialize(name, value, options) {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
let path = options.path;
|
|
167
|
+
let path = options.path ?? '/';
|
|
186
168
|
|
|
187
169
|
if (!options.domain || options.domain === url.hostname) {
|
|
188
170
|
if (!normalized_url) {
|
|
@@ -217,7 +199,9 @@ export function get_cookies(request, url) {
|
|
|
217
199
|
|
|
218
200
|
// explicit header has highest precedence
|
|
219
201
|
if (header) {
|
|
220
|
-
const parsed =
|
|
202
|
+
const parsed = /** @type {Record<string, string>} */ (
|
|
203
|
+
parse(header, { decode: (value) => value })
|
|
204
|
+
);
|
|
221
205
|
for (const name in parsed) {
|
|
222
206
|
combined_cookies[name] = parsed[name];
|
|
223
207
|
}
|
|
@@ -234,7 +218,7 @@ export function get_cookies(request, url) {
|
|
|
234
218
|
/**
|
|
235
219
|
* @param {string} name
|
|
236
220
|
* @param {string} value
|
|
237
|
-
* @param {import('
|
|
221
|
+
* @param {import('cookie').SerializeOptions} options
|
|
238
222
|
*/
|
|
239
223
|
function set_internal(name, value, options) {
|
|
240
224
|
if (!normalized_url) {
|
|
@@ -242,7 +226,7 @@ export function get_cookies(request, url) {
|
|
|
242
226
|
return;
|
|
243
227
|
}
|
|
244
228
|
|
|
245
|
-
let path = options.path;
|
|
229
|
+
let path = options.path ?? '/';
|
|
246
230
|
|
|
247
231
|
if (!options.domain || options.domain === url.hostname) {
|
|
248
232
|
path = resolve(normalized_url, path);
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import * as devalue from 'devalue';
|
|
2
|
-
import { public_env } from '../shared-server.js';
|
|
3
2
|
import { rendered_env } from '__sveltekit/env';
|
|
4
3
|
|
|
5
4
|
/** @type {string} */
|
|
@@ -16,10 +15,9 @@ let headers;
|
|
|
16
15
|
* @returns {Response}
|
|
17
16
|
*/
|
|
18
17
|
export function get_public_env(request) {
|
|
18
|
+
const env = rendered_env;
|
|
19
19
|
const script = request.url.endsWith('.script.js');
|
|
20
20
|
|
|
21
|
-
const env = __SVELTEKIT_EXPERIMENTAL_EXPLICIT_ENVIRONMENT_VARIABLES__ ? rendered_env : public_env;
|
|
22
|
-
|
|
23
21
|
payload ??= devalue.uneval(env);
|
|
24
22
|
etag ??= `W/${Date.now()}`;
|
|
25
23
|
headers ??= new Headers({
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { parseSetCookie } from 'cookie';
|
|
2
2
|
import { noop } from '../../utils/functions.js';
|
|
3
|
-
import { get_set_cookies } from '../../utils/http.js';
|
|
4
3
|
import { respond } from './respond.js';
|
|
5
4
|
import * as paths from '$app/paths/internal/server';
|
|
6
5
|
import { read_implementation } from '__sveltekit/server';
|
|
@@ -83,9 +82,8 @@ export function create_fetch({ event, options, manifest, state, get_cookie_heade
|
|
|
83
82
|
|
|
84
83
|
// handle fetch requests for static assets. e.g. prebaked data, etc.
|
|
85
84
|
// we need to support everything the browser's fetch supports
|
|
86
|
-
const prefix = paths.assets || paths.base;
|
|
87
85
|
const filename = (
|
|
88
|
-
decoded.startsWith(
|
|
86
|
+
decoded.startsWith(paths.assets) ? decoded.slice(paths.assets.length) : decoded
|
|
89
87
|
).slice(1);
|
|
90
88
|
const filename_html = `${filename}/index.html`; // path may also match path/index.html
|
|
91
89
|
|
|
@@ -153,18 +151,16 @@ export function create_fetch({ event, options, manifest, state, get_cookie_heade
|
|
|
153
151
|
|
|
154
152
|
const response = await internal_fetch(request, options, manifest, state);
|
|
155
153
|
|
|
156
|
-
for (const str of
|
|
157
|
-
const { name, value, ...options } =
|
|
158
|
-
decodeValues: false
|
|
159
|
-
});
|
|
154
|
+
for (const str of response.headers.getSetCookie()) {
|
|
155
|
+
const { name, value, ...options } = parseSetCookie(str, { decode: (v) => v });
|
|
160
156
|
|
|
161
157
|
const path = options.path ?? (url.pathname.split('/').slice(0, -1).join('/') || '/');
|
|
162
158
|
|
|
163
159
|
// options.sameSite is string, something more specific is required - type cast is safe
|
|
164
|
-
set_internal(name, value, {
|
|
160
|
+
set_internal(name, /** @type {string} */ (value), {
|
|
165
161
|
path,
|
|
166
162
|
encode: (value) => value,
|
|
167
|
-
.../** @type {import('cookie').
|
|
163
|
+
.../** @type {import('cookie').SerializeOptions} */ (options)
|
|
168
164
|
});
|
|
169
165
|
}
|
|
170
166
|
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
/** @import { PromiseWithResolvers } from '../../utils/promise.js' */
|
|
2
1
|
import { noop } from '../../utils/functions.js';
|
|
3
|
-
import { with_resolvers } from '../../utils/promise.js';
|
|
4
2
|
import { IN_WEBCONTAINER } from './constants.js';
|
|
5
3
|
import { respond } from './respond.js';
|
|
6
|
-
import { set_private_env, set_public_env } from '../shared-server.js';
|
|
7
4
|
import { options, get_hooks } from '__SERVER__/internal.js';
|
|
8
|
-
import { filter_env } from '../../utils/env.js';
|
|
9
5
|
import { format_server_error } from './utils.js';
|
|
10
6
|
import { set_read_implementation, set_manifest } from '__sveltekit/server';
|
|
11
7
|
import { set_env } from '__sveltekit/env';
|
|
@@ -37,7 +33,9 @@ export class Server {
|
|
|
37
33
|
|
|
38
34
|
/** @type {typeof respond} */
|
|
39
35
|
this.respond = async (...args) => {
|
|
40
|
-
const { promise, resolve } = /** @type {PromiseWithResolvers<void>} */ (
|
|
36
|
+
const { promise, resolve } = /** @type {PromiseWithResolvers<void>} */ (
|
|
37
|
+
Promise.withResolvers()
|
|
38
|
+
);
|
|
41
39
|
|
|
42
40
|
const previous = current;
|
|
43
41
|
current = promise;
|
|
@@ -59,10 +57,6 @@ export class Server {
|
|
|
59
57
|
// been done already.
|
|
60
58
|
|
|
61
59
|
// set env, in case it's used in initialisation
|
|
62
|
-
const { env_public_prefix, env_private_prefix } = this.#options;
|
|
63
|
-
|
|
64
|
-
set_private_env(filter_env(env, env_private_prefix, env_public_prefix));
|
|
65
|
-
set_public_env(filter_env(env, env_public_prefix, env_private_prefix));
|
|
66
60
|
set_env(env);
|
|
67
61
|
|
|
68
62
|
if (read) {
|
|
@@ -8,7 +8,6 @@ import { serialize_data } from './serialize_data.js';
|
|
|
8
8
|
import { s } from '../../../utils/misc.js';
|
|
9
9
|
import { Csp } from './csp.js';
|
|
10
10
|
import { uneval_action_response } from './actions.js';
|
|
11
|
-
import { public_env } from '../../shared-server.js';
|
|
12
11
|
import { SVELTE_KIT_ASSETS } from '../../../constants.js';
|
|
13
12
|
import { SCHEME } from '../../../utils/url.js';
|
|
14
13
|
import { create_server_routing_response, generate_route_object } from './server_routing.js';
|
|
@@ -294,7 +293,7 @@ export async function render_response({
|
|
|
294
293
|
}
|
|
295
294
|
}
|
|
296
295
|
|
|
297
|
-
const head = new Head(rendered.head
|
|
296
|
+
const head = new Head(rendered.head);
|
|
298
297
|
let body = rendered.html;
|
|
299
298
|
|
|
300
299
|
/** @param {string} path */
|
|
@@ -332,7 +331,7 @@ export async function render_response({
|
|
|
332
331
|
// include them in disabled state so that Vite can detect them and doesn't try to add them
|
|
333
332
|
attributes.push('disabled', 'media="(max-width: 0)"');
|
|
334
333
|
} else {
|
|
335
|
-
if (resolve_opts.preload({ type: 'css', path })) {
|
|
334
|
+
if (options.link_header_preload && resolve_opts.preload({ type: 'css', path })) {
|
|
336
335
|
link_headers.add(`<${encodeURI(path)}>; rel="preload"; as="style"; nopush`);
|
|
337
336
|
}
|
|
338
337
|
}
|
|
@@ -346,11 +345,18 @@ export async function render_response({
|
|
|
346
345
|
if (resolve_opts.preload({ type: 'font', path })) {
|
|
347
346
|
const ext = dep.slice(dep.lastIndexOf('.') + 1);
|
|
348
347
|
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
348
|
+
if (options.link_header_preload && !state.prerendering) {
|
|
349
|
+
link_headers.add(
|
|
350
|
+
`<${encodeURI(path)}>; rel="preload"; as="font"; type="font/${ext}"; crossorigin; nopush`
|
|
351
|
+
);
|
|
352
|
+
} else {
|
|
353
|
+
head.add_link_tag(path, [
|
|
354
|
+
'rel="preload"',
|
|
355
|
+
'as="font"',
|
|
356
|
+
`type="font/${ext}"`,
|
|
357
|
+
'crossorigin'
|
|
358
|
+
]);
|
|
359
|
+
}
|
|
354
360
|
}
|
|
355
361
|
}
|
|
356
362
|
|
|
@@ -377,15 +383,19 @@ export async function render_response({
|
|
|
377
383
|
(path) => resolve_opts.preload({ type: 'js', path })
|
|
378
384
|
);
|
|
379
385
|
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
link_headers.add(`<${encodeURI(path)}>; rel="modulepreload"; nopush`);
|
|
386
|
+
/** @type {(path: string) => void} */
|
|
387
|
+
let add_preload;
|
|
383
388
|
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
+
// see the kit.output.preloadStrategy option for details on why we have multiple options here
|
|
390
|
+
if (options.link_header_preload && !state.prerendering) {
|
|
391
|
+
add_preload = (path) =>
|
|
392
|
+
link_headers.add(`<${encodeURI(path)}>; rel="modulepreload"; nopush`);
|
|
393
|
+
} else {
|
|
394
|
+
add_preload = (path) => head.add_link_tag(path, ['rel="modulepreload"']);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
for (const path of included_modulepreloads) {
|
|
398
|
+
add_preload(path);
|
|
389
399
|
}
|
|
390
400
|
}
|
|
391
401
|
|
|
@@ -401,14 +411,11 @@ export async function render_response({
|
|
|
401
411
|
|
|
402
412
|
const blocks = [];
|
|
403
413
|
|
|
404
|
-
// when serving a prerendered page in an app that uses $env/
|
|
414
|
+
// when serving a prerendered page in an app that uses $app/env/public, we must
|
|
405
415
|
// import the env.js module so that it evaluates before any user code can evaluate.
|
|
406
416
|
// TODO revert to using top-level await once https://bugs.webkit.org/show_bug.cgi?id=242740 is fixed
|
|
407
417
|
// https://github.com/sveltejs/kit/pull/11601
|
|
408
|
-
const load_env_eagerly =
|
|
409
|
-
(__SVELTEKIT_EXPERIMENTAL_EXPLICIT_ENVIRONMENT_VARIABLES__ ||
|
|
410
|
-
client.uses_env_dynamic_public) &&
|
|
411
|
-
state.prerendering;
|
|
418
|
+
const load_env_eagerly = client.uses_env_dynamic_public && state.prerendering; // TODO implement uses_env_dynamic_public
|
|
412
419
|
|
|
413
420
|
const properties = [`base: ${base_expression}`];
|
|
414
421
|
|
|
@@ -416,10 +423,8 @@ export async function render_response({
|
|
|
416
423
|
properties.push(`assets: ${s(paths.assets)}`);
|
|
417
424
|
}
|
|
418
425
|
|
|
419
|
-
if (
|
|
426
|
+
if (client.uses_env_dynamic_public) {
|
|
420
427
|
properties.push(`env: ${load_env_eagerly ? 'null' : devalue.uneval(env.rendered_env)}`);
|
|
421
|
-
} else if (client.uses_env_dynamic_public) {
|
|
422
|
-
properties.push(`env: ${load_env_eagerly ? 'null' : s(public_env)}`);
|
|
423
428
|
}
|
|
424
429
|
|
|
425
430
|
if (chunks) {
|
|
@@ -673,7 +678,7 @@ export async function render_response({
|
|
|
673
678
|
headers.set('content-security-policy-report-only', report_only_header);
|
|
674
679
|
}
|
|
675
680
|
|
|
676
|
-
if (link_headers.size) {
|
|
681
|
+
if (options.link_header_preload && link_headers.size) {
|
|
677
682
|
headers.set('link', Array.from(link_headers).join(', '));
|
|
678
683
|
}
|
|
679
684
|
}
|
|
@@ -683,9 +688,7 @@ export async function render_response({
|
|
|
683
688
|
body,
|
|
684
689
|
assets,
|
|
685
690
|
nonce: /** @type {string} */ (csp.nonce),
|
|
686
|
-
env:
|
|
687
|
-
? env.explicit_public_env
|
|
688
|
-
: public_env
|
|
691
|
+
env: env.explicit_public_env
|
|
689
692
|
});
|
|
690
693
|
|
|
691
694
|
// TODO flush chunks as early as we can
|
|
@@ -742,32 +745,26 @@ export async function render_response({
|
|
|
742
745
|
|
|
743
746
|
class Head {
|
|
744
747
|
#rendered;
|
|
745
|
-
#prerendering;
|
|
746
748
|
/** @type {string[]} */
|
|
747
749
|
#http_equiv = [];
|
|
748
750
|
/** @type {string[]} */
|
|
749
751
|
#link_tags = [];
|
|
750
752
|
/** @type {string[]} */
|
|
751
|
-
#script_preloads = [];
|
|
752
|
-
/** @type {string[]} */
|
|
753
753
|
#style_tags = [];
|
|
754
754
|
/** @type {string[]} */
|
|
755
755
|
#stylesheet_links = [];
|
|
756
756
|
|
|
757
757
|
/**
|
|
758
758
|
* @param {string} rendered
|
|
759
|
-
* @param {boolean} prerendering
|
|
760
759
|
*/
|
|
761
|
-
constructor(rendered
|
|
760
|
+
constructor(rendered) {
|
|
762
761
|
this.#rendered = rendered;
|
|
763
|
-
this.#prerendering = prerendering;
|
|
764
762
|
}
|
|
765
763
|
|
|
766
764
|
build() {
|
|
767
765
|
return [
|
|
768
766
|
...this.#http_equiv,
|
|
769
767
|
...this.#link_tags,
|
|
770
|
-
...this.#script_preloads,
|
|
771
768
|
this.#rendered,
|
|
772
769
|
...this.#style_tags,
|
|
773
770
|
...this.#stylesheet_links
|
|
@@ -792,25 +789,16 @@ class Head {
|
|
|
792
789
|
this.#stylesheet_links.push(`<link href="${href}" ${attributes.join(' ')}>`);
|
|
793
790
|
}
|
|
794
791
|
|
|
795
|
-
/** @param {string} href */
|
|
796
|
-
add_script_preload(href) {
|
|
797
|
-
this.#script_preloads.push(
|
|
798
|
-
`<link rel="preload" as="script" crossorigin="anonymous" href="${href}">`
|
|
799
|
-
);
|
|
800
|
-
}
|
|
801
|
-
|
|
802
792
|
/**
|
|
803
793
|
* @param {string} href
|
|
804
794
|
* @param {string[]} attributes
|
|
805
795
|
*/
|
|
806
796
|
add_link_tag(href, attributes) {
|
|
807
|
-
if (!this.#prerendering) return;
|
|
808
797
|
this.#link_tags.push(`<link href="${href}" ${attributes.join(' ')}>`);
|
|
809
798
|
}
|
|
810
799
|
|
|
811
800
|
/** @param {string} tag */
|
|
812
801
|
add_http_equiv(tag) {
|
|
813
|
-
if (!this.#prerendering) return;
|
|
814
802
|
this.#http_equiv.push(tag);
|
|
815
803
|
}
|
|
816
804
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SerializeOptions } from 'cookie';
|
|
2
2
|
import {
|
|
3
3
|
CspDirectives,
|
|
4
4
|
ServerDataNode,
|
|
@@ -39,7 +39,9 @@ export interface CspOpts {
|
|
|
39
39
|
export interface Cookie {
|
|
40
40
|
name: string;
|
|
41
41
|
value: string;
|
|
42
|
-
options:
|
|
42
|
+
options: SerializeOptions & {
|
|
43
|
+
path: string;
|
|
44
|
+
};
|
|
43
45
|
}
|
|
44
46
|
|
|
45
47
|
export type ServerDataSerializer = {
|
|
@@ -8,7 +8,7 @@ import { is_endpoint_request, render_endpoint } from './endpoint.js';
|
|
|
8
8
|
import { render_page } from './page/index.js';
|
|
9
9
|
import { render_response } from './page/render.js';
|
|
10
10
|
import { respond_with_error } from './page/respond_with_error.js';
|
|
11
|
-
import {
|
|
11
|
+
import { is_form_content_type } from '../../utils/http.js';
|
|
12
12
|
import {
|
|
13
13
|
handle_fatal_error,
|
|
14
14
|
has_prerendered_path,
|
|
@@ -517,7 +517,7 @@ export async function internal_respond(request, options, manifest, state) {
|
|
|
517
517
|
if (value) headers.set(key, value);
|
|
518
518
|
}
|
|
519
519
|
|
|
520
|
-
for (const cookie of
|
|
520
|
+
for (const cookie of response.headers.getSetCookie()) {
|
|
521
521
|
headers.append('set-cookie', cookie);
|
|
522
522
|
}
|
|
523
523
|
|
|
@@ -9,6 +9,7 @@ import { negotiate } from '../../utils/http.js';
|
|
|
9
9
|
import { fix_stack_trace } from '../shared-server.js';
|
|
10
10
|
import { ENDPOINT_METHODS } from '../../constants.js';
|
|
11
11
|
import { escape_html } from '../../utils/escape.js';
|
|
12
|
+
import * as path from '../../utils/path.js';
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* @param {Partial<Record<import('types').HttpMethod, any>>} mod
|
|
@@ -212,10 +213,7 @@ let relative = (file) => file;
|
|
|
212
213
|
|
|
213
214
|
if (DEV) {
|
|
214
215
|
try {
|
|
215
|
-
|
|
216
|
-
const process = await import('node:process');
|
|
217
|
-
|
|
218
|
-
relative = (file) => path.relative(process.cwd(), file);
|
|
216
|
+
relative = (file) => path.relative(__SVELTEKIT_ROOT__, file);
|
|
219
217
|
} catch {
|
|
220
218
|
// do nothing
|
|
221
219
|
}
|
|
@@ -1,28 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `$env/dynamic/private`
|
|
3
|
-
* @type {Record<string, string>}
|
|
4
|
-
*/
|
|
5
|
-
export let private_env = {};
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* `$env/dynamic/public`
|
|
9
|
-
* @type {Record<string, string>}
|
|
10
|
-
*/
|
|
11
|
-
export let public_env = {};
|
|
12
|
-
|
|
13
1
|
/** @param {any} error */
|
|
14
2
|
export let fix_stack_trace = (error) => error?.stack;
|
|
15
3
|
|
|
16
|
-
/** @type {(environment: Record<string, string>) => void} */
|
|
17
|
-
export function set_private_env(environment) {
|
|
18
|
-
private_env = environment;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/** @type {(environment: Record<string, string>) => void} */
|
|
22
|
-
export function set_public_env(environment) {
|
|
23
|
-
public_env = environment;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
4
|
/** @param {(error: Error) => string} value */
|
|
27
5
|
export function set_fix_stack_trace(value) {
|
|
28
6
|
fix_stack_trace = value;
|
package/src/runtime/shared.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/** @import { Transport } from '@sveltejs/kit' */
|
|
2
2
|
import * as devalue from 'devalue';
|
|
3
3
|
import { base64_decode, base64_encode, text_encoder } from './utils.js';
|
|
4
|
-
import * as svelte from 'svelte';
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* @param {string} route_id
|
|
@@ -305,17 +304,3 @@ export function split_remote_key(key) {
|
|
|
305
304
|
payload: key.slice(i + 1)
|
|
306
305
|
};
|
|
307
306
|
}
|
|
308
|
-
|
|
309
|
-
/**
|
|
310
|
-
* @template T
|
|
311
|
-
* @param {string} key
|
|
312
|
-
* @param {() => T} fn
|
|
313
|
-
* @returns {T}
|
|
314
|
-
* @deprecated TODO remove in SvelteKit 3.0
|
|
315
|
-
*/
|
|
316
|
-
export function unfriendly_hydratable(key, fn) {
|
|
317
|
-
if (!svelte.hydratable) {
|
|
318
|
-
throw new Error('Remote functions require Svelte 5.44.0 or later');
|
|
319
|
-
}
|
|
320
|
-
return svelte.hydratable(key, fn);
|
|
321
|
-
}
|
|
@@ -48,6 +48,11 @@ declare global {
|
|
|
48
48
|
/** Resolve a placeholder promise */
|
|
49
49
|
resolve?: (data: { id: number; data: any; error: any }) => void;
|
|
50
50
|
};
|
|
51
|
+
/**
|
|
52
|
+
* The Vite `root` setting used to construct paths to nodes and components
|
|
53
|
+
* for the SSR manifest during development
|
|
54
|
+
*/
|
|
55
|
+
const __SVELTEKIT_ROOT__: string;
|
|
51
56
|
/**
|
|
52
57
|
* This makes the use of specific features visible at both dev and build time, in such a
|
|
53
58
|
* way that we can error when they are not supported by the target platform.
|
|
@@ -64,7 +69,6 @@ declare global {
|
|
|
64
69
|
*/
|
|
65
70
|
var __SVELTEKIT_TRACK__: (label: string) => void;
|
|
66
71
|
var __SVELTEKIT_EXPERIMENTAL_USE_TRANSFORM_ERROR__: boolean;
|
|
67
|
-
var __SVELTEKIT_EXPERIMENTAL_EXPLICIT_ENVIRONMENT_VARIABLES__: boolean;
|
|
68
72
|
var Bun: object;
|
|
69
73
|
var Deno: object;
|
|
70
74
|
}
|
package/src/types/internal.d.ts
CHANGED
|
@@ -47,8 +47,6 @@ export interface ServerInternalModule {
|
|
|
47
47
|
set_env(environment: Record<string, string>): void;
|
|
48
48
|
set_manifest(manifest: SSRManifest): void;
|
|
49
49
|
set_prerendering(): void;
|
|
50
|
-
set_private_env(environment: Record<string, string>): void;
|
|
51
|
-
set_public_env(environment: Record<string, string>): void;
|
|
52
50
|
set_read_implementation(implementation: (path: string) => ReadableStream): void;
|
|
53
51
|
set_version(version: string): void;
|
|
54
52
|
set_fix_stack_trace(fix_stack_trace: (error: unknown) => string): void;
|
|
@@ -501,11 +499,9 @@ export interface SSROptions {
|
|
|
501
499
|
csrf_check_origin: boolean;
|
|
502
500
|
csrf_trusted_origins: string[];
|
|
503
501
|
embedded: boolean;
|
|
504
|
-
env_public_prefix: string;
|
|
505
|
-
env_private_prefix: string;
|
|
506
502
|
hash_routing: boolean;
|
|
507
503
|
hooks: ServerHooks;
|
|
508
|
-
|
|
504
|
+
link_header_preload: ValidatedConfig['kit']['output']['linkHeaderPreload'];
|
|
509
505
|
root: SSRComponent['default'];
|
|
510
506
|
service_worker: boolean;
|
|
511
507
|
service_worker_options: RegistrationOptions;
|
|
@@ -607,9 +603,8 @@ export type ValidatedConfig = Config & {
|
|
|
607
603
|
extensions: string[];
|
|
608
604
|
};
|
|
609
605
|
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
};
|
|
606
|
+
// TODO: remove the omit in 4.0
|
|
607
|
+
export type ValidatedKitConfig = Omit<RecursiveRequired<KitConfig>, 'adapter'>;
|
|
613
608
|
|
|
614
609
|
export type BinaryFormMeta = {
|
|
615
610
|
remote_refreshes?: string[];
|