@sveltejs/kit 3.0.0-next.11 → 3.0.0-next.13

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.
Files changed (84) hide show
  1. package/package.json +10 -10
  2. package/src/cli.js +8 -8
  3. package/src/constants.js +1 -1
  4. package/src/core/config/options.js +43 -35
  5. package/src/core/env.js +25 -11
  6. package/src/core/postbuild/prerender.js +3 -3
  7. package/src/core/sync/sync.js +11 -14
  8. package/src/core/sync/utils.js +21 -1
  9. package/src/core/sync/{write_non_ambient.js → write_app_types.js} +24 -23
  10. package/src/core/sync/write_client_manifest.js +4 -12
  11. package/src/core/sync/write_env.js +6 -4
  12. package/src/core/sync/write_server.js +10 -15
  13. package/src/core/sync/write_tsconfig/index.js +257 -0
  14. package/src/core/sync/write_tsconfig/utils.js +162 -0
  15. package/src/core/sync/write_types/index.js +80 -88
  16. package/src/exports/index.js +23 -12
  17. package/src/exports/internal/server/index.js +3 -1
  18. package/src/exports/internal/shared.js +4 -12
  19. package/src/exports/public.d.ts +87 -62
  20. package/src/exports/vite/build/remote.js +10 -12
  21. package/src/exports/vite/dev/index.js +113 -88
  22. package/src/exports/vite/index.js +452 -237
  23. package/src/exports/vite/module_ids.js +3 -1
  24. package/src/exports/vite/utils.js +1 -10
  25. package/src/runner.js +13 -0
  26. package/src/runtime/app/forms.js +4 -0
  27. package/src/runtime/app/manifest/index.js +1 -0
  28. package/src/runtime/app/paths/client.js +30 -30
  29. package/src/runtime/app/paths/internal/client.js +26 -0
  30. package/src/runtime/app/paths/server.js +22 -9
  31. package/src/runtime/app/paths/types.d.ts +11 -19
  32. package/src/runtime/app/server/remote/command.js +12 -7
  33. package/src/runtime/app/server/remote/form.js +37 -26
  34. package/src/runtime/app/server/remote/prerender.js +22 -11
  35. package/src/runtime/app/server/remote/query.js +5 -4
  36. package/src/runtime/app/server/remote/requested.js +4 -4
  37. package/src/runtime/app/server/remote/shared.js +48 -30
  38. package/src/runtime/app/service-worker/index.js +24 -0
  39. package/src/runtime/app/state/client.js +3 -0
  40. package/src/runtime/app/state/index.js +3 -3
  41. package/src/runtime/app/state/server.js +3 -0
  42. package/src/runtime/client/client.js +627 -311
  43. package/src/runtime/client/constants.js +2 -6
  44. package/src/runtime/client/fetcher.js +27 -17
  45. package/src/runtime/client/remote-functions/form.svelte.js +82 -58
  46. package/src/runtime/client/remote-functions/prerender.svelte.js +1 -1
  47. package/src/runtime/client/remote-functions/query/index.js +2 -2
  48. package/src/runtime/client/remote-functions/query/instance.svelte.js +2 -2
  49. package/src/runtime/client/remote-functions/query-batch.svelte.js +3 -4
  50. package/src/runtime/client/remote-functions/query-live/instance.svelte.js +2 -2
  51. package/src/runtime/client/remote-functions/query-live/iterator.js +15 -10
  52. package/src/runtime/client/remote-functions/shared.svelte.js +15 -11
  53. package/src/runtime/client/state.svelte.js +54 -33
  54. package/src/runtime/client/types.d.ts +1 -2
  55. package/src/runtime/client/utils.js +21 -14
  56. package/src/runtime/components/root.svelte +4 -14
  57. package/src/runtime/form-utils.js +89 -54
  58. package/src/runtime/props.svelte.js +71 -0
  59. package/src/runtime/server/cookie.js +1 -1
  60. package/src/runtime/server/data/index.js +31 -28
  61. package/src/runtime/server/errors.js +1 -1
  62. package/src/runtime/server/fetch.js +4 -6
  63. package/src/runtime/server/page/actions.js +3 -3
  64. package/src/runtime/server/page/csp.js +86 -103
  65. package/src/runtime/server/page/index.js +1 -2
  66. package/src/runtime/server/page/load_data.js +15 -5
  67. package/src/runtime/server/page/render.js +46 -52
  68. package/src/runtime/server/page/respond_with_error.js +1 -3
  69. package/src/runtime/server/remote-functions.js +66 -35
  70. package/src/runtime/server/respond.js +56 -16
  71. package/src/runtime/server/utils.js +10 -0
  72. package/src/types/ambient-private.d.ts +9 -1
  73. package/src/types/ambient.d.ts +23 -28
  74. package/src/types/global-private.d.ts +12 -0
  75. package/src/types/internal.d.ts +15 -10
  76. package/src/types/private.d.ts +3 -12
  77. package/src/utils/url.js +12 -0
  78. package/src/version.js +1 -1
  79. package/types/index.d.ts +172 -155
  80. package/types/index.d.ts.map +5 -1
  81. package/src/core/sync/write_ambient.js +0 -18
  82. package/src/core/sync/write_tsconfig.js +0 -258
  83. package/src/runtime/types.d.ts +0 -8
  84. /package/src/core/sync/{write_tsconfig_test → write_tsconfig/test-app}/package.json +0 -0
