@sveltejs/kit 3.0.0-next.0 → 3.0.0-next.10
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 +33 -21
- package/src/core/adapt/builder.js +29 -43
- package/src/core/adapt/index.js +1 -4
- package/src/core/config/index.js +132 -71
- package/src/core/config/options.js +294 -244
- package/src/core/config/types.d.ts +1 -1
- package/src/core/env.js +121 -5
- package/src/core/generate_manifest/index.js +12 -15
- package/src/core/postbuild/analyse.js +7 -19
- package/src/core/postbuild/crawl.js +22 -6
- package/src/core/postbuild/prerender.js +42 -23
- package/src/core/sync/create_manifest_data/index.js +53 -50
- package/src/core/sync/sync.js +0 -2
- package/src/core/sync/write_client_manifest.js +8 -15
- package/src/core/sync/write_env.js +2 -1
- package/src/core/sync/write_non_ambient.js +12 -9
- package/src/core/sync/write_server.js +13 -14
- package/src/core/sync/write_tsconfig.js +16 -8
- package/src/core/sync/write_tsconfig_test/package.json +7 -0
- package/src/core/sync/write_types/index.js +28 -24
- package/src/core/utils.js +2 -2
- package/src/exports/env/index.js +12 -0
- package/src/exports/hooks/index.js +3 -9
- package/src/exports/hooks/sequence.js +3 -2
- package/src/exports/index.js +35 -13
- package/src/exports/internal/client.js +5 -0
- package/src/exports/internal/env.js +2 -2
- package/src/exports/internal/index.js +1 -90
- package/src/exports/internal/{event.js → server/event.js} +1 -2
- package/src/exports/internal/server/index.js +33 -0
- package/src/exports/internal/shared.js +89 -0
- package/src/exports/node/index.js +62 -15
- package/src/exports/params.js +63 -0
- package/src/exports/public.d.ts +323 -170
- package/src/exports/url.js +86 -0
- package/src/exports/vite/build/build_server.js +53 -59
- package/src/exports/vite/build/remote.js +18 -11
- package/src/exports/vite/build/utils.js +0 -8
- package/src/exports/vite/dev/index.js +42 -44
- package/src/exports/vite/index.js +810 -593
- package/src/exports/vite/preview/index.js +29 -22
- package/src/exports/vite/static_analysis/index.js +2 -4
- package/src/exports/vite/static_analysis/types.d.ts +14 -0
- package/src/exports/vite/utils.js +21 -36
- 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 +6 -0
- package/src/runtime/app/forms.js +24 -7
- package/src/runtime/app/paths/client.js +4 -10
- package/src/runtime/app/paths/internal/client.js +4 -2
- package/src/runtime/app/paths/internal/server.js +2 -23
- package/src/runtime/app/paths/public.d.ts +0 -28
- package/src/runtime/app/paths/server.js +9 -5
- package/src/runtime/app/server/remote/command.js +0 -3
- package/src/runtime/app/server/remote/form.js +27 -15
- package/src/runtime/app/server/remote/prerender.js +29 -36
- package/src/runtime/app/server/remote/query.js +101 -99
- package/src/runtime/app/server/remote/requested.js +22 -14
- package/src/runtime/app/server/remote/shared.js +30 -26
- package/src/runtime/app/state/client.js +1 -2
- package/src/runtime/app/stores.js +13 -76
- package/src/runtime/client/bundle.js +1 -1
- package/src/runtime/client/client-entry.js +3 -0
- package/src/runtime/client/client.js +411 -318
- package/src/runtime/client/entry.js +24 -3
- package/src/runtime/client/fetcher.js +3 -2
- package/src/runtime/client/ndjson.js +6 -33
- 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 +7 -32
- package/src/runtime/client/remote-functions/form.svelte.js +183 -112
- package/src/runtime/client/remote-functions/prerender.svelte.js +29 -8
- package/src/runtime/client/remote-functions/query/index.js +7 -14
- package/src/runtime/client/remote-functions/query/instance.svelte.js +63 -18
- package/src/runtime/client/remote-functions/query/proxy.js +3 -3
- package/src/runtime/client/remote-functions/query-batch.svelte.js +60 -68
- package/src/runtime/client/remote-functions/query-live/instance.svelte.js +60 -18
- package/src/runtime/client/remote-functions/query-live/iterator.js +36 -55
- package/src/runtime/client/remote-functions/shared.svelte.js +88 -62
- package/src/runtime/client/sse.js +32 -0
- package/src/runtime/client/state.svelte.js +65 -49
- package/src/runtime/client/stream.js +38 -0
- package/src/runtime/client/types.d.ts +11 -7
- package/src/runtime/client/utils.js +0 -96
- package/src/runtime/components/root.svelte +66 -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 +100 -22
- package/src/runtime/server/cookie.js +69 -52
- package/src/runtime/server/csrf.js +65 -0
- package/src/runtime/server/data/index.js +14 -18
- package/src/runtime/server/env_module.js +0 -5
- package/src/runtime/server/index.js +2 -2
- package/src/runtime/server/page/actions.js +41 -26
- package/src/runtime/server/page/index.js +9 -15
- package/src/runtime/server/page/load_data.js +1 -1
- package/src/runtime/server/page/render.js +112 -187
- package/src/runtime/server/page/respond_with_error.js +7 -8
- package/src/runtime/server/page/server_routing.js +27 -18
- package/src/runtime/server/remote.js +355 -216
- package/src/runtime/server/respond.js +97 -61
- package/src/runtime/server/utils.js +32 -9
- package/src/runtime/shared.js +83 -13
- package/src/runtime/telemetry/otel.js +1 -1
- package/src/runtime/types.d.ts +8 -0
- package/src/types/ambient.d.ts +10 -5
- package/src/types/global-private.d.ts +15 -22
- package/src/types/internal.d.ts +89 -74
- package/src/types/private.d.ts +33 -1
- package/src/utils/error.js +24 -4
- package/src/utils/import.js +6 -1
- package/src/utils/imports.js +83 -0
- package/src/utils/mime.js +9 -0
- package/src/utils/params.js +66 -0
- package/src/utils/routing.js +90 -44
- package/src/utils/shared-iterator.js +5 -0
- package/src/utils/streaming.js +14 -4
- package/src/utils/url.js +20 -2
- package/src/version.js +1 -1
- package/types/index.d.ts +467 -537
- package/types/index.d.ts.map +22 -39
- package/src/core/sync/write_root.js +0 -148
- package/src/exports/internal/server.js +0 -22
- package/src/types/synthetic/$lib.md +0 -5
- /package/src/exports/internal/{remote-functions.js → server/remote-functions.js} +0 -0
|
@@ -1,24 +1,22 @@
|
|
|
1
|
+
/** @import { NextHandleFunction } from 'connect' */
|
|
2
|
+
/** @import { PreviewServer, ResolvedConfig } from 'vite' */
|
|
3
|
+
/** @import { ValidatedConfig, ServerInternalModule, ServerModule } from 'types' */
|
|
1
4
|
import fs from 'node:fs';
|
|
2
5
|
import { join } from 'node:path';
|
|
3
6
|
import { pathToFileURL } from 'node:url';
|
|
4
|
-
import { lookup } from '
|
|
7
|
+
import { lookup } from '../../../utils/mime.js';
|
|
5
8
|
import sirv from 'sirv';
|
|
6
9
|
import { loadEnv, normalizePath } from 'vite';
|
|
7
10
|
import { createReadableStream, getRequest, setResponse } from '../../../exports/node/index.js';
|
|
8
11
|
import { SVELTE_KIT_ASSETS } from '../../../constants.js';
|
|
9
12
|
import { is_chrome_devtools_request, not_found } from '../utils.js';
|
|
10
13
|
|
|
11
|
-
/** @typedef {import('http').IncomingMessage} Req */
|
|
12
|
-
/** @typedef {import('http').ServerResponse} Res */
|
|
13
|
-
/** @typedef {(req: Req, res: Res, next: () => void) => void} Handler */
|
|
14
|
-
|
|
15
14
|
/**
|
|
16
|
-
* @param {
|
|
17
|
-
* @param {
|
|
18
|
-
* @param {
|
|
19
|
-
* @param {import('@sveltejs/kit').Adapter | undefined} adapter
|
|
15
|
+
* @param {PreviewServer} vite
|
|
16
|
+
* @param {ResolvedConfig} vite_config
|
|
17
|
+
* @param {ValidatedConfig} svelte_config
|
|
20
18
|
*/
|
|
21
|
-
export async function preview(vite, vite_config, svelte_config
|
|
19
|
+
export async function preview(vite, vite_config, svelte_config) {
|
|
22
20
|
const { paths } = svelte_config.kit;
|
|
23
21
|
const base = paths.base;
|
|
24
22
|
const assets = paths.assets ? SVELTE_KIT_ASSETS : paths.base;
|
|
@@ -38,10 +36,10 @@ export async function preview(vite, vite_config, svelte_config, adapter) {
|
|
|
38
36
|
await import(pathToFileURL(instrumentation).href);
|
|
39
37
|
}
|
|
40
38
|
|
|
41
|
-
/** @type {
|
|
39
|
+
/** @type {ServerInternalModule} */
|
|
42
40
|
const { set_assets } = await import(pathToFileURL(join(dir, 'internal.js')).href);
|
|
43
41
|
|
|
44
|
-
/** @type {
|
|
42
|
+
/** @type {ServerModule} */
|
|
45
43
|
const { Server } = await import(pathToFileURL(join(dir, 'index.js')).href);
|
|
46
44
|
|
|
47
45
|
const { manifest } = await import(pathToFileURL(join(dir, 'manifest.js')).href);
|
|
@@ -49,12 +47,21 @@ export async function preview(vite, vite_config, svelte_config, adapter) {
|
|
|
49
47
|
set_assets(assets);
|
|
50
48
|
|
|
51
49
|
const server = new Server(manifest);
|
|
52
|
-
await server.init({
|
|
53
|
-
env: loadEnv(vite_config.mode, svelte_config.kit.env.dir, ''),
|
|
54
|
-
read: (file) => createReadableStream(`${dir}/${file}`)
|
|
55
|
-
});
|
|
56
50
|
|
|
57
|
-
|
|
51
|
+
try {
|
|
52
|
+
await server.init({
|
|
53
|
+
env: loadEnv(vite_config.mode, svelte_config.kit.env.dir, ''),
|
|
54
|
+
read: (file) => createReadableStream(`${dir}/${file}`)
|
|
55
|
+
});
|
|
56
|
+
} catch (error) {
|
|
57
|
+
// Vite erases the error message when starting the preview server so we store
|
|
58
|
+
// it in the stack instead. This ensures errors thrown using `stackless`
|
|
59
|
+
// are still readable
|
|
60
|
+
if (error instanceof Error) error.stack = error.message;
|
|
61
|
+
throw error;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const emulator = await svelte_config.kit.adapter?.emulate?.();
|
|
58
65
|
|
|
59
66
|
return () => {
|
|
60
67
|
// Remove the base middleware. It screws with the URL.
|
|
@@ -196,12 +203,12 @@ export async function preview(vite, vite_config, svelte_config, adapter) {
|
|
|
196
203
|
vite.middlewares.use(async (req, res) => {
|
|
197
204
|
const host = req.headers[':authority'] || req.headers.host;
|
|
198
205
|
|
|
199
|
-
const request =
|
|
206
|
+
const request = getRequest({
|
|
200
207
|
base: `${protocol}://${host}`,
|
|
201
208
|
request: req
|
|
202
209
|
});
|
|
203
210
|
|
|
204
|
-
|
|
211
|
+
setResponse(
|
|
205
212
|
res,
|
|
206
213
|
await server.respond(request, {
|
|
207
214
|
getClientAddress: () => {
|
|
@@ -225,7 +232,7 @@ export async function preview(vite, vite_config, svelte_config, adapter) {
|
|
|
225
232
|
|
|
226
233
|
/**
|
|
227
234
|
* @param {string} dir
|
|
228
|
-
* @returns {
|
|
235
|
+
* @returns {NextHandleFunction}
|
|
229
236
|
*/
|
|
230
237
|
const mutable = (dir) =>
|
|
231
238
|
fs.existsSync(dir)
|
|
@@ -237,8 +244,8 @@ const mutable = (dir) =>
|
|
|
237
244
|
|
|
238
245
|
/**
|
|
239
246
|
* @param {string} scope
|
|
240
|
-
* @param {
|
|
241
|
-
* @returns {
|
|
247
|
+
* @param {NextHandleFunction} handler
|
|
248
|
+
* @returns {NextHandleFunction}
|
|
242
249
|
*/
|
|
243
250
|
function scoped(scope, handler) {
|
|
244
251
|
if (scope === '') return handler;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
/** @import { PageOptions } from './types.js' */
|
|
1
2
|
import path from 'node:path';
|
|
2
3
|
import { tsPlugin } from '@sveltejs/acorn-typescript';
|
|
3
4
|
import { Parser } from 'acorn';
|
|
4
5
|
import { read } from '../../../utils/filesystem.js';
|
|
5
6
|
|
|
6
|
-
const valid_page_options_array = /** @type {const} */ ([
|
|
7
|
+
export const valid_page_options_array = /** @type {const} */ ([
|
|
7
8
|
'ssr',
|
|
8
9
|
'prerender',
|
|
9
10
|
'csr',
|
|
@@ -16,9 +17,6 @@ const valid_page_options_array = /** @type {const} */ ([
|
|
|
16
17
|
/** @type {Set<string>} */
|
|
17
18
|
const valid_page_options = new Set(valid_page_options_array);
|
|
18
19
|
|
|
19
|
-
/** @typedef {typeof valid_page_options_array[number]} ValidPageOption */
|
|
20
|
-
/** @typedef {Partial<Record<ValidPageOption, any>>} PageOptions */
|
|
21
|
-
|
|
22
20
|
const skip_parsing_regex = new RegExp(
|
|
23
21
|
`${Array.from(valid_page_options).join('|')}|(?:export[\\s\\n]+\\*[\\s\\n]+from)`
|
|
24
22
|
);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { PrerenderOption, TrailingSlash } from 'types';
|
|
2
|
+
import type { valid_page_options_array } from './index.js';
|
|
3
|
+
|
|
4
|
+
type ValidPageOption = (typeof valid_page_options_array)[number];
|
|
5
|
+
|
|
6
|
+
export type PageOptions = Partial<{
|
|
7
|
+
[K in ValidPageOption]: K extends 'ssr' | 'csr'
|
|
8
|
+
? boolean
|
|
9
|
+
: K extends 'prerender'
|
|
10
|
+
? PrerenderOption
|
|
11
|
+
: K extends 'trailingSlash'
|
|
12
|
+
? TrailingSlash
|
|
13
|
+
: any;
|
|
14
|
+
}>;
|
|
@@ -2,6 +2,7 @@ import path from 'node:path';
|
|
|
2
2
|
import { posixify } from '../../utils/os.js';
|
|
3
3
|
import { negotiate } from '../../utils/http.js';
|
|
4
4
|
import { escape_html } from '../../utils/escape.js';
|
|
5
|
+
import { stackless } from '../../utils/error.js';
|
|
5
6
|
import { dedent } from '../../core/sync/utils.js';
|
|
6
7
|
import {
|
|
7
8
|
app_server,
|
|
@@ -11,20 +12,16 @@ import {
|
|
|
11
12
|
} from './module_ids.js';
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
|
-
* Transforms
|
|
15
|
+
* Transforms alias to a valid vite.resolve.alias array.
|
|
15
16
|
*
|
|
16
17
|
* Related to tsconfig path alias creation.
|
|
17
18
|
*
|
|
18
19
|
* @param {import('types').ValidatedKitConfig} config
|
|
19
20
|
* @param {string} root
|
|
20
|
-
|
|
21
|
+
*/
|
|
21
22
|
export function get_config_aliases(config, root) {
|
|
22
23
|
/** @type {import('vite').Alias[]} */
|
|
23
|
-
const alias = [
|
|
24
|
-
// For now, we handle `$lib` specially here rather than make it a default value for
|
|
25
|
-
// `config.kit.alias` since it has special meaning for packaging, etc.
|
|
26
|
-
{ find: '$lib', replacement: config.files.lib }
|
|
27
|
-
];
|
|
24
|
+
const alias = [];
|
|
28
25
|
|
|
29
26
|
for (let [key, value] of Object.entries(config.alias)) {
|
|
30
27
|
value = posixify(value);
|
|
@@ -35,16 +32,16 @@ export function get_config_aliases(config, root) {
|
|
|
35
32
|
// Doing just `{ find: key.slice(0, -2) ,..}` would mean `import .. from "key"` would also be matched, which we don't want
|
|
36
33
|
alias.push({
|
|
37
34
|
find: new RegExp(`^${escape_for_regexp(key.slice(0, -2))}\\/(.+)$`),
|
|
38
|
-
replacement: `${path.resolve(root, value)}/$1`
|
|
35
|
+
replacement: `${posixify(path.resolve(root, value))}/$1`
|
|
39
36
|
});
|
|
40
37
|
} else if (key + '/*' in config.alias) {
|
|
41
38
|
// key and key/* both exist -> the replacement for key needs to happen _only_ on import .. from "key"
|
|
42
39
|
alias.push({
|
|
43
40
|
find: new RegExp(`^${escape_for_regexp(key)}$`),
|
|
44
|
-
replacement: path.resolve(root, value)
|
|
41
|
+
replacement: posixify(path.resolve(root, value))
|
|
45
42
|
});
|
|
46
43
|
} else {
|
|
47
|
-
alias.push({ find: key, replacement: path.resolve(root, value) });
|
|
44
|
+
alias.push({ find: key, replacement: posixify(path.resolve(root, value)) });
|
|
48
45
|
}
|
|
49
46
|
}
|
|
50
47
|
|
|
@@ -117,16 +114,20 @@ export function not_found(req, res, base) {
|
|
|
117
114
|
const query_pattern = /\?.*$/s;
|
|
118
115
|
|
|
119
116
|
/**
|
|
120
|
-
* Removes cwd
|
|
117
|
+
* Removes cwd path from the start of the id and replaces any `#`-prefixed
|
|
118
|
+
* import alias target paths with their alias names.
|
|
121
119
|
* @param {string} id
|
|
122
|
-
* @param {string}
|
|
120
|
+
* @param {Array<{ alias: string, path: string }>} aliases — sorted by path length descending
|
|
123
121
|
* @param {string} cwd
|
|
124
122
|
*/
|
|
125
|
-
export function normalize_id(id,
|
|
123
|
+
export function normalize_id(id, aliases, cwd) {
|
|
126
124
|
id = id.replace(query_pattern, '');
|
|
127
125
|
|
|
128
|
-
|
|
129
|
-
id
|
|
126
|
+
for (const { alias, path } of aliases) {
|
|
127
|
+
if (id === path || id.startsWith(path + '/')) {
|
|
128
|
+
id = id.replace(path, alias);
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
130
131
|
}
|
|
131
132
|
|
|
132
133
|
if (id.startsWith(cwd)) {
|
|
@@ -148,34 +149,18 @@ export function normalize_id(id, lib, cwd) {
|
|
|
148
149
|
return posixify(id);
|
|
149
150
|
}
|
|
150
151
|
|
|
151
|
-
/**
|
|
152
|
-
* For times when you need to throw an error, but without
|
|
153
|
-
* displaying a useless stack trace (since the developer
|
|
154
|
-
* can't do anything useful with it)
|
|
155
|
-
* @param {string} message
|
|
156
|
-
*/
|
|
157
|
-
export function stackless(message) {
|
|
158
|
-
const error = new Error(message);
|
|
159
|
-
error.stack = '';
|
|
160
|
-
return error;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
152
|
export const strip_virtual_prefix = /** @param {string} id */ (id) => id.replace('\0virtual:', '');
|
|
164
153
|
|
|
165
154
|
/**
|
|
166
|
-
* For `error_for_missing_config('
|
|
155
|
+
* For `error_for_missing_config('remote functions', 'experimental.remoteFunctions', 'true')`,
|
|
167
156
|
* returns:
|
|
168
157
|
*
|
|
169
158
|
* ```
|
|
170
|
-
* To enable
|
|
159
|
+
* To enable remote functions, add the following to the SvelteKit plugin in your `vite.config.js`:
|
|
171
160
|
*
|
|
172
161
|
*\`\`\`js
|
|
173
|
-
*
|
|
174
|
-
*
|
|
175
|
-
* instrumentation:
|
|
176
|
-
* server: true
|
|
177
|
-
* }
|
|
178
|
-
* }
|
|
162
|
+
* experimental: {
|
|
163
|
+
* remoteFunctions: true
|
|
179
164
|
* }
|
|
180
165
|
*\`\`\`
|
|
181
166
|
*```
|
|
@@ -196,7 +181,7 @@ export function error_for_missing_config(feature_name, path, value) {
|
|
|
196
181
|
|
|
197
182
|
throw stackless(
|
|
198
183
|
dedent`\
|
|
199
|
-
To enable ${feature_name}, add the following to your \`
|
|
184
|
+
To enable ${feature_name}, add the following to your SvelteKit plugin in \`vite.config.js\`:
|
|
200
185
|
|
|
201
186
|
${result}
|
|
202
187
|
`
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import { BROWSER } from 'esm-env';
|
|
2
|
+
import { payload } from '../../client/payload.js';
|
|
3
|
+
|
|
4
|
+
export const version = BROWSER ? payload.version : __SVELTEKIT_APP_VERSION__;
|
|
2
5
|
export let building = false;
|
|
3
6
|
export let prerendering = false;
|
|
4
7
|
|
|
@@ -9,6 +12,3 @@ export function set_building() {
|
|
|
9
12
|
export function set_prerendering() {
|
|
10
13
|
prerendering = true;
|
|
11
14
|
}
|
|
12
|
-
|
|
13
|
-
// force /@vite/client to be injected
|
|
14
|
-
import.meta.hot;
|
package/src/runtime/app/forms.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as devalue from 'devalue';
|
|
2
2
|
import { BROWSER, DEV } from 'esm-env';
|
|
3
3
|
import { noop } from '../../utils/functions.js';
|
|
4
|
-
import {
|
|
5
|
-
import { app as client_app, applyAction } from '../client/client.js';
|
|
4
|
+
import { refreshAll } from './navigation.js';
|
|
5
|
+
import { app as client_app, applyAction, handle_error } from '../client/client.js';
|
|
6
6
|
import { app as server_app } from '../server/app.js';
|
|
7
7
|
|
|
8
8
|
export { applyAction };
|
|
@@ -30,11 +30,15 @@ export { applyAction };
|
|
|
30
30
|
* @returns {import('@sveltejs/kit').ActionResult<Success, Failure>}
|
|
31
31
|
*/
|
|
32
32
|
export function deserialize(result) {
|
|
33
|
+
if (result === '') {
|
|
34
|
+
return { type: 'success', status: 204, data: undefined };
|
|
35
|
+
}
|
|
36
|
+
|
|
33
37
|
const parsed = JSON.parse(result);
|
|
34
38
|
|
|
35
39
|
if (parsed.data) {
|
|
36
40
|
// the decoders should never be initialised at the top-level because `app`
|
|
37
|
-
// will not be initialised yet if `
|
|
41
|
+
// will not be initialised yet if `output.bundleStrategy` is 'single' or 'inline'
|
|
38
42
|
parsed.data = devalue.parse(parsed.data, BROWSER ? client_app.decoders : server_app.decoders);
|
|
39
43
|
}
|
|
40
44
|
|
|
@@ -102,7 +106,7 @@ export function enhance(form_element, submit = noop) {
|
|
|
102
106
|
HTMLFormElement.prototype.reset.call(form_element);
|
|
103
107
|
}
|
|
104
108
|
if (shouldInvalidateAll) {
|
|
105
|
-
await
|
|
109
|
+
await refreshAll();
|
|
106
110
|
}
|
|
107
111
|
}
|
|
108
112
|
|
|
@@ -197,11 +201,24 @@ export function enhance(form_element, submit = noop) {
|
|
|
197
201
|
signal: controller.signal
|
|
198
202
|
});
|
|
199
203
|
|
|
200
|
-
|
|
201
|
-
|
|
204
|
+
if (response.status === 204) {
|
|
205
|
+
result = { type: 'success', status: 204 };
|
|
206
|
+
} else {
|
|
207
|
+
result = deserialize(await response.text());
|
|
208
|
+
if (result.type === 'error' || result.type === 'failure') {
|
|
209
|
+
result.status = response.status;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
202
212
|
} catch (error) {
|
|
203
213
|
if (/** @type {any} */ (error)?.name === 'AbortError') return;
|
|
204
|
-
result = {
|
|
214
|
+
result = {
|
|
215
|
+
type: 'error',
|
|
216
|
+
error: await handle_error(error, {
|
|
217
|
+
params: {},
|
|
218
|
+
route: { id: null },
|
|
219
|
+
url: new URL(location.href)
|
|
220
|
+
})
|
|
221
|
+
};
|
|
205
222
|
}
|
|
206
223
|
|
|
207
224
|
await callback({
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
/** @import { Asset, RouteId, RouteIdWithSearchOrHash, Pathname, PathnameWithSearchOrHash, ResolvedPathname } from '$app/types' */
|
|
1
|
+
/** @import { Asset, RouteId, RouteIdWithSearchOrHash, Pathname, PathnameWithSearchOrHash, ResolvedPathname, RouteParams } from '$app/types' */
|
|
2
2
|
/** @import { ResolveArgs } from './types.js' */
|
|
3
3
|
import { base, assets, hash_routing } from './internal/client.js';
|
|
4
4
|
import { resolve_route } from '../../../utils/routing.js';
|
|
5
5
|
import { get_navigation_intent } from '../../client/client.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* Resolve the URL of an asset in your `static` directory, by prefixing it with [`config.
|
|
8
|
+
* Resolve the URL of an asset in your `static` directory, by prefixing it with [`config.paths.assets`](https://svelte.dev/docs/kit/configuration#paths) if configured, or otherwise by prefixing it with the base path.
|
|
9
9
|
*
|
|
10
10
|
* During server rendering, the base path is relative and depends on the page currently being rendered.
|
|
11
11
|
*
|
|
@@ -59,11 +59,7 @@ export function resolve(...args) {
|
|
|
59
59
|
);
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
|
|
63
|
-
// but we don't want to adjust the internal resolve_route function to accept `undefined`, hence the type cast.
|
|
64
|
-
return (
|
|
65
|
-
base + pathname_prefix + resolve_route(args[0], /** @type {Record<string, string>} */ (args[1]))
|
|
66
|
-
);
|
|
62
|
+
return base + pathname_prefix + resolve_route(args[0], args[1] ?? {});
|
|
67
63
|
}
|
|
68
64
|
|
|
69
65
|
/**
|
|
@@ -84,7 +80,7 @@ export function resolve(...args) {
|
|
|
84
80
|
* @since 2.52.0
|
|
85
81
|
*
|
|
86
82
|
* @param {Pathname | URL | (string & {})} url
|
|
87
|
-
* @returns {Promise<{ id:
|
|
83
|
+
* @returns {Promise<{ [K in RouteId]: { id: K; params: RouteParams<K>; } }[RouteId] | null>}
|
|
88
84
|
*/
|
|
89
85
|
export async function match(url) {
|
|
90
86
|
if (typeof url === 'string') {
|
|
@@ -102,5 +98,3 @@ export async function match(url) {
|
|
|
102
98
|
|
|
103
99
|
return null;
|
|
104
100
|
}
|
|
105
|
-
|
|
106
|
-
export { base, assets, resolve as resolveRoute };
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { payload } from '../../../client/payload.js';
|
|
2
|
+
|
|
3
|
+
export const base = payload.base ?? __SVELTEKIT_PATHS_BASE__;
|
|
4
|
+
export const assets = payload.assets ?? base ?? __SVELTEKIT_PATHS_ASSETS__;
|
|
3
5
|
export const app_dir = __SVELTEKIT_APP_DIR__;
|
|
4
6
|
export const hash_routing = __SVELTEKIT_HASH_ROUTING__;
|
|
@@ -1,30 +1,9 @@
|
|
|
1
|
-
export
|
|
1
|
+
export const base = __SVELTEKIT_PATHS_BASE__;
|
|
2
2
|
export let assets = __SVELTEKIT_PATHS_ASSETS__ || base;
|
|
3
3
|
export const app_dir = __SVELTEKIT_APP_DIR__;
|
|
4
4
|
export const relative = __SVELTEKIT_PATHS_RELATIVE__;
|
|
5
5
|
|
|
6
|
-
const initial = { base, assets };
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* `base` could be overridden during rendering to be relative;
|
|
10
|
-
* this one's the original non-relative base path
|
|
11
|
-
*/
|
|
12
|
-
export const initial_base = initial.base;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @param {{ base: string, assets: string }} paths
|
|
16
|
-
*/
|
|
17
|
-
export function override(paths) {
|
|
18
|
-
base = paths.base;
|
|
19
|
-
assets = paths.assets;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function reset() {
|
|
23
|
-
base = initial.base;
|
|
24
|
-
assets = initial.assets;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
6
|
/** @param {string} path */
|
|
28
7
|
export function set_assets(path) {
|
|
29
|
-
assets =
|
|
8
|
+
assets = path;
|
|
30
9
|
}
|
|
@@ -1,29 +1 @@
|
|
|
1
|
-
import { RouteIdWithSearchOrHash, PathnameWithSearchOrHash, ResolvedPathname } from '$app/types';
|
|
2
|
-
import { ResolveArgs } from './types.js';
|
|
3
|
-
|
|
4
1
|
export { resolve, asset, match } from './client.js';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* A string that matches [`config.kit.paths.base`](https://svelte.dev/docs/kit/configuration#paths).
|
|
8
|
-
*
|
|
9
|
-
* Example usage: `<a href="{base}/your-page">Link</a>`
|
|
10
|
-
*
|
|
11
|
-
* @deprecated Use [`resolve(...)`](https://svelte.dev/docs/kit/$app-paths#resolve) instead
|
|
12
|
-
*/
|
|
13
|
-
export let base: '' | `/${string}`;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* An absolute path that matches [`config.kit.paths.assets`](https://svelte.dev/docs/kit/configuration#paths).
|
|
17
|
-
*
|
|
18
|
-
* > [!NOTE] If a value for `config.kit.paths.assets` is specified, it will be replaced with `'/_svelte_kit_assets'` during `vite dev` or `vite preview`, since the assets don't yet live at their eventual URL.
|
|
19
|
-
*
|
|
20
|
-
* @deprecated Use [`asset(...)`](https://svelte.dev/docs/kit/$app-paths#asset) instead
|
|
21
|
-
*/
|
|
22
|
-
export let assets: '' | `https://${string}` | `http://${string}` | '/_svelte_kit_assets';
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* @deprecated Use [`resolve(...)`](https://svelte.dev/docs/kit/$app-paths#resolve) instead
|
|
26
|
-
*/
|
|
27
|
-
export function resolveRoute<T extends RouteIdWithSearchOrHash | PathnameWithSearchOrHash>(
|
|
28
|
-
...args: ResolveArgs<T>
|
|
29
|
-
): ResolvedPathname;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { base, assets, relative
|
|
1
|
+
import { base, assets, relative } from './internal/server.js';
|
|
2
2
|
import { resolve_route, find_route } from '../../../utils/routing.js';
|
|
3
3
|
import { decode_pathname } from '../../../utils/url.js';
|
|
4
|
+
import { add_data_suffix } from '../../pathname.js';
|
|
4
5
|
import { try_get_request_store } from '@sveltejs/kit/internal/server';
|
|
5
6
|
import { manifest } from '__sveltekit/server';
|
|
6
7
|
import { get_hooks } from '__SERVER__/internal.js';
|
|
@@ -20,13 +21,18 @@ export function resolve(id, params) {
|
|
|
20
21
|
);
|
|
21
22
|
}
|
|
22
23
|
|
|
23
|
-
const resolved = resolve_route(id,
|
|
24
|
+
const resolved = resolve_route(id, params ?? {});
|
|
24
25
|
|
|
25
26
|
if (relative) {
|
|
26
27
|
const store = try_get_request_store();
|
|
27
28
|
|
|
28
29
|
if (store && !store.state.prerendering?.fallback) {
|
|
29
|
-
|
|
30
|
+
// the relative path depth must reflect the URL the browser is actually at, which
|
|
31
|
+
// for a data request includes the `__data.json` suffix that was stripped during routing
|
|
32
|
+
const pathname = store.event.isDataRequest
|
|
33
|
+
? add_data_suffix(store.event.url.pathname)
|
|
34
|
+
: store.event.url.pathname;
|
|
35
|
+
const after_base = pathname.slice(base.length);
|
|
30
36
|
const segments = after_base.split('/').slice(2);
|
|
31
37
|
const prefix = segments.map(() => '..').join('/') || '.';
|
|
32
38
|
|
|
@@ -74,5 +80,3 @@ export async function match(url) {
|
|
|
74
80
|
|
|
75
81
|
return null;
|
|
76
82
|
}
|
|
77
|
-
|
|
78
|
-
export { base, assets, resolve as resolveRoute };
|
|
@@ -77,9 +77,6 @@ export function command(validate_or_fn, maybe_fn) {
|
|
|
77
77
|
);
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
state.remote.refreshes ??= new Map();
|
|
81
|
-
state.remote.reconnects ??= new Map();
|
|
82
|
-
|
|
83
80
|
const promise = Promise.resolve(
|
|
84
81
|
run_remote_function(event, state, true, () => validate(arg), fn)
|
|
85
82
|
);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** @import { RemoteFormInput, RemoteForm, InvalidField } from '@sveltejs/kit' */
|
|
2
|
-
/** @import { InternalRemoteFormIssue, MaybePromise, RemoteFormInternals } from 'types' */
|
|
2
|
+
/** @import { InternalRemoteFormIssue, MaybePromise, HasNonOptionalBoolean, RemoteFormInternals } from 'types' */
|
|
3
3
|
/** @import { StandardSchemaV1 } from '@standard-schema/spec' */
|
|
4
4
|
import { get_request_store } from '@sveltejs/kit/internal/server';
|
|
5
5
|
import {
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
normalize_issue,
|
|
10
10
|
flatten_issues
|
|
11
11
|
} from '../../../form-utils.js';
|
|
12
|
-
import { get_cache, run_remote_function } from './shared.js';
|
|
12
|
+
import { get_cache, get_implicit_lookup, run_remote_function } from './shared.js';
|
|
13
13
|
import { ValidationError } from '@sveltejs/kit/internal';
|
|
14
14
|
|
|
15
15
|
/**
|
|
@@ -44,7 +44,7 @@ import { ValidationError } from '@sveltejs/kit/internal';
|
|
|
44
44
|
* @template {StandardSchemaV1<RemoteFormInput, Record<string, any>>} Schema
|
|
45
45
|
* @template Output
|
|
46
46
|
* @overload
|
|
47
|
-
* @param {Schema} validate
|
|
47
|
+
* @param {true extends HasNonOptionalBoolean<StandardSchemaV1.InferInput<Schema>> ? 'Error: All booleans in form schemas must be optional (e.g. `v.optional(v.boolean(), false)`) because checkbox inputs do not send a false value when unchecked.' : Schema} validate
|
|
48
48
|
* @param {(data: StandardSchemaV1.InferOutput<Schema>, issue: InvalidField<StandardSchemaV1.InferInput<Schema>>) => MaybePromise<Output>} fn
|
|
49
49
|
* @returns {RemoteForm<StandardSchemaV1.InferInput<Schema>, Output>}
|
|
50
50
|
* @since 2.27
|
|
@@ -108,9 +108,6 @@ export function form(validate_or_fn, maybe_fn) {
|
|
|
108
108
|
data = validated.value;
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
state.remote.refreshes ??= new Map();
|
|
112
|
-
state.remote.reconnects ??= new Map();
|
|
113
|
-
|
|
114
111
|
const issue = create_issues();
|
|
115
112
|
|
|
116
113
|
try {
|
|
@@ -133,7 +130,12 @@ export function form(validate_or_fn, maybe_fn) {
|
|
|
133
130
|
// We don't need to care about args or deduplicating calls, because uneval results are only relevant in full page reloads
|
|
134
131
|
// where only one form submission is active at the same time
|
|
135
132
|
if (!event.isRemoteRequest) {
|
|
136
|
-
get_cache(__, state)
|
|
133
|
+
const cache = get_cache(__, state);
|
|
134
|
+
cache[''] ??= output;
|
|
135
|
+
|
|
136
|
+
// register under the client-side action id so the output is serialized
|
|
137
|
+
// into the page, allowing the hydrated client to restore `result`/`issues`/`input`
|
|
138
|
+
get_implicit_lookup(__, state)[__.action_id ?? __.id] = () => cache[''];
|
|
137
139
|
}
|
|
138
140
|
|
|
139
141
|
return output;
|
|
@@ -149,28 +151,33 @@ export function form(validate_or_fn, maybe_fn) {
|
|
|
149
151
|
|
|
150
152
|
Object.defineProperty(instance, 'fields', {
|
|
151
153
|
get() {
|
|
154
|
+
// the form instance is created once per module and shared across requests,
|
|
155
|
+
// so the current request's state has to be resolved at access time
|
|
152
156
|
return create_field_proxy(
|
|
153
157
|
{},
|
|
154
|
-
() => get_cache(__)?.['']?.
|
|
158
|
+
() => get_cache(__, get_request_store().state)?.['']?.input ?? {},
|
|
155
159
|
(path, value) => {
|
|
156
|
-
const cache = get_cache(__);
|
|
160
|
+
const cache = get_cache(__, get_request_store().state);
|
|
157
161
|
const entry = cache[''];
|
|
158
162
|
|
|
159
|
-
if (entry?.
|
|
163
|
+
if (entry?.submission) {
|
|
160
164
|
// don't override a submission
|
|
161
165
|
return;
|
|
162
166
|
}
|
|
163
167
|
|
|
164
168
|
if (path.length === 0) {
|
|
165
|
-
(cache[''] ??= {
|
|
169
|
+
(cache[''] ??= {}).input = value;
|
|
166
170
|
return;
|
|
167
171
|
}
|
|
168
172
|
|
|
169
|
-
const input = entry?.
|
|
173
|
+
const input = entry?.input ?? {};
|
|
170
174
|
deep_set(input, path.map(String), value);
|
|
171
|
-
(cache[''] ??= {
|
|
175
|
+
(cache[''] ??= {}).input = input;
|
|
172
176
|
},
|
|
173
|
-
() => flatten_issues(get_cache(__)?.['']?.
|
|
177
|
+
() => flatten_issues(get_cache(__, get_request_store().state)?.['']?.issues ?? []),
|
|
178
|
+
() => ({}),
|
|
179
|
+
() => ({}),
|
|
180
|
+
[]
|
|
174
181
|
);
|
|
175
182
|
}
|
|
176
183
|
});
|
|
@@ -178,7 +185,7 @@ export function form(validate_or_fn, maybe_fn) {
|
|
|
178
185
|
Object.defineProperty(instance, 'result', {
|
|
179
186
|
get() {
|
|
180
187
|
try {
|
|
181
|
-
return get_cache(__)?.['']?.
|
|
188
|
+
return get_cache(__, get_request_store().state)?.['']?.result;
|
|
182
189
|
} catch {
|
|
183
190
|
return undefined;
|
|
184
191
|
}
|
|
@@ -190,6 +197,10 @@ export function form(validate_or_fn, maybe_fn) {
|
|
|
190
197
|
get: () => 0
|
|
191
198
|
});
|
|
192
199
|
|
|
200
|
+
Object.defineProperty(instance, 'submitted', {
|
|
201
|
+
get: () => false
|
|
202
|
+
});
|
|
203
|
+
|
|
193
204
|
Object.defineProperty(instance, 'preflight', {
|
|
194
205
|
// preflight is a noop on the server
|
|
195
206
|
value: () => instance
|
|
@@ -222,6 +233,7 @@ export function form(validate_or_fn, maybe_fn) {
|
|
|
222
233
|
if (!instance) {
|
|
223
234
|
instance = create_instance(key);
|
|
224
235
|
instance.__.id = `${__.id}/${encodeURIComponent(JSON.stringify(key))}`;
|
|
236
|
+
instance.__.action_id = `${__.id}/${JSON.stringify(key)}`;
|
|
225
237
|
instance.__.name = __.name;
|
|
226
238
|
|
|
227
239
|
state.remote.forms.set(cache_key, instance);
|