@sveltejs/kit 3.0.0-next.22 → 3.0.0-next.24

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 (106) hide show
  1. package/package.json +40 -9
  2. package/src/cli.js +3 -3
  3. package/src/constants.js +13 -1
  4. package/src/core/adapt/builder.js +2 -3
  5. package/src/core/env.js +139 -181
  6. package/src/core/postbuild/analyse.js +9 -4
  7. package/src/core/postbuild/prerender.js +22 -23
  8. package/src/core/sync/create_manifest_data/index.js +29 -33
  9. package/src/core/sync/sync.js +23 -40
  10. package/src/core/sync/write_app_manifest.js +83 -0
  11. package/src/core/sync/write_client_manifest.js +6 -4
  12. package/src/core/sync/write_server.js +10 -6
  13. package/src/core/sync/write_types/index.js +2 -2
  14. package/src/core/utils.js +0 -28
  15. package/src/exports/hooks/public.d.ts +9 -1
  16. package/src/exports/index.js +10 -0
  17. package/src/exports/node/index.js +77 -5
  18. package/src/exports/public.d.ts +9 -0
  19. package/src/exports/vite/build/build_server.js +3 -3
  20. package/src/exports/vite/build/utils.js +48 -4
  21. package/src/exports/vite/dev/index.js +11 -22
  22. package/src/exports/vite/index.js +62 -345
  23. package/src/exports/vite/module_ids.js +1 -11
  24. package/src/exports/vite/plugins/env-vars.js +117 -0
  25. package/src/exports/vite/preview/index.js +6 -4
  26. package/src/exports/vite/utils.js +2 -4
  27. package/src/runtime/app/env/{types.d.ts → client.js} +9 -4
  28. package/src/runtime/app/env/index.js +1 -2
  29. package/src/runtime/app/env/private/index.js +1 -0
  30. package/src/runtime/app/env/public/client.js +1 -1
  31. package/src/runtime/app/env/public/server.js +1 -1
  32. package/src/runtime/app/env/{internal.js → server.js} +4 -4
  33. package/src/runtime/app/forms/client.js +263 -0
  34. package/src/runtime/app/forms/index.js +1 -263
  35. package/src/runtime/app/forms/public.d.ts +1 -1
  36. package/src/runtime/app/forms/server.js +6 -0
  37. package/src/runtime/app/forms/shared.js +34 -0
  38. package/src/runtime/app/manifest/index.js +1 -1
  39. package/src/runtime/app/navigation/client.js +15 -0
  40. package/src/runtime/app/navigation/index.js +1 -15
  41. package/src/runtime/app/navigation/public.d.ts +1 -1
  42. package/src/runtime/app/navigation/server.js +15 -0
  43. package/src/runtime/app/paths/server.js +1 -1
  44. package/src/runtime/app/server/public.d.ts +512 -0
  45. package/src/runtime/app/server/remote/command.js +1 -1
  46. package/src/runtime/app/server/remote/form.js +16 -6
  47. package/src/runtime/app/server/remote/prerender.js +2 -3
  48. package/src/runtime/app/server/remote/query.js +2 -2
  49. package/src/runtime/app/server/remote/requested.js +3 -3
  50. package/src/runtime/app/state/client.svelte.js +207 -0
  51. package/src/runtime/app/state/index.js +1 -66
  52. package/src/runtime/app/state/public.d.ts +1 -1
  53. package/src/runtime/client/bundle.js +1 -1
  54. package/src/runtime/client/client.js +206 -274
  55. package/src/runtime/client/fetcher.js +18 -8
  56. package/src/runtime/client/remote-functions/command.svelte.js +1 -1
  57. package/src/runtime/client/remote-functions/form.svelte.js +10 -7
  58. package/src/runtime/client/remote-functions/prerender.svelte.js +2 -2
  59. package/src/runtime/client/remote-functions/query/index.js +1 -1
  60. package/src/runtime/client/remote-functions/query/instance.svelte.js +2 -1
  61. package/src/runtime/client/remote-functions/query-batch.svelte.js +1 -1
  62. package/src/runtime/client/remote-functions/query-live/index.js +1 -1
  63. package/src/runtime/client/remote-functions/query-live/instance.svelte.js +4 -3
  64. package/src/runtime/client/remote-functions/query-live/iterator.js +1 -1
  65. package/src/runtime/client/remote-functions/shared.svelte.js +3 -3
  66. package/src/runtime/client/snapshots.js +1 -3
  67. package/src/runtime/client/stream.js +27 -20
  68. package/src/runtime/client/utils.js +7 -3
  69. package/src/runtime/components/root.svelte +5 -5
  70. package/src/runtime/env/dynamic/private.js +1 -1
  71. package/src/runtime/env/static/private.js +1 -1
  72. package/src/runtime/error-chain.js +54 -0
  73. package/src/runtime/form-utils.js +53 -77
  74. package/src/runtime/invalid-import.js +1 -0
  75. package/src/runtime/props.svelte.js +1 -1
  76. package/src/runtime/server/data/index.js +1 -1
  77. package/src/runtime/server/endpoint.js +8 -3
  78. package/src/runtime/server/env_module.js +1 -1
  79. package/src/runtime/server/errors.js +2 -2
  80. package/src/runtime/server/index.js +2 -2
  81. package/src/runtime/server/page/actions.js +77 -122
  82. package/src/runtime/server/page/index.js +37 -69
  83. package/src/runtime/server/page/render.js +18 -23
  84. package/src/runtime/server/remote-functions.js +15 -43
  85. package/src/runtime/server/respond.js +23 -3
  86. package/src/telemetry.js +1 -33
  87. package/src/types/ambient-private.d.ts +9 -17
  88. package/src/types/internal.d.ts +21 -5
  89. package/src/types/private.d.ts +1 -1
  90. package/src/utils/exports.js +1 -0
  91. package/src/utils/filesystem.js +9 -21
  92. package/src/utils/functions.js +10 -0
  93. package/src/utils/promise.js +25 -0
  94. package/src/utils/routing.js +0 -11
  95. package/src/utils/url.js +0 -11
  96. package/src/version.js +1 -1
  97. package/types/index.d.ts +1134 -1136
  98. package/types/index.d.ts.map +50 -50
  99. package/src/exports/remote/index.js +0 -11
  100. package/src/exports/remote/public.d.ts +0 -519
  101. package/src/runtime/app/env/private.js +0 -1
  102. package/src/runtime/app/env/standard-schema.d.ts +0 -0
  103. package/src/runtime/app/state/client.js +0 -63
  104. package/src/runtime/client/state.svelte.js +0 -98
  105. package/src/runtime/server/ambient.d.ts +0 -4
  106. package/src/utils/path.js +0 -23
