@sveltejs/kit 2.56.0 → 2.57.0
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 +2 -2
- package/src/core/config/index.js +22 -2
- package/src/core/config/options.js +20 -4
- package/src/core/postbuild/prerender.js +2 -1
- package/src/core/sync/utils.js +8 -1
- package/src/core/utils.js +1 -2
- package/src/exports/node/index.js +2 -1
- package/src/exports/public.d.ts +25 -18
- package/src/exports/vite/build/build_service_worker.js +1 -1
- package/src/exports/vite/build/remote.js +126 -0
- package/src/exports/vite/dev/index.js +21 -8
- package/src/exports/vite/index.js +35 -22
- package/src/exports/vite/preview/index.js +5 -1
- package/src/exports/vite/utils.js +18 -0
- package/src/runtime/app/forms.js +2 -1
- package/src/runtime/app/server/remote/prerender.js +2 -1
- package/src/runtime/app/server/remote/query.js +2 -4
- package/src/runtime/app/server/remote/requested.js +3 -2
- package/src/runtime/app/server/remote/shared.js +2 -1
- package/src/runtime/client/client.js +7 -8
- package/src/runtime/client/fetcher.js +2 -1
- package/src/runtime/client/remote-functions/form.svelte.js +10 -5
- package/src/runtime/client/remote-functions/query.svelte.js +3 -2
- package/src/runtime/client/utils.js +2 -1
- package/src/runtime/server/fetch.js +4 -3
- package/src/runtime/server/index.js +3 -2
- package/src/runtime/server/page/index.js +3 -2
- package/src/runtime/server/page/load_data.js +4 -3
- package/src/runtime/server/page/render.js +7 -1
- package/src/runtime/server/respond.js +0 -17
- package/src/utils/functions.js +2 -0
- package/src/version.js +1 -1
- package/types/index.d.ts +27 -19
- package/types/index.d.ts.map +1 -1
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/** @import { Options } from '@sveltejs/vite-plugin-svelte' */
|
|
2
|
+
/** @import { PreprocessorGroup } from 'svelte/compiler' */
|
|
3
|
+
/** @import { ConfigEnv, Manifest, Plugin, ResolvedConfig, UserConfig, ViteDevServer } from 'vite' */
|
|
1
4
|
import fs from 'node:fs';
|
|
2
5
|
import path from 'node:path';
|
|
3
6
|
import process from 'node:process';
|
|
@@ -41,6 +44,7 @@ import {
|
|
|
41
44
|
import { import_peer } from '../../utils/import.js';
|
|
42
45
|
import { compact } from '../../utils/array.js';
|
|
43
46
|
import { should_ignore, has_children } from './static_analysis/utils.js';
|
|
47
|
+
import { treeshake_prerendered_remotes } from './build/remote.js';
|
|
44
48
|
|
|
45
49
|
const cwd = posixify(process.cwd());
|
|
46
50
|
|
|
@@ -86,7 +90,7 @@ const options_regex = /(export\s+const\s+(prerender|csr|ssr|trailingSlash))\s*=/
|
|
|
86
90
|
/** @type {Set<string>} */
|
|
87
91
|
const warned = new Set();
|
|
88
92
|
|
|
89
|
-
/** @type {
|
|
93
|
+
/** @type {PreprocessorGroup} */
|
|
90
94
|
const warning_preprocessor = {
|
|
91
95
|
script: ({ content, filename }) => {
|
|
92
96
|
if (!filename) return;
|
|
@@ -129,12 +133,12 @@ const warning_preprocessor = {
|
|
|
129
133
|
|
|
130
134
|
/**
|
|
131
135
|
* Returns the SvelteKit Vite plugins.
|
|
132
|
-
* @returns {Promise<
|
|
136
|
+
* @returns {Promise<Plugin[]>}
|
|
133
137
|
*/
|
|
134
138
|
export async function sveltekit() {
|
|
135
139
|
const svelte_config = await load_config();
|
|
136
140
|
|
|
137
|
-
/** @type {
|
|
141
|
+
/** @type {Options['preprocess']} */
|
|
138
142
|
let preprocess = svelte_config.preprocess;
|
|
139
143
|
if (Array.isArray(preprocess)) {
|
|
140
144
|
preprocess = [...preprocess, warning_preprocessor];
|
|
@@ -144,7 +148,7 @@ export async function sveltekit() {
|
|
|
144
148
|
preprocess = warning_preprocessor;
|
|
145
149
|
}
|
|
146
150
|
|
|
147
|
-
/** @type {
|
|
151
|
+
/** @type {Options} */
|
|
148
152
|
const vite_plugin_svelte_options = {
|
|
149
153
|
configFile: false,
|
|
150
154
|
extensions: svelte_config.extensions,
|
|
@@ -184,10 +188,10 @@ let build_metadata = undefined;
|
|
|
184
188
|
* - https://rollupjs.org/guide/en/#output-generation-hooks
|
|
185
189
|
*
|
|
186
190
|
* @param {{ svelte_config: import('types').ValidatedConfig }} options
|
|
187
|
-
* @return {Promise<
|
|
191
|
+
* @return {Promise<Plugin[]>}
|
|
188
192
|
*/
|
|
189
193
|
async function kit({ svelte_config }) {
|
|
190
|
-
/** @type {import('vite')} */
|
|
194
|
+
/** @type {typeof import('vite')} */
|
|
191
195
|
const vite = await import_peer('vite');
|
|
192
196
|
|
|
193
197
|
// @ts-ignore `vite.rolldownVersion` only exists in `vite 8`
|
|
@@ -198,10 +202,10 @@ async function kit({ svelte_config }) {
|
|
|
198
202
|
|
|
199
203
|
const version_hash = hash(kit.version.name);
|
|
200
204
|
|
|
201
|
-
/** @type {
|
|
205
|
+
/** @type {ResolvedConfig} */
|
|
202
206
|
let vite_config;
|
|
203
207
|
|
|
204
|
-
/** @type {
|
|
208
|
+
/** @type {ConfigEnv} */
|
|
205
209
|
let vite_config_env;
|
|
206
210
|
|
|
207
211
|
/** @type {boolean} */
|
|
@@ -213,7 +217,7 @@ async function kit({ svelte_config }) {
|
|
|
213
217
|
/** @type {() => Promise<void>} */
|
|
214
218
|
let finalise;
|
|
215
219
|
|
|
216
|
-
/** @type {
|
|
220
|
+
/** @type {UserConfig} */
|
|
217
221
|
let initial_config;
|
|
218
222
|
|
|
219
223
|
const service_worker_entry_file = resolve_entry(kit.files.serviceWorker);
|
|
@@ -233,7 +237,7 @@ async function kit({ svelte_config }) {
|
|
|
233
237
|
const sourcemapIgnoreList = /** @param {string} relative_path */ (relative_path) =>
|
|
234
238
|
relative_path.includes('node_modules') || relative_path.includes(kit.outDir);
|
|
235
239
|
|
|
236
|
-
/** @type {
|
|
240
|
+
/** @type {Plugin} */
|
|
237
241
|
const plugin_setup = {
|
|
238
242
|
name: 'vite-plugin-sveltekit-setup',
|
|
239
243
|
|
|
@@ -267,7 +271,7 @@ async function kit({ svelte_config }) {
|
|
|
267
271
|
const generated = path.posix.join(kit.outDir, 'generated');
|
|
268
272
|
|
|
269
273
|
// dev and preview config can be shared
|
|
270
|
-
/** @type {
|
|
274
|
+
/** @type {UserConfig} */
|
|
271
275
|
const new_config = {
|
|
272
276
|
resolve: {
|
|
273
277
|
alias: [
|
|
@@ -437,7 +441,7 @@ async function kit({ svelte_config }) {
|
|
|
437
441
|
}
|
|
438
442
|
};
|
|
439
443
|
|
|
440
|
-
/** @type {
|
|
444
|
+
/** @type {Plugin} */
|
|
441
445
|
const plugin_virtual_modules = {
|
|
442
446
|
name: 'vite-plugin-sveltekit-virtual-modules',
|
|
443
447
|
|
|
@@ -561,7 +565,7 @@ async function kit({ svelte_config }) {
|
|
|
561
565
|
/**
|
|
562
566
|
* Ensures that client-side code can't accidentally import server-side code,
|
|
563
567
|
* whether in `*.server.js` files, `$app/server`, `$lib/server`, or `$env/[static|dynamic]/private`
|
|
564
|
-
* @type {
|
|
568
|
+
* @type {Plugin}
|
|
565
569
|
*/
|
|
566
570
|
const plugin_guard = {
|
|
567
571
|
name: 'vite-plugin-sveltekit-guard',
|
|
@@ -668,7 +672,7 @@ async function kit({ svelte_config }) {
|
|
|
668
672
|
}
|
|
669
673
|
};
|
|
670
674
|
|
|
671
|
-
/** @type {
|
|
675
|
+
/** @type {ViteDevServer} */
|
|
672
676
|
let dev_server;
|
|
673
677
|
|
|
674
678
|
/** @type {Array<{ hash: string, file: string }>} */
|
|
@@ -680,7 +684,7 @@ async function kit({ svelte_config }) {
|
|
|
680
684
|
/** @type {Set<string>} Track which remote hashes have already been emitted */
|
|
681
685
|
const emitted_remote_hashes = new Set();
|
|
682
686
|
|
|
683
|
-
/** @type {
|
|
687
|
+
/** @type {Plugin} */
|
|
684
688
|
const plugin_remote = {
|
|
685
689
|
name: 'vite-plugin-sveltekit-remote',
|
|
686
690
|
|
|
@@ -809,7 +813,7 @@ async function kit({ svelte_config }) {
|
|
|
809
813
|
}
|
|
810
814
|
};
|
|
811
815
|
|
|
812
|
-
/** @type {
|
|
816
|
+
/** @type {Plugin} */
|
|
813
817
|
const plugin_compile = {
|
|
814
818
|
name: 'vite-plugin-sveltekit-compile',
|
|
815
819
|
|
|
@@ -821,7 +825,7 @@ async function kit({ svelte_config }) {
|
|
|
821
825
|
// avoids overwriting the base setting that's also set by Vitest
|
|
822
826
|
order: 'pre',
|
|
823
827
|
handler(config) {
|
|
824
|
-
/** @type {
|
|
828
|
+
/** @type {UserConfig} */
|
|
825
829
|
let new_config;
|
|
826
830
|
|
|
827
831
|
const kit_paths_base = kit.paths.base || '/';
|
|
@@ -1063,13 +1067,13 @@ async function kit({ svelte_config }) {
|
|
|
1063
1067
|
*/
|
|
1064
1068
|
writeBundle: {
|
|
1065
1069
|
sequential: true,
|
|
1066
|
-
async handler(_options) {
|
|
1070
|
+
async handler(_options, server_bundle) {
|
|
1067
1071
|
if (secondary_build_started) return; // only run this once
|
|
1068
1072
|
|
|
1069
1073
|
const verbose = vite_config.logLevel === 'info';
|
|
1070
1074
|
const log = logger({ verbose });
|
|
1071
1075
|
|
|
1072
|
-
/** @type {
|
|
1076
|
+
/** @type {Manifest} */
|
|
1073
1077
|
const server_manifest = JSON.parse(read(`${out}/server/.vite/manifest.json`));
|
|
1074
1078
|
|
|
1075
1079
|
/** @type {import('types').BuildData} */
|
|
@@ -1193,7 +1197,7 @@ async function kit({ svelte_config }) {
|
|
|
1193
1197
|
}
|
|
1194
1198
|
}
|
|
1195
1199
|
|
|
1196
|
-
/** @type {
|
|
1200
|
+
/** @type {Manifest} */
|
|
1197
1201
|
const client_manifest = JSON.parse(read(`${out}/client/.vite/manifest.json`));
|
|
1198
1202
|
|
|
1199
1203
|
/**
|
|
@@ -1318,6 +1322,15 @@ async function kit({ svelte_config }) {
|
|
|
1318
1322
|
env: { ...env.private, ...env.public }
|
|
1319
1323
|
});
|
|
1320
1324
|
|
|
1325
|
+
await treeshake_prerendered_remotes(
|
|
1326
|
+
out,
|
|
1327
|
+
remotes,
|
|
1328
|
+
metadata,
|
|
1329
|
+
cwd,
|
|
1330
|
+
server_bundle,
|
|
1331
|
+
vite_config.build.sourcemap
|
|
1332
|
+
);
|
|
1333
|
+
|
|
1321
1334
|
// generate a new manifest that doesn't include prerendered pages
|
|
1322
1335
|
fs.writeFileSync(
|
|
1323
1336
|
`${out}/server/manifest.js`,
|
|
@@ -1411,8 +1424,8 @@ async function kit({ svelte_config }) {
|
|
|
1411
1424
|
}
|
|
1412
1425
|
|
|
1413
1426
|
/**
|
|
1414
|
-
* @param {
|
|
1415
|
-
* @param {
|
|
1427
|
+
* @param {UserConfig} config
|
|
1428
|
+
* @param {UserConfig} resolved_config
|
|
1416
1429
|
*/
|
|
1417
1430
|
function warn_overridden_config(config, resolved_config) {
|
|
1418
1431
|
const overridden = find_overridden_config(config, resolved_config, enforced_config, '', []);
|
|
@@ -7,7 +7,7 @@ import { loadEnv, normalizePath } from 'vite';
|
|
|
7
7
|
import { createReadableStream, getRequest, setResponse } from '../../../exports/node/index.js';
|
|
8
8
|
import { installPolyfills } from '../../../exports/node/polyfills.js';
|
|
9
9
|
import { SVELTE_KIT_ASSETS } from '../../../constants.js';
|
|
10
|
-
import { not_found } from '../utils.js';
|
|
10
|
+
import { is_chrome_devtools_request, not_found } from '../utils.js';
|
|
11
11
|
|
|
12
12
|
/** @typedef {import('http').IncomingMessage} Req */
|
|
13
13
|
/** @typedef {import('http').ServerResponse} Res */
|
|
@@ -102,6 +102,10 @@ export async function preview(vite, vite_config, svelte_config) {
|
|
|
102
102
|
return;
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
+
if (is_chrome_devtools_request(pathname, res)) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
|
|
105
109
|
if (pathname.startsWith(base)) {
|
|
106
110
|
next();
|
|
107
111
|
} else {
|
|
@@ -76,6 +76,24 @@ export function get_env(env_config, mode) {
|
|
|
76
76
|
};
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
+
/**
|
|
80
|
+
* Silently respond with 404 for Chrome DevTools workspaces request.
|
|
81
|
+
* Chrome always requests this at the root, regardless of base path.
|
|
82
|
+
* Users who want workspaces can install `vite-plugin-devtools-json`,
|
|
83
|
+
* which takes precedence as Vite plugin middleware runs first.
|
|
84
|
+
* @param {string} pathname
|
|
85
|
+
* @param {import('http').ServerResponse} res
|
|
86
|
+
* @returns {boolean} `true` if the request was handled
|
|
87
|
+
*/
|
|
88
|
+
export function is_chrome_devtools_request(pathname, res) {
|
|
89
|
+
if (pathname === '/.well-known/appspecific/com.chrome.devtools.json') {
|
|
90
|
+
res.writeHead(404);
|
|
91
|
+
res.end('not found');
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
|
|
79
97
|
/**
|
|
80
98
|
* @param {import('http').IncomingMessage} req
|
|
81
99
|
* @param {import('http').ServerResponse} res
|
package/src/runtime/app/forms.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as devalue from 'devalue';
|
|
2
2
|
import { BROWSER, DEV } from 'esm-env';
|
|
3
|
+
import { noop } from '../../utils/functions.js';
|
|
3
4
|
import { invalidateAll } from './navigation.js';
|
|
4
5
|
import { app as client_app, applyAction } from '../client/client.js';
|
|
5
6
|
import { app as server_app } from '../server/app.js';
|
|
@@ -76,7 +77,7 @@ function clone(element) {
|
|
|
76
77
|
* @param {HTMLFormElement} form_element The form element
|
|
77
78
|
* @param {import('@sveltejs/kit').SubmitFunction<Success, Failure>} submit Submit callback
|
|
78
79
|
*/
|
|
79
|
-
export function enhance(form_element, submit =
|
|
80
|
+
export function enhance(form_element, submit = noop) {
|
|
80
81
|
if (DEV && clone(form_element).method !== 'post') {
|
|
81
82
|
throw new Error('use:enhance can only be used on <form> fields with method="POST"');
|
|
82
83
|
}
|
|
@@ -5,6 +5,7 @@ import { error, json } from '@sveltejs/kit';
|
|
|
5
5
|
import { DEV } from 'esm-env';
|
|
6
6
|
import { get_request_store } from '@sveltejs/kit/internal/server';
|
|
7
7
|
import { stringify, stringify_remote_arg } from '../../../shared.js';
|
|
8
|
+
import { noop } from '../../../../utils/functions.js';
|
|
8
9
|
import { app_dir, base } from '$app/paths/internal/server';
|
|
9
10
|
import {
|
|
10
11
|
create_validator,
|
|
@@ -153,7 +154,7 @@ export function prerender(validate_or_fn, fn_or_options, maybe_options) {
|
|
|
153
154
|
return result;
|
|
154
155
|
})();
|
|
155
156
|
|
|
156
|
-
promise.catch(
|
|
157
|
+
promise.catch(noop);
|
|
157
158
|
|
|
158
159
|
return /** @type {RemoteResource<Output>} */ (promise);
|
|
159
160
|
};
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import { get_request_store } from '@sveltejs/kit/internal/server';
|
|
5
5
|
import { create_remote_key, stringify, stringify_remote_arg } from '../../../shared.js';
|
|
6
6
|
import { prerendering } from '__sveltekit/environment';
|
|
7
|
+
import { noop } from '../../../../utils/functions.js';
|
|
7
8
|
import { create_validator, get_cache, get_response, run_remote_function } from './shared.js';
|
|
8
9
|
import { handle_error_and_jsonify } from '../../../server/utils.js';
|
|
9
10
|
import { HttpError, SvelteKitError } from '@sveltejs/kit/internal';
|
|
@@ -382,8 +383,5 @@ function update_refresh_value(
|
|
|
382
383
|
refreshes[refreshes_key] = promise;
|
|
383
384
|
}
|
|
384
385
|
|
|
385
|
-
return promise.then(
|
|
386
|
-
() => {},
|
|
387
|
-
() => {}
|
|
388
|
-
);
|
|
386
|
+
return promise.then(noop, noop);
|
|
389
387
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
/** @import { MaybePromise, RemoteQueryInternals } from 'types' */
|
|
3
3
|
import { get_request_store } from '@sveltejs/kit/internal/server';
|
|
4
4
|
import { create_remote_key, parse_remote_arg } from '../../../shared.js';
|
|
5
|
+
import { noop } from '../../../../utils/functions.js';
|
|
5
6
|
import { mark_argument_validated } from './query.js';
|
|
6
7
|
|
|
7
8
|
/**
|
|
@@ -55,7 +56,7 @@ export function requested(query, limit = Infinity) {
|
|
|
55
56
|
*/
|
|
56
57
|
const record_failure = (payload, error) => {
|
|
57
58
|
const promise = Promise.reject(error);
|
|
58
|
-
promise.catch(
|
|
59
|
+
promise.catch(noop);
|
|
59
60
|
|
|
60
61
|
const key = create_remote_key(internals.id, payload);
|
|
61
62
|
refreshes[key] = promise;
|
|
@@ -156,7 +157,7 @@ async function* race_all(array, fn) {
|
|
|
156
157
|
value: result
|
|
157
158
|
}));
|
|
158
159
|
|
|
159
|
-
promise.catch(
|
|
160
|
+
promise.catch(noop);
|
|
160
161
|
pending.add(promise);
|
|
161
162
|
}
|
|
162
163
|
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import { parse } from 'devalue';
|
|
4
4
|
import { error } from '@sveltejs/kit';
|
|
5
5
|
import { with_request_store, get_request_store } from '@sveltejs/kit/internal/server';
|
|
6
|
+
import { noop } from '../../../../utils/functions.js';
|
|
6
7
|
import {
|
|
7
8
|
stringify_remote_arg,
|
|
8
9
|
create_remote_key,
|
|
@@ -93,7 +94,7 @@ export async function get_response(internals, arg, state, get_result) {
|
|
|
93
94
|
.then((value) => {
|
|
94
95
|
void unfriendly_hydratable(remote_key, () => stringify(value, state.transport));
|
|
95
96
|
})
|
|
96
|
-
.catch(
|
|
97
|
+
.catch(noop);
|
|
97
98
|
}
|
|
98
99
|
|
|
99
100
|
return entry.data;
|
|
@@ -39,6 +39,7 @@ import {
|
|
|
39
39
|
PAGE_URL_KEY
|
|
40
40
|
} from './constants.js';
|
|
41
41
|
import { validate_page_exports } from '../../utils/exports.js';
|
|
42
|
+
import { noop } from '../../utils/functions.js';
|
|
42
43
|
import { compact } from '../../utils/array.js';
|
|
43
44
|
import {
|
|
44
45
|
INVALIDATED_PARAM,
|
|
@@ -166,7 +167,7 @@ function native_navigation(url, replace = false) {
|
|
|
166
167
|
} else {
|
|
167
168
|
location.href = url.href;
|
|
168
169
|
}
|
|
169
|
-
return new Promise(
|
|
170
|
+
return new Promise(noop);
|
|
170
171
|
}
|
|
171
172
|
|
|
172
173
|
/**
|
|
@@ -182,8 +183,6 @@ async function update_service_worker() {
|
|
|
182
183
|
}
|
|
183
184
|
}
|
|
184
185
|
|
|
185
|
-
function noop() {}
|
|
186
|
-
|
|
187
186
|
/** @type {import('types').CSRRoute[]} All routes of the app. Only available when kit.router.resolution=client */
|
|
188
187
|
let routes;
|
|
189
188
|
/** @type {import('types').CSRPageNodeLoader} */
|
|
@@ -940,7 +939,7 @@ async function load_node({ loader, parent, url, params, route, server_data_node
|
|
|
940
939
|
|
|
941
940
|
return promise;
|
|
942
941
|
},
|
|
943
|
-
setHeaders:
|
|
942
|
+
setHeaders: noop,
|
|
944
943
|
depends,
|
|
945
944
|
parent() {
|
|
946
945
|
if (is_tracking) {
|
|
@@ -1118,8 +1117,8 @@ async function load_route({ id, invalidating, url, params, route, preload }) {
|
|
|
1118
1117
|
// preload modules to avoid waterfall, but handle rejections
|
|
1119
1118
|
// so they don't get reported to Sentry et al (we don't need
|
|
1120
1119
|
// to act on the failures at this point)
|
|
1121
|
-
errors.forEach((loader) => loader?.().catch(
|
|
1122
|
-
loaders.forEach((loader) => loader?.[1]().catch(
|
|
1120
|
+
errors.forEach((loader) => loader?.().catch(noop));
|
|
1121
|
+
loaders.forEach((loader) => loader?.[1]().catch(noop));
|
|
1123
1122
|
|
|
1124
1123
|
/** @type {import('types').ServerNodesResponse | import('types').ServerRedirectNode | null} */
|
|
1125
1124
|
let server_data = null;
|
|
@@ -1232,7 +1231,7 @@ async function load_route({ id, invalidating, url, params, route, preload }) {
|
|
|
1232
1231
|
});
|
|
1233
1232
|
|
|
1234
1233
|
// if we don't do this, rejections will be unhandled
|
|
1235
|
-
for (const p of branch_promises) p.catch(
|
|
1234
|
+
for (const p of branch_promises) p.catch(noop);
|
|
1236
1235
|
|
|
1237
1236
|
/** @type {Array<import('./types.js').BranchNode | undefined>} */
|
|
1238
1237
|
const branch = [];
|
|
@@ -3229,7 +3228,7 @@ function create_navigation(current, intent, url, type, target_scroll = null) {
|
|
|
3229
3228
|
});
|
|
3230
3229
|
|
|
3231
3230
|
// Handle any errors off-chain so that it doesn't show up as an unhandled rejection
|
|
3232
|
-
complete.catch(
|
|
3231
|
+
complete.catch(noop);
|
|
3233
3232
|
|
|
3234
3233
|
/** @type {(import('@sveltejs/kit').Navigation | import('@sveltejs/kit').AfterNavigate) & { type: T }} */
|
|
3235
3234
|
const navigation = /** @type {any} */ ({
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { BROWSER, DEV } from 'esm-env';
|
|
2
|
+
import { noop } from '../../utils/functions.js';
|
|
2
3
|
import { hash } from '../../utils/hash.js';
|
|
3
4
|
import { base64_decode } from '../utils.js';
|
|
4
5
|
|
|
5
6
|
let loading = 0;
|
|
6
7
|
|
|
7
8
|
/** @type {typeof fetch} */
|
|
8
|
-
const native_fetch = BROWSER ? window.fetch : /** @type {any} */ (
|
|
9
|
+
const native_fetch = BROWSER ? window.fetch : /** @type {any} */ (noop);
|
|
9
10
|
|
|
10
11
|
export function lock_fetch() {
|
|
11
12
|
loading += 1;
|
|
@@ -156,6 +156,7 @@ export function form(id) {
|
|
|
156
156
|
}
|
|
157
157
|
|
|
158
158
|
try {
|
|
159
|
+
// eslint-disable-next-line @typescript-eslint/await-thenable -- `callback` is typed as returning `void` to allow returning e.g. `Promise<boolean>`
|
|
159
160
|
await callback({
|
|
160
161
|
form,
|
|
161
162
|
data,
|
|
@@ -172,7 +173,7 @@ export function form(id) {
|
|
|
172
173
|
|
|
173
174
|
/**
|
|
174
175
|
* @param {FormData} data
|
|
175
|
-
* @returns {Promise<
|
|
176
|
+
* @returns {Promise<boolean> & { updates: (...args: any[]) => Promise<boolean> }}
|
|
176
177
|
*/
|
|
177
178
|
function submit(data) {
|
|
178
179
|
// Store a reference to the current instance and increment the usage count for the duration
|
|
@@ -193,7 +194,7 @@ export function form(id) {
|
|
|
193
194
|
/** @type {Error | undefined} */
|
|
194
195
|
let updates_error;
|
|
195
196
|
|
|
196
|
-
/** @type {Promise<
|
|
197
|
+
/** @type {Promise<boolean> & { updates: (...args: RemoteQueryUpdate[]) => Promise<boolean> }} */
|
|
197
198
|
const promise = (async () => {
|
|
198
199
|
try {
|
|
199
200
|
await Promise.resolve();
|
|
@@ -230,14 +231,17 @@ export function form(id) {
|
|
|
230
231
|
|
|
231
232
|
if (form_result.type === 'result') {
|
|
232
233
|
({ issues: raw_issues = [], result } = devalue.parse(form_result.result, app.decoders));
|
|
234
|
+
const succeeded = raw_issues.length === 0;
|
|
233
235
|
|
|
234
|
-
if (
|
|
236
|
+
if (succeeded) {
|
|
235
237
|
if (form_result.refreshes) {
|
|
236
238
|
apply_refreshes(form_result.refreshes);
|
|
237
239
|
} else {
|
|
238
240
|
void invalidateAll();
|
|
239
241
|
}
|
|
240
242
|
}
|
|
243
|
+
|
|
244
|
+
return succeeded;
|
|
241
245
|
} else if (form_result.type === 'redirect') {
|
|
242
246
|
const stringified_refreshes = form_result.refreshes ?? '';
|
|
243
247
|
if (stringified_refreshes) {
|
|
@@ -245,6 +249,7 @@ export function form(id) {
|
|
|
245
249
|
}
|
|
246
250
|
// Use internal version to allow redirects to external URLs
|
|
247
251
|
void _goto(form_result.location, { invalidateAll: !stringified_refreshes }, 0);
|
|
252
|
+
return true;
|
|
248
253
|
} else {
|
|
249
254
|
throw new HttpError(form_result.status ?? 500, form_result.error);
|
|
250
255
|
}
|
|
@@ -460,8 +465,8 @@ export function form(id) {
|
|
|
460
465
|
|
|
461
466
|
instance[createAttachmentKey()] = create_attachment(
|
|
462
467
|
form_onsubmit(({ submit, form }) =>
|
|
463
|
-
submit().then(() => {
|
|
464
|
-
if (
|
|
468
|
+
submit().then((succeeded) => {
|
|
469
|
+
if (succeeded) {
|
|
465
470
|
form.reset();
|
|
466
471
|
}
|
|
467
472
|
})
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
import * as devalue from 'devalue';
|
|
13
13
|
import { HttpError, Redirect } from '@sveltejs/kit/internal';
|
|
14
14
|
import { DEV } from 'esm-env';
|
|
15
|
+
import { noop } from '../../../utils/functions.js';
|
|
15
16
|
import { with_resolvers } from '../../../utils/promise.js';
|
|
16
17
|
import { tick, untrack } from 'svelte';
|
|
17
18
|
import { create_remote_key, stringify_remote_arg, unfriendly_hydratable } from '../../shared.js';
|
|
@@ -30,7 +31,7 @@ import { create_remote_key, stringify_remote_arg, unfriendly_hydratable } from '
|
|
|
30
31
|
*/
|
|
31
32
|
function is_in_effect() {
|
|
32
33
|
try {
|
|
33
|
-
$effect.pre(
|
|
34
|
+
$effect.pre(noop);
|
|
34
35
|
return true;
|
|
35
36
|
} catch {
|
|
36
37
|
return false;
|
|
@@ -371,7 +372,7 @@ export class Query {
|
|
|
371
372
|
|
|
372
373
|
const promise = Promise.reject(error);
|
|
373
374
|
|
|
374
|
-
promise.catch(
|
|
375
|
+
promise.catch(noop);
|
|
375
376
|
this.#promise = promise;
|
|
376
377
|
}
|
|
377
378
|
|
|
@@ -2,6 +2,7 @@ import { BROWSER, DEV } from 'esm-env';
|
|
|
2
2
|
import { writable } from 'svelte/store';
|
|
3
3
|
import { assets } from '$app/paths';
|
|
4
4
|
import { version } from '__sveltekit/environment';
|
|
5
|
+
import { noop } from '../../utils/functions.js';
|
|
5
6
|
import { PRELOAD_PRIORITIES } from './constants.js';
|
|
6
7
|
|
|
7
8
|
/* global __SVELTEKIT_APP_VERSION_FILE__, __SVELTEKIT_APP_VERSION_POLL_INTERVAL__ */
|
|
@@ -242,7 +243,7 @@ export function notifiable_store(value) {
|
|
|
242
243
|
}
|
|
243
244
|
|
|
244
245
|
export const updated_listener = {
|
|
245
|
-
v:
|
|
246
|
+
v: noop
|
|
246
247
|
};
|
|
247
248
|
|
|
248
249
|
export function create_updated_store() {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as set_cookie_parser from 'set-cookie-parser';
|
|
2
|
+
import { noop } from '../../utils/functions.js';
|
|
2
3
|
import { respond } from './respond.js';
|
|
3
4
|
import * as paths from '$app/paths/internal/server';
|
|
4
5
|
import { read_implementation } from '__sveltekit/server';
|
|
@@ -175,11 +176,11 @@ export function create_fetch({ event, options, manifest, state, get_cookie_heade
|
|
|
175
176
|
};
|
|
176
177
|
|
|
177
178
|
// Don't make this function `async`! Otherwise, the user has to `catch` promises they use for streaming responses or else
|
|
178
|
-
// it will be an unhandled rejection. Instead, we add a `.catch(
|
|
179
|
+
// it will be an unhandled rejection. Instead, we add a `.catch(noop)` ourselves below to prevent this from happening.
|
|
179
180
|
return (input, init) => {
|
|
180
181
|
// See docs in fetch.js for why we need to do this
|
|
181
182
|
const response = server_fetch(input, init);
|
|
182
|
-
response.catch(
|
|
183
|
+
response.catch(noop);
|
|
183
184
|
return response;
|
|
184
185
|
};
|
|
185
186
|
}
|
|
@@ -210,7 +211,7 @@ async function internal_fetch(request, options, manifest, state) {
|
|
|
210
211
|
throw new DOMException('The operation was aborted.', 'AbortError');
|
|
211
212
|
}
|
|
212
213
|
|
|
213
|
-
let remove_abort_listener =
|
|
214
|
+
let remove_abort_listener = noop;
|
|
214
215
|
/** @type {Promise<never>} */
|
|
215
216
|
const abort_promise = new Promise((_, reject) => {
|
|
216
217
|
const on_abort = () => {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/** @import { PromiseWithResolvers } from '../../utils/promise.js' */
|
|
2
|
+
import { noop } from '../../utils/functions.js';
|
|
2
3
|
import { with_resolvers } from '../../utils/promise.js';
|
|
3
4
|
import { IN_WEBCONTAINER } from './constants.js';
|
|
4
5
|
import { respond } from './respond.js';
|
|
@@ -126,7 +127,7 @@ export class Server {
|
|
|
126
127
|
console.error('Remote function schema validation failed:', issues);
|
|
127
128
|
return { message: 'Bad Request' };
|
|
128
129
|
}),
|
|
129
|
-
reroute: module.reroute ||
|
|
130
|
+
reroute: module.reroute || noop,
|
|
130
131
|
transport: module.transport || {}
|
|
131
132
|
};
|
|
132
133
|
|
|
@@ -150,7 +151,7 @@ export class Server {
|
|
|
150
151
|
handleValidationError: () => {
|
|
151
152
|
return { message: 'Bad Request' };
|
|
152
153
|
},
|
|
153
|
-
reroute:
|
|
154
|
+
reroute: noop,
|
|
154
155
|
transport: {}
|
|
155
156
|
};
|
|
156
157
|
|
|
@@ -2,6 +2,7 @@ import { text } from '@sveltejs/kit';
|
|
|
2
2
|
import { HttpError, Redirect } from '@sveltejs/kit/internal';
|
|
3
3
|
import { compact } from '../../../utils/array.js';
|
|
4
4
|
import { get_status, normalize_error } from '../../../utils/error.js';
|
|
5
|
+
import { noop } from '../../../utils/functions.js';
|
|
5
6
|
import { add_data_suffix } from '../../pathname.js';
|
|
6
7
|
import { redirect_response, static_error_page, handle_error_and_jsonify } from '../utils.js';
|
|
7
8
|
import {
|
|
@@ -239,8 +240,8 @@ export async function render_page(
|
|
|
239
240
|
});
|
|
240
241
|
|
|
241
242
|
// if we don't do this, rejections will be unhandled
|
|
242
|
-
for (const p of server_promises) p.catch(
|
|
243
|
-
for (const p of load_promises) p.catch(
|
|
243
|
+
for (const p of server_promises) p.catch(noop);
|
|
244
|
+
for (const p of load_promises) p.catch(noop);
|
|
244
245
|
|
|
245
246
|
for (let i = 0; i < nodes.data.length; i += 1) {
|
|
246
247
|
const node = nodes.data[i];
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DEV } from 'esm-env';
|
|
2
|
+
import { noop } from '../../../utils/functions.js';
|
|
2
3
|
import { disable_search, make_trackable } from '../../../utils/url.js';
|
|
3
4
|
import { validate_depends, validate_load_response } from '../../shared.js';
|
|
4
5
|
import { with_request_store, merge_tracing } from '@sveltejs/kit/internal/server';
|
|
@@ -243,7 +244,7 @@ export async function load_data({
|
|
|
243
244
|
route: event.route,
|
|
244
245
|
fetch: create_universal_fetch(event, state, fetched, csr, resolve_opts),
|
|
245
246
|
setHeaders: event.setHeaders,
|
|
246
|
-
depends:
|
|
247
|
+
depends: noop,
|
|
247
248
|
parent,
|
|
248
249
|
untrack: (fn) => fn(),
|
|
249
250
|
tracing: traced_event.tracing
|
|
@@ -477,11 +478,11 @@ export function create_universal_fetch(event, state, fetched, csr, resolve_opts)
|
|
|
477
478
|
};
|
|
478
479
|
|
|
479
480
|
// Don't make this function `async`! Otherwise, the user has to `catch` promises they use for streaming responses or else
|
|
480
|
-
// it will be an unhandled rejection. Instead, we add a `.catch(
|
|
481
|
+
// it will be an unhandled rejection. Instead, we add a `.catch(noop)` ourselves below to this from happening.
|
|
481
482
|
return (input, init) => {
|
|
482
483
|
// See docs in fetch.js for why we need to do this
|
|
483
484
|
const response = universal_fetch(input, init);
|
|
484
|
-
response.catch(
|
|
485
|
+
response.catch(noop);
|
|
485
486
|
return response;
|
|
486
487
|
};
|
|
487
488
|
}
|
|
@@ -614,8 +614,14 @@ export async function render_response({
|
|
|
614
614
|
// we use an anonymous function instead of an arrow function to support
|
|
615
615
|
// older browsers (https://github.com/sveltejs/kit/pull/5417)
|
|
616
616
|
blocks.push(`if ('serviceWorker' in navigator) {
|
|
617
|
+
const script_url = '${prefixed('service-worker.js')}';
|
|
618
|
+
const policy = globalThis?.window?.trustedTypes?.createPolicy(
|
|
619
|
+
'sveltekit-trusted-url',
|
|
620
|
+
{ createScriptURL(url) { return url; } }
|
|
621
|
+
);
|
|
622
|
+
const sanitised = policy?.createScriptURL(script_url) ?? script_url;
|
|
617
623
|
addEventListener('load', function () {
|
|
618
|
-
navigator.serviceWorker.register(
|
|
624
|
+
navigator.serviceWorker.register(sanitised${opts});
|
|
619
625
|
});
|
|
620
626
|
}`);
|
|
621
627
|
}
|