@@ -27,10 +27,10 @@ export { defineParams } from './params.js';
27
27
  * return an error response without invoking `handleError`.
28
28
  * Make sure you're not catching the thrown error, which would prevent SvelteKit from handling it.
29
29
  * @param {number} status The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses). Must be in the range 400-599.
30
- * @param {Omit<App.Error, 'status'> & { status?: App.Error['status'] }} body An object that conforms to the App.Error type. If a string is passed, it will be used as the message property.
30
+ * @param {string} [message] The error message.
31
31
  * @overload
32
- * @param {number} status
33
- * @param {Omit<App.Error, 'status'> & { status?: App.Error['status'] }} body
32
+ * @param {{ status: number; message: string } extends App.Error ? number : never} status
33
+ * @param {{ status: number; message: string } extends App.Error ? string : never} [message]
34
34
  * @return {never}
35
35
  * @throws {import('./public.js').HttpError} This error instructs SvelteKit to initiate HTTP error handling.
36
36
  * @throws {Error} If the provided status is invalid (not between 400 and 599).
@@ -41,10 +41,12 @@ export { defineParams } from './params.js';
41
41
  * return an error response without invoking `handleError`.
42
42
  * Make sure you're not catching the thrown error, which would prevent SvelteKit from handling it.
43
43
  * @param {number} status The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses). Must be in the range 400-599.
44
- * @param {{ status: number; message: string } extends App.Error ? string | void | undefined : never} body The error message.
44
+ * @param {string} message The error message.
45
+ * @param {{ status: number; message: string } extends App.Error ? never : Omit<App.Error, 'status' | 'message'>} properties Additional properties of the App.Error type.
45
46
  * @overload
46
47
  * @param {number} status
47
- * @param {{ status: number; message: string } extends App.Error ? string | void | undefined : never} body
48
+ * @param {string} message
49
+ * @param {{ status: number; message: string } extends App.Error ? never : Omit<App.Error, 'status' | 'message'>} properties
48
50
  * @return {never}
49
51
  * @throws {import('./public.js').HttpError} This error instructs SvelteKit to initiate HTTP error handling.
50
52
  * @throws {Error} If the provided status is invalid (not between 400 and 599).
@@ -54,13 +56,12 @@ export { defineParams } from './params.js';
54
56
  * When called during request handling, this will cause SvelteKit to
55
57
  * return an error response without invoking `handleError`.
56
58
  * Make sure you're not catching the thrown error, which would prevent SvelteKit from handling it.
59
+ * @deprecated Passing an `App.Error` body as the second argument is deprecated — pass the `message` as the second argument, and any additional properties as the third
57
60
  * @param {number} status The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses). Must be in the range 400-599.