@@ -1,6 +1,6 @@
1
1
  /** @import { SSRNode } from 'types' */
2
2
  import { DEV } from 'esm-env';
3
- import { json, text } from '@sveltejs/kit';
3
+ import { text } from '@sveltejs/kit';
4
4
  import { Redirect, SvelteKitError } from '@sveltejs/kit/internal';
5
5
  import {
6
6
  merge_tracing,
@@ -111,7 +111,7 @@ export async function internal_respond(request, options, manifest, state) {
111
111
  })
112
112
  ) {
113
113
  const message = 'Cross-site remote requests are forbidden';
114
- return json({ message }, { status: 403 });
114
+ return Response.json({ message }, { status: 403 });
115
115
  }
116
116
  } else if (options.csrf_check_origin) {
117
117
  const forbidden = is_csrf_forbidden({
@@ -126,7 +126,7 @@ export async function internal_respond(request, options, manifest, state) {
126
126
  const opts = { status: 403 };
127
127
 
128
128
  if (request.headers.get('accept') === 'application/json') {
129
- return json({ message }, opts);
129
+ return Response.json({ message }, opts);
130
130
  }
131
131
 
132
132
  return text(message, opts);
@@ -754,6 +754,26 @@ export async function internal_respond(request, options, manifest, state) {
754
754
  // if this request came direct from the user, rather than
755
755
  // via our own `fetch`, render a 404 page
756
756
  if (state.depth === 0) {
757
+ // Error-page data requests only invalidate the root layout.
758
+ if (
759
+ !state.prerendering &&
760
+ is_data_request &&
761
+ invalidated_data_nodes?.length === 1 &&
762
+ invalidated_data_nodes[0]
763
+ ) {
764
+ return await render_data(
765
+ event,
766
+ state,
767
+ { page: { layouts: [], leaf: 0 } },
768
+ options,
769
+ manifest,
770
+ invalidated_data_nodes,
771
+ // there is no route to take a trailing slash option from, and the
772
+ // SSR'd error page sees the pathname as-is
773
+ 'ignore'
774
+ );
775
+ }
776
+
757
777
  if (non_html_fetch_destinations.has(event.request.headers.get('sec-fetch-dest') ?? '')) {
758
778
  return text('Not Found', {
759
779
  status: 404,
package/src/telemetry.js CHANGED
@@ -1,36 +1,4 @@
1
- /** @import { Tracer, Span, SpanContext } from '@opentelemetry/api' */
2
-
3
- /**
4
- * Tracer implementation that does nothing (null object).
5
- * @type {Tracer}
6
- */
7
- export const noop_tracer = {
8
- /**
9
- * @returns {Span}
10
- */
11
- startSpan() {
12
- return noop_span;
13
- },
14
-
15
- /**
16
- * @param {unknown} _name
17
- * @param {unknown} arg_1
18
- * @param {unknown} [arg_2]
19
- * @param {Function} [arg_3]
20
- * @returns {unknown}
21
- */
22
- startActiveSpan(_name, arg_1, arg_2, arg_3) {
23
- if (typeof arg_1 === 'function') {
24
- return arg_1(noop_span);
25
- }
26
- if (typeof arg_2 === 'function') {
27
- return arg_2(noop_span);
28
- }
29
- if (typeof arg_3 === 'function') {
30
- return arg_3(noop_span);
31
- }
32
- }
33
- };
1
+ /** @import { Span, SpanContext } from '@opentelemetry/api' */
34
2
 
35
3
  /**
36
4
  * @type {Span}
@@ -1,18 +1,10 @@
1
- /** Internal version of $app/paths */
2
- declare module '__sveltekit/paths' {
3
- export let base: '' | `/${string}`;
4
- export let assets: '' | `https://${string}` | `http://${string}` | '/_svelte_kit_assets';
5
- export let app_dir: string;
6
- export let relative: boolean;
7
- export function reset(): void;
8
- export function override(paths: { base: string; assets: string }): void;
9
- export function set_assets(path: string): void;
10
- }
11
-
12
1
  /** Internal version of $app/server */
13
- declare module '__sveltekit/server' {
2
+ declare module '<sveltekit:generated>/server.js' {
14
3
  import { SSRManifest } from '@sveltejs/kit';
4
+ import { SSROptions, ServerHooks } from 'types';
15
5
 
6
+ export const options: SSROptions;
7
+ export const get_hooks: () => Promise<Partial<ServerHooks>>;
16
8
  export let fix_stack_trace: (error: Error) => string;
17
9
  export let manifest: SSRManifest;
18
10
  export function read_implementation(path: string): ReadableStream;
@@ -21,7 +13,7 @@ declare module '__sveltekit/server' {
21
13
  export function set_read_implementation(fn: (path: string) => ReadableStream): void;
22
14
  }
23
15
 
24
- declare module '__sveltekit/env' {
16
+ declare module '<sveltekit:generated>/env/config.js' {
25
17
  // exported environment variables are defined in env.d.ts
26
18
 
27
19
  /** Populate exported environment variables */
@@ -34,20 +26,20 @@ declare module '__sveltekit/env' {
34
26
  export const rendered_env: Record<string, any>;
35
27
  }
36
28
 
37
- declare module '__sveltekit/env/private' {
29
+ declare module '<sveltekit:generated>/env/private/server.js' {
38
30
  // exported environment variables are defined in env.d.ts
39
31
  }
40
32
 
41
- declare module '__sveltekit/env/public/client' {
33
+ declare module '<sveltekit:generated>/env/public/client.js' {
42
34
  // exported environment variables are defined in env.d.ts
43
35
  }
44
36
 
45
- declare module '__sveltekit/env/public/server' {
37
+ declare module '<sveltekit:generated>/env/public/server.js' {
46
38
  // exported environment variables are defined in env.d.ts
47
39
  }
48
40
 
49
41
  /** Internal version of $app/manifest */
50
- declare module '__sveltekit/manifest-data' {
42
+ declare module '<sveltekit:generated>/app-manifest.js' {
51
43
  export const immutable: Array<{ path: string }>;
52
44
  export const assets: Array<{ path: string }>;
53
45
  export const prerendered: Array<{ path: string }>;
@@ -8,9 +8,10 @@ import {
8
8
  Actions,
9
9
  RequestEvent,
10
10
  SSRManifest,
11
- Emulator
11
+ Emulator,
12
+ HttpError
12
13
  } from '@sveltejs/kit';
13
- import { RemoteFormIssue, RemoteQuery, RemoteLiveQuery } from '@sveltejs/kit/remote';
14
+ import { RemoteFormIssue, RemoteQuery, RemoteLiveQuery } from '$app/server';
14
15
  import { Config } from '@sveltejs/kit/vite';
15
16
  import {
16
17
  ClientInit,
@@ -61,10 +62,17 @@ export interface AssetDependencies {
61
62
  file: string;
62
63
  imports: string[];
63
64
  stylesheets: string[];
64
- fonts: string[];
65
+ fonts: FontDependency[];
65
66
  stylesheet_map: Map<string, { css: Set<string>; assets: Set<string> }>;
66
67
  }
67
68
 
69
+ export interface FontDependency {
70
+ /** emitted file path, relative to the client output directory */
71
+ file: string;
72
+ /** the source file path relative to the project root, before hashing and character sanitization */
73
+ filename: string;
74
+ }
75
+
68
76
  export interface BuildData {
69
77
  app_dir: string;
70
78
  app_path: string;
@@ -97,7 +105,7 @@ export interface BuildData {
97
105
  */
98
106
  routes?: SSRClientRoute[];
99
107
  stylesheets: string[];
100
- fonts: string[];
108
+ fonts: FontDependency[];
101
109
  /**
102
110
  * Whether the client uses public dynamic env vars — `$env/dynamic/public` or `$app/env/public`.
103
111
  */
@@ -292,6 +300,14 @@ export interface RouteData {
292
300
  } | null;
293
301
  }
294
302
 
303
+ /**
304
+ * The server-side form of `ActionResult`, before the error is passed
305
+ * through `handleError` and the data is serialized
306
+ */
307
+ export type ServerActionResult =
308
+ | Exclude<import('$app/forms').ActionResult, { type: 'error' }>
309
+ | { type: 'error'; location: string; error: Error | HttpError };
310
+
295
311
  export type ServerRedirectNode = {
296
312
  type: 'redirect';
297
313
  status: number;
@@ -449,7 +465,7 @@ export interface SSRNode {
449
465
  /** external CSS files that are loaded on the client */
450
466
  stylesheets: string[];
451
467
  /** external font files that are loaded on the client */
452
- fonts: string[];
468
+ fonts: FontDependency[];
453
469
 
454
470
  universal_id?: string;
455
471
  server_id?: string;
@@ -154,7 +154,7 @@ export interface CspDirectives {
154
154
  >;
155
155
  }
156
156
 
157
- export type HttpMethod = 'GET' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'OPTIONS';
157
+ export type HttpMethod = 'GET' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'OPTIONS' | 'QUERY';
158
158
 
159
159
  export interface Logger {
160
160
  (msg: string): void;
@@ -79,6 +79,7 @@ const valid_server_exports = new Set([
79
79
  'DELETE',
80
80
  'OPTIONS',
81
81
  'HEAD',
82
+ 'QUERY',
82
83
  'fallback',
83
84
  'prerender',
84
85
  'trailingSlash',
@@ -63,30 +63,18 @@ export function copy(source, target, opts = {}) {
63
63
  /**
64
64
  * Get a list of all files in a directory
65
65
  * @param {string} cwd - the directory to walk
66
- * @param {boolean} [dirs] - whether to include directories in the result
67
- * @returns {string[]} a list of all found files (and possibly directories) relative to `cwd`
66
+ * @param {string} [dir] - the subdirectory to walk, relative to `cwd`
67
+ * @returns {Generator<string>} the posix paths of all found files, relative to `cwd`
68
68
  */
69
- export function walk(cwd, dirs = false) {
70
- /** @type {string[]} */
71
- const all_files = [];
72
-
73
- /** @param {string} dir */
74
- function walk_dir(dir) {
75
- const files = fs.readdirSync(path.join(cwd, dir));
76
-
77
- for (const file of files) {
78
- const joined = path.join(dir, file);
79
- const stats = fs.statSync(path.join(cwd, joined));
80
- if (stats.isDirectory()) {
81
- if (dirs) all_files.push(joined);
82
- walk_dir(joined);
83
- } else {
84
- all_files.push(joined);
85
- }
69
+ export function* walk(cwd, dir = '') {
70
+ for (const file of fs.readdirSync(path.join(cwd, dir))) {
71
+ const joined = dir ? `${dir}/${file}` : file;
72
+ if (fs.statSync(path.join(cwd, joined)).isDirectory()) {
73
+ yield* walk(cwd, joined);
74
+ } else {
75
+ yield joined;
86
76
  }
87
77
  }
88
-
89
- return (walk_dir(''), all_files);
90
78
  }
91
79
 
92
80
  /**
@@ -16,3 +16,13 @@ export function once(fn) {
16
16
  return (result = fn());
17
17
  };
18
18
  }
19
+
20
+ /**
21
+ * @param {string} name
22
+ * @param {string} [parens]
23
+ */
24
+ export function disallow_on_server(name, parens = '(...)') {
25
+ return () => {
26
+ throw new Error(`Cannot call \`${name}${parens}\` on the server`);
27
+ };
28
+ }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Replacement for `Promise.withResolvers()` that does not require the native
3
+ * static method, which only shipped in Safari 17.4 / Chrome 119 / Firefox 121.
4
+ *
5
+ * The client remote-function runtime is bundled and shipped to browsers verbatim
6
+ * (Vite 8's default build target is Safari 16.4 / Chrome 111) and is not
7
+ * polyfilled, so it must not assume `Promise.withResolvers` exists. The
8
+ * server-side and build-time call sites run on Node 22+ and keep using the
9
+ * native method.
10
+ *
11
+ * @template T
12
+ * @returns {PromiseWithResolvers<T>}
13
+ */
14
+ export function with_resolvers() {
15
+ let resolve;
16
+ let reject;
17
+
18
+ const promise = new Promise((res, rej) => {
19
+ resolve = res;
20
+ reject = rej;
21
+ });
22
+
23
+ // @ts-expect-error `resolve` and `reject` are assigned!
24
+ return { promise, resolve, reject };
25
+ }
@@ -116,17 +116,6 @@ export function parse_route_id(id) {
116
116
  return { pattern, params };
117
117
  }
118
118
 
119
- const optional_param_regex = /\/\[\[[\w-]+?(?:=[\w-]+)?\]\]/;
120
-
121
- /**
122
- * Removes optional params from a route ID.
123
- * @param {string} id
124
- * @returns The route id with optional params removed
125
- */
126
- export function remove_optional_params(id) {
127
- return id.replace(optional_param_regex, '');
128
- }
129
-
130
119
  /**
131
120
  * Returns `false` for `(group)` segments
132
121
  * @param {string} segment
package/src/utils/url.js CHANGED
@@ -82,17 +82,6 @@ export function decode_pathname(pathname) {
82
82
  return pathname.split('%25').map(decodeURI).join('%25');
83
83
  }
84
84
 
85
- /** @param {Record<string, string>} params */
86
- export function decode_params(params) {
87
- for (const key in params) {
88
- // input has already been decoded by decodeURI
89
- // now handle the rest
90
- params[key] = decodeURIComponent(params[key]);
91
- }
92
-
93
- return params;
94
- }
95
-
96
85
  /**
97
86
  * The error when a URL is malformed is not very helpful, so we augment it with the URI
98
87
  * @param {string} uri
package/src/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  // generated during release, do not modify
2
2
 
3
3
  /** @type {string} */
4
- export const VERSION = '3.0.0-next.22';
4
+ export const VERSION = '3.0.0-next.24';