58
- * @param {string} body The error message.
59
- * @param {{ status: number; message: string } extends App.Error ? never : Omit<App.Error, 'status' | 'message'>} properties Additional properties of the App.Error type.
61
+ * @param {Omit<App.Error, 'status'> & { status?: App.Error['status'] }} body An object that conforms to the App.Error type. If a string is passed, it will be used as the message property.
60
62
  * @overload
61
63
  * @param {number} status
62
- * @param {string} body
63
- * @param {{ status: number; message: string } extends App.Error ? never : Omit<App.Error, 'status' | 'message'>} properties
64
+ * @param {Omit<App.Error, 'status'> & { status?: App.Error['status'] }} properties
64
65
  * @return {never}
65
66
  * @throws {import('./public.js').HttpError} This error instructs SvelteKit to initiate HTTP error handling.
66
67
  * @throws {Error} If the provided status is invalid (not between 400 and 599).
@@ -71,18 +72,28 @@ export { defineParams } from './params.js';
71
72
  * return an error response without invoking `handleError`.
72
73
  * Make sure you're not catching the thrown error, which would prevent SvelteKit from handling it.
73
74
  * @param {any} status The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses). Must be in the range 400-599.
74
- * @param {any} [body] An object that conforms to the App.Error type. If a string is passed, it will be used as the message property.
75
+ * @param {any} [message] A string, or (deprecated) a partial App.Error object
75
76
  * @param {any} [properties] Additional properties of the App.Error type when passing a string message.
76
77
  * @return {never}
77
78
  * @throws {import('./public.js').HttpError} This error instructs SvelteKit to initiate HTTP error handling.
78
79
  * @throws {Error} If the provided status is invalid (not between 400 and 599).
79
80
  */
80
- export function error(status, body, properties) {
81
+ export function error(status, message, properties) {
81
82
  if ((!BROWSER || DEV) && (isNaN(status) || status < 400 || status > 599)) {
82
83
  throw new Error(`HTTP error status codes must be between 400 and 599 — ${status} is invalid`);
83
84
  }
84
85
 
85
- throw new HttpError(status, body, properties);
86
+ if (message !== undefined && typeof message !== 'string') {
87
+ if (DEV) {
88
+ console.warn(
89
+ 'Passing an `App.Error` body as the second argument is deprecated — pass the `message` as the second argument, and any additional properties as the third'
90
+ );
91
+ }
92
+
93
+ ({ message, ...properties } = message);
94
+ }
95
+
96
+ throw new HttpError({ ...properties, status, message: message ?? `Error: ${status}` });
86
97
  }
87
98
 
88
99
  /**
@@ -2,7 +2,9 @@
2
2
  import { try_get_request_store } from './event.js';
3
3
 
4
4
  export function get_origin() {
5
- return try_get_request_store()?.event.url.origin;
5
+ // `request.url` rather than `event.url`, which throws inside queries
6
+ const request = try_get_request_store()?.event.request;
7
+ return request && new URL(request.url).origin;
6
8
  }
7
9
 
8
10
  /**
@@ -2,19 +2,11 @@
2
2
 
3
3
  export class HttpError {
4
4
  /**
5
- * @param {number} status
6
- * @param {Omit<App.Error, 'status'> | string | undefined} body
7
- * @param {Omit<App.Error, 'status' | 'message'>} [properties]
5
+ * @param {App.Error} error
8
6
  */
9
- constructor(status, body, properties) {
10
- this.status = status;
11
- if (typeof body === 'string') {
12
- this.body = { ...properties, message: body, status };
13
- } else if (body) {
14
- this.body = { ...body, status };
15
- } else {
16
- this.body = { message: `Error: ${status}`, status };
17
- }
7
+ constructor(error) {
8
+ this.status = error.status;
9
+ this.body = error;
18
10
  }
19
11
 
20
12
  toString() {
@@ -288,7 +288,7 @@ export interface Cookies {
288
288
  /**
289
289
  * Sets a cookie. This will add a `set-cookie` header to the response, but also make the cookie available via `cookies.get` or `cookies.getAll` during the current request.
290
290
  *
291
- * The `httpOnly` and `secure` options are `true` by default (except on http://localhost, where `secure` is `false`), and must be explicitly disabled if you want cookies to be readable by client-side JavaScript and/or transmitted over HTTP.
291
+ * The `httpOnly` is `true` by default, as is `secure`, except during development, when it defaults to `false`. These must be explicitly disabled if you want cookies to be readable by client-side JavaScript and/or transmitted over HTTP.
292
292
  *
293
293
  * The `path` option is `'/'` by default. You can use relative paths, or set `path: ''` to make the cookie only available on the current path and its children.
294
294
  * @param name the name of the cookie
@@ -300,7 +300,7 @@ export interface Cookies {
300
300
  /**
301
301
  * Deletes a cookie by setting its value to an empty string and setting the expiry date in the past.
302
302
  *
303
- * The `httpOnly` and `secure` options are `true` by default (except on http://localhost, where `secure` is `false`), and must be explicitly disabled if you want cookies to be readable by client-side JavaScript and/or transmitted over HTTP.
303
+ * The `httpOnly` is `true` by default, as is `secure`, except during development, when it defaults to `false`. These must be explicitly disabled if you want cookies to be readable by client-side JavaScript and/or transmitted over HTTP.
304
304
  *
305
305
  * The `path` option is `'/'` by default. You can use relative paths, or set `path: ''` to make the cookie only available on the current path and its children.
306
306
  * @param name the name of the cookie
@@ -335,7 +335,7 @@ export interface Cookies {
335
335
  /**
336
336
  * Serialize a cookie name-value pair into a `Set-Cookie` header string, but don't apply it to the response.
337
337
  *
338
- * The `httpOnly` and `secure` options are `true` by default (except on http://localhost, where `secure` is `false`), and must be explicitly disabled if you want cookies to be readable by client-side JavaScript and/or transmitted over HTTP.
338
+ * The `httpOnly` is `true` by default, as is `secure`, except during development, when it defaults to `false`. These must be explicitly disabled if you want cookies to be readable by client-side JavaScript and/or transmitted over HTTP.
339
339
  *
340
340
  * The `path` option is `'/'` by default. You can use relative paths, or set `path: ''` to make the cookie only available on the current path and its children.
341
341
  * @param name the name of the cookie
@@ -365,32 +365,10 @@ export interface KitConfig {
365
365
  /**
366
366
  * An object containing zero or more aliases used to replace values in `import` statements. These aliases are automatically passed to Vite and TypeScript.
367
367
  *
368
- * ```js
369
- * /// file: vite.config.js
370
- * import { defineConfig } from 'vite';
371
- * import { sveltekit } from '@sveltejs/kit/vite';
372
- *
373
- * export default defineConfig({
374
- * plugins: [
375
- * sveltekit({
376
- * alias: {
377
- * // this will match a file
378
- * 'my-file': 'path/to/my-file.js',
379
- *
380
- * // this will match a directory and its contents
381
- * // (`my-directory/x` resolves to `path/to/my-directory/x`)
382
- * 'my-directory': 'path/to/my-directory',
383
- *
384
- * // an alias ending /* will only match
385
- * // the contents of a directory, not the directory itself
386
- * 'my-directory/*': 'path/to/my-directory/*'
387
- * }
388
- * })
389
- * ]
390
- * });
391
- * ```
368
+ * This option is deprecated. Use [subpath imports](https://svelte.dev/docs/kit/$lib) instead.
392
369
  *
393
370
  * > [!NOTE] You will need to run `npm run dev` to have SvelteKit automatically generate the required alias configuration in `jsconfig.json` or `tsconfig.json`.
371
+ * @deprecated
394
372
  * @default {}
395
373
  */
396
374
  alias?: Record<string, string>;
@@ -846,13 +824,7 @@ export interface KitConfig {
846
824
  */
847
825
  resolution?: 'client' | 'server';
848
826
  };
849
- serviceWorker?: {
850
- /**
851
- * Determine which files in your `static` directory will be available in `$service-worker.files`.
852
- * @default (filename) => !/\.DS_Store/.test(filename)
853
- */
854
- files?: (file: string) => boolean;
855
- } & (
827
+ serviceWorker?:
856
828
  | {
857
829
  /**
858
830
  * Whether to automatically register the service worker, if it exists.
@@ -870,8 +842,7 @@ export interface KitConfig {
870
842
  * @default true
871
843
  */
872
844
  register?: false;
873
- }
874
- );
845
+ };
875
846
  /**
876
847
  * Options for enabling [OpenTelemetry](https://opentelemetry.io/) tracing for SvelteKit operations.
877
848
  * @default { server: false }
@@ -883,12 +854,15 @@ export interface KitConfig {
883
854
  */
884
855
  server?: boolean;
885
856
  };
857
+ /**
858
+ * @deprecated Add configuration to `tsconfig.json` directly
859
+ */
886
860
  typescript?: {
887
861
  /**
888
862
  * A function that allows you to edit the generated `tsconfig.json`. You can mutate the config (recommended) or return a new one.
889
863
  * This is useful for extending a shared `tsconfig.json` in a monorepo root, for example.
890
864
  *
891
- * Note that any paths configured here should be relative to the generated config file, which is written to `.svelte-kit/tsconfig.json`.
865
+ * Note that any paths configured here should be relative to the generated config file, which is written to `node_modules/$app/tsconfig/tsconfig.json`.
892
866
  *
893
867
  * @default (config) => config
894
868
  * @since 1.3.0
@@ -897,9 +871,9 @@ export interface KitConfig {
897
871
  };
898
872
  /**
899
873
  * Client-side navigation can be buggy if you deploy a new version of your app while people are using it. If the code for the new page is already loaded, it may have stale content; if it isn't, the app's route manifest may point to a JavaScript file that no longer exists.
900
- * SvelteKit helps you solve this problem through version management.
874
+ * SvelteKit helps you solve this problem through version management. The current version is included in data, remote, and form action responses via the `x-sveltekit-version` header, so SvelteKit can detect new deployments without polling — for example when a navigation triggers a server `load` function, or when a remote function is called. SvelteKit also checks for new versions when the tab regains focus or becomes visible.
901
875
  * If SvelteKit encounters an error while loading the page and detects that a new version has been deployed (using the `name` specified here, which defaults to a timestamp of the build) it will fall back to traditional full-page navigation.
902
- * Not all navigations will result in an error though, for example if the JavaScript for the next page is already loaded. If you still want to force a full-page navigation in these cases, use techniques such as setting the `pollInterval` and then using `beforeNavigate`:
876
+ * Not all navigations will result in an error though, for example if the JavaScript for the next page is already loaded. If you still want to force a full-page navigation in these cases, use `beforeNavigate`:
903
877
  * ```html
904
878
  * /// file: +layout.svelte
905
879
  * <script>
@@ -914,7 +888,7 @@ export interface KitConfig {
914
888
  * </script>
915
889
  * ```
916
890
  *
917
- * If you set `pollInterval` to a non-zero value, SvelteKit will poll for new versions in the background and set the value of [`updated.current`](https://svelte.dev/docs/kit/$app-state#updated) `true` when it detects one.
891
+ * In addition to these checks, SvelteKit polls for new versions on an interval and sets [`updated.current`](https://svelte.dev/docs/kit/$app-state#updated) to `true` when it detects one. Set `pollInterval` to `0` to disable polling (the header- and event-based checks will still run).
918
892
  */
919
893
  version?: {
920
894
  /**
@@ -941,8 +915,8 @@ export interface KitConfig {
941
915
  */
942
916
  name?: string;
943
917
  /**
944
- * The interval in milliseconds to poll for version changes. If this is `0`, no polling occurs.
945
- * @default 0
918
+ * The interval in milliseconds to poll for version changes. If this is `0`, no polling occurs. SvelteKit also checks for new versions on server responses (via the `x-sveltekit-version` header) and when the tab regains focus or becomes visible, so polling is only needed for long-lived sessions on a single page.
919
+ * @default 3600000
946
920
  */
947
921
  pollInterval?: number;
948
922
  };
@@ -1263,6 +1237,46 @@ export interface NavigationTarget<
1263
1237
  scroll: { x: number; y: number } | null;
1264
1238
  }
1265
1239
 
1240
+ export interface GotoOptions {
1241
+ /**
1242
+ * If `true`, replaces the current history entry rather than creating a new one.
1243
+ * @default false
1244
+ */
1245
+ replace?: boolean;
1246
+ /** @deprecated Use `replace` instead. */
1247
+ replaceState?: boolean;
1248
+ /**
1249
+ * If `true`, updates the URL and `page.state` without navigating.
1250
+ * @default false
1251
+ */
1252
+ shallow?: boolean;
1253
+ /**
1254
+ * If `true`, resets the scroll position (to the top of the page, or to the element
1255
+ * matching the URL's `#hash` if there is one) and resets focus (to the `<body>`, or the
1256
+ * `autofocus` element if there is one) once the navigation completes.
1257
+ *
1258
+ * If `false`, the current scroll position and focused element are left alone.
1259
+ * @default true, or false when `shallow` is true
1260
+ */
1261
+ reset?: boolean;
1262
+ /**
1263
+ * If `true`, reruns all `load` functions and queries of the page.
1264
+ * @default false
1265
+ */
1266
+ refreshAll?: boolean;
1267
+ /** Causes any `load` functions to rerun if they depend on one of the URLs. */
1268
+ invalidate?: Array<string | URL | ((url: URL) => boolean)>;
1269
+ /** @deprecated Use `refreshAll` instead. */
1270
+ invalidateAll?: boolean;
1271
+ /** An optional object that will be available as `page.state`. */
1272
+ state?: App.PageState;
1273
+ /**
1274
+ * If `true`, `page.state` will be restored after a full page reload.
1275
+ * @default false
1276
+ */
1277
+ persistState?: boolean;
1278
+ }
1279
+
1266
1280
  /**
1267
1281
  * - `enter`: The app has hydrated/started
1268
1282
  * - `form`: The user submitted a `<form method="GET">`
@@ -1284,6 +1298,8 @@ export interface NavigationBase {
1284
1298
  * - `popstate`: Navigation was triggered by back/forward navigation
1285
1299
  */
1286
1300
  type: NavigationType;
1301
+ /** Whether this is a shallow navigation. */
1302
+ shallow: boolean;
1287
1303
  /**
1288
1304
  * Where navigation was triggered from
1289
1305
  */
@@ -1378,10 +1394,7 @@ export interface NavigationLink extends NavigationBase {
1378
1394
  }
1379
1395
 
1380
1396
  export type Navigation =
1381
- | NavigationExternal
1382
- | NavigationFormSubmit
1383
- | NavigationPopState
1384
- | NavigationLink;
1397
+ NavigationExternal | NavigationFormSubmit | NavigationPopState | NavigationLink;
1385
1398
 
1386
1399
  /**
1387
1400
  * The argument passed to [`beforeNavigate`](https://svelte.dev/docs/kit/$app-navigation#beforeNavigate) callbacks.
@@ -1452,9 +1465,20 @@ export interface Page<
1452
1465
  */
1453
1466
  data: App.PageData & Record<string, any>;
1454
1467
  /**
1455
- * The page state, which can be manipulated using the [`pushState`](https://svelte.dev/docs/kit/$app-navigation#pushState) and [`replaceState`](https://svelte.dev/docs/kit/$app-navigation#replaceState) functions from `$app/navigation`.
1468
+ * The page state, which can be manipulated using [`goto`](https://svelte.dev/docs/kit/$app-navigation#goto) from `$app/navigation`.
1456
1469
  */
1457
1470
  state: App.PageState;
1471
+ /**
1472
+ * Information about the target of the current shallow navigation, or `null` if no shallow navigation has occurred.
1473
+ */
1474
+ shallow: {
1475
+ /** Parameters of the target route, or `null` if the URL does not resolve to a route. */
1476
+ params: AppLayoutParams<'/'> | null;
1477
+ /** Info about the target route, or `null` if the URL does not resolve to a route. */
1478
+ route: { id: AppRouteId } | null;
1479
+ /** The normalized URL passed to `goto(..., { shallow: true })`. */
1480
+ url: ReadonlyURL;
1481
+ } | null;
1458
1482
  /**
1459
1483
  * Filled only after a form submission. See [form actions](https://svelte.dev/docs/kit/form-actions) for more info.
1460
1484
  */
@@ -1475,8 +1499,7 @@ export type ParamValue = string | number | boolean | bigint;
1475
1499
  * A param matcher definition passed to [`defineParams`](https://svelte.dev/docs/kit/@sveltejs-kit#defineParams).
1476
1500
  */
1477
1501
  export type ParamDefinition =
1478
- | ((param: string) => ParamValue | undefined)
1479
- | StandardSchemaV1<string, ParamValue>;
1502
+ ((param: string) => ParamValue | undefined) | StandardSchemaV1<string, ParamValue>;
1480
1503
 
1481
1504
  /**
1482
1505
  * The return type of [`defineParams`](https://svelte.dev/docs/kit/@sveltejs-kit#defineParams).
@@ -1581,8 +1604,7 @@ export type LiveQueryRequestedResult<Validated, Output> = Iterable<
1581
1604
  };
1582
1605
 
1583
1606
  export type RequestedResult<Validated, Output> =
1584
- | QueryRequestedResult<Validated, Output>
1585
- | LiveQueryRequestedResult<Validated, Output>;
1607
+ QueryRequestedResult<Validated, Output> | LiveQueryRequestedResult<Validated, Output>;
1586
1608
 
1587
1609
  export interface RequestEvent<
1588
1610
  Params extends AppLayoutParams<'/'> = AppLayoutParams<'/'>,
@@ -1615,9 +1637,10 @@ export interface RequestEvent<
1615
1637
  /**
1616
1638
  * The parameters of the current route - e.g. for a route like `/blog/[slug]`, a `{ slug: string }` object.
1617
1639
  *
1618
- * In the context of a remote function request initiated by the client, this relates to the page the remote function
1619
- * was called from, _not_ the URL of the endpoint SvelteKit creates for the remote function. Never use this to determine
1620
- * whether or not a user is authorized to access certain data, as these values are part of the request which could be manipulated.
1640
+ * Inside `query` functions (including `query.batch` and `query.live`), accessing this property throws an error.
1641
+ * Pass values from the page as arguments to the query instead. Inside `form` and `command` functions it relates to the page
1642
+ * the remote function was called from, _not_ the URL of the endpoint SvelteKit creates for the remote function. Never use it
1643
+ * to determine whether or not a user is authorized to access certain data, as these values are part of the request which could be manipulated.
1621
1644
  */
1622
1645
  params: Params;
1623
1646
  /**
@@ -1635,9 +1658,10 @@ export interface RequestEvent<
1635
1658
  /**
1636
1659
  * The ID of the current route - e.g. for `src/routes/blog/[slug]`, it would be `/blog/[slug]`. It is `null` when no route is matched.
1637
1660
  *
1638
- * In the context of a remote function request initiated by the client, this relates to the page the remote function
1639
- * was called from, _not_ the URL of the endpoint SvelteKit creates for the remote function. Never use this to determine
1640
- * whether or not a user is authorized to access certain data, as these values are part of the request which could be manipulated.
1661
+ * Inside `query` functions (including `query.batch` and `query.live`), accessing this property throws an error.
1662
+ * Pass values from the page as arguments to the query instead. Inside `form` and `command` functions it relates to the page
1663
+ * the remote function was called from, _not_ the URL of the endpoint SvelteKit creates for the remote function. Never use it
1664
+ * to determine whether or not a user is authorized to access certain data, as these values are part of the request which could be manipulated.
1641
1665
  */
1642
1666
  id: RouteId;
1643
1667
  };
@@ -1667,9 +1691,10 @@ export interface RequestEvent<
1667
1691
  /**
1668
1692
  * The requested URL.
1669
1693
  *
1670
- * In the context of a remote function request initiated by the client, this relates to the page the remote function
1671
- * was called from, _not_ the URL of the endpoint SvelteKit creates for the remote function. Never use this to determine
1672
- * whether or not a user is authorized to access certain data, as these values are part of the request which could be manipulated.
1694
+ * Inside `query` functions (including `query.batch` and `query.live`), accessing this property throws an error.
1695
+ * Pass values from the page as arguments to the query instead. Inside `form` and `command` functions it relates to the page
1696
+ * the remote function was called from, _not_ the URL of the endpoint SvelteKit creates for the remote function. Never use it
1697
+ * to determine whether or not a user is authorized to access certain data, as these values are part of the request which could be manipulated.
1673
1698
  */
1674
1699
  url: URL;
1675
1700
  /**
@@ -1760,7 +1785,7 @@ export class Server {
1760
1785
 
1761
1786
  export interface ServerInitOptions {
1762
1787
  /** A map of environment variables. */
1763
- env: Record<string, string>;
1788
+ env: Record<string, string | undefined>;
1764
1789
  /** A function that turns an asset filename into a `ReadableStream`. Required for the `read` export from `$app/server` to work. */
1765
1790
  read?: (file: string) => MaybePromise<ReadableStream | null>;
1766
1791
  }
@@ -2107,7 +2132,7 @@ type AsArgs<Type extends keyof InputTypeMap, Value> = Type extends 'checkbox'
2107
2132
  ? [type: Type, value: Value | (string & {})]
2108
2133
  : Type extends 'file' | 'file multiple'
2109
2134
  ? [type: Type]
2110
- : [type: Type] | [type: Type, value: Value | (string & {})];
2135
+ : [type: Type] | [type: Type, value: Value | undefined];
2111
2136
 
2112
2137
  /**
2113
2138
  * Form field accessor type that provides name(), value(), and issues() methods
@@ -11,6 +11,7 @@ import { posixify } from '../../../utils/os.js';
11
11
  * @param {typeof import('vite')} vite
12
12
  * @param {string} out
13
13
  * @param {Array<{ hash: string, file: string }>} remotes
14
+ * @param {Map<string, string>} remote_original_by_hash
14
15
  * @param {ServerMetadata} metadata
15
16
  * @param {string} cwd
16
17
  * @param {(Rolldown.OutputAsset | Rolldown.OutputChunk)[]} server_chunks
@@ -20,6 +21,7 @@ export async function treeshake_prerendered_remotes(
20
21
  vite,
21
22
  out,
22
23
  remotes,
24
+ remote_original_by_hash,
23
25
  metadata,
24
26
  cwd,
25
27
  server_chunks,
@@ -45,11 +47,11 @@ export async function treeshake_prerendered_remotes(
45
47
 
46
48
  if (prerendered.length === 0) continue; // nothing to treeshake
47
49
 
48
- // remove file extension
49
- const remote_filename = path.basename(remote.file).split('.').slice(0, -1).join('.');
50
+ const original_id = remote_original_by_hash.get(remote.hash);
51
+ if (!original_id) continue;
50
52
 
51
53
  const remote_chunk = server_chunks.find((chunk) => {
52
- return chunk.name === remote_filename;
54
+ return chunk.type === 'chunk' && chunk.moduleIds.includes(original_id);
53
55
  });
54
56
 
55
57
  if (!remote_chunk) continue;
@@ -116,16 +118,12 @@ export async function treeshake_prerendered_remotes(
116
118
  })
117
119
  );
118
120
 
121
+ // the only possible outputs are the treeshaken chunk and, with sourcemaps, its map
119
122
  for (const output of bundle.output) {
120
- if (output.type !== 'chunk' || output.name !== 'treeshaken') return;
121
-
122
- fs.writeFileSync(chunk_path, output.code);
123
-
124
- const chunk_sourcemap = bundle.output.find(
125
- (o) => o.type === 'asset' && o.fileName === output.fileName + '.map'
126
- );
127
- if (chunk_sourcemap && chunk_sourcemap.type === 'asset') {
128
- fs.writeFileSync(chunk_path + '.map', chunk_sourcemap.source);
123
+ if (output.type === 'chunk') {
124
+ fs.writeFileSync(chunk_path, output.code);
125
+ } else {
126
+ fs.writeFileSync(chunk_path + '.map', output.source);
129
127
  }
130
128
  }
131
129
  }