@sveltejs/kit 2.63.1 → 2.65.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.
Files changed (33) hide show
  1. package/package.json +2 -2
  2. package/src/core/postbuild/analyse.js +0 -5
  3. package/src/core/postbuild/prerender.js +2 -0
  4. package/src/exports/public.d.ts +1 -1
  5. package/src/exports/vite/build/build_server.js +47 -57
  6. package/src/exports/vite/build/utils.js +0 -8
  7. package/src/exports/vite/index.js +226 -178
  8. package/src/runtime/app/server/remote/command.js +0 -3
  9. package/src/runtime/app/server/remote/form.js +18 -13
  10. package/src/runtime/app/server/remote/prerender.js +28 -34
  11. package/src/runtime/app/server/remote/query.js +105 -94
  12. package/src/runtime/app/server/remote/requested.js +14 -10
  13. package/src/runtime/app/server/remote/shared.js +25 -18
  14. package/src/runtime/client/client.js +19 -13
  15. package/src/runtime/client/remote-functions/command.svelte.js +7 -32
  16. package/src/runtime/client/remote-functions/form.svelte.js +62 -82
  17. package/src/runtime/client/remote-functions/prerender.svelte.js +14 -6
  18. package/src/runtime/client/remote-functions/query/index.js +6 -14
  19. package/src/runtime/client/remote-functions/query/instance.svelte.js +20 -0
  20. package/src/runtime/client/remote-functions/query/proxy.js +3 -3
  21. package/src/runtime/client/remote-functions/query-batch.svelte.js +59 -68
  22. package/src/runtime/client/remote-functions/query-live/instance.svelte.js +20 -6
  23. package/src/runtime/client/remote-functions/shared.svelte.js +76 -59
  24. package/src/runtime/server/page/render.js +20 -80
  25. package/src/runtime/server/page/server_routing.js +20 -15
  26. package/src/runtime/server/remote.js +296 -204
  27. package/src/runtime/server/respond.js +4 -2
  28. package/src/runtime/shared.js +83 -28
  29. package/src/types/global-private.d.ts +3 -3
  30. package/src/types/internal.d.ts +53 -34
  31. package/src/version.js +1 -1
  32. package/types/index.d.ts +4 -4
  33. package/types/index.d.ts.map +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/kit",
3
- "version": "2.63.1",
3
+ "version": "2.65.0",
4
4
  "description": "SvelteKit is the fastest way to build Svelte apps",
5
5
  "keywords": [
6
6
  "framework",
@@ -41,7 +41,7 @@
41
41
  "dts-buddy": "^0.8.0",
42
42
  "jsdom": "^26.1.0",
43
43
  "rollup": "^4.59.0",
44
- "svelte": "^5.55.7",
44
+ "svelte": "^5.56.3",
45
45
  "typescript": "^5.3.3",
46
46
  "vite": "^6.4.2",
47
47
  "vitest": "^4.1.7"
@@ -11,7 +11,6 @@ import { has_server_load, resolve_route } from '../../utils/routing.js';
11
11
  import { check_feature } from '../../utils/features.js';
12
12
  import { createReadableStream } from '@sveltejs/kit/node';
13
13
  import { PageNodes } from '../../utils/page_nodes.js';
14
- import { build_server_nodes } from '../../exports/vite/build/build_server.js';
15
14
 
16
15
  export default forked(import.meta.url, analyse);
17
16
 
@@ -34,7 +33,6 @@ async function analyse({
34
33
  server_manifest,
35
34
  tracked_features,
36
35
  env,
37
- out,
38
36
  remotes
39
37
  }) {
40
38
  /** @type {import('@sveltejs/kit').SSRManifest} */
@@ -64,9 +62,6 @@ async function analyse({
64
62
  internal.set_manifest(manifest);
65
63
  internal.set_read_implementation((file) => createReadableStream(`${server_root}/server/${file}`));
66
64
 
67
- // first, build server nodes without the client manifest so we can analyse it
68
- build_server_nodes(out, config, manifest_data, server_manifest, null, null, null);
69
-
70
65
  /** @type {import('types').ServerMetadata} */
71
66
  const metadata = {
72
67
  nodes: [],
@@ -204,6 +204,8 @@ async function prerender({ hash, out, manifest_path, metadata, verbose, env }) {
204
204
 
205
205
  const seen = new Set();
206
206
  const written = new Set();
207
+
208
+ /** @type {Map<string, Promise<any>>} */
207
209
  const remote_responses = new Map();
208
210
 
209
211
  /** @type {Map<string, Set<string>>} */
@@ -1696,7 +1696,7 @@ export interface SSRManifest {
1696
1696
 
1697
1697
  /** private fields */
1698
1698
  _: {
1699
- client: NonNullable<BuildData['client']>;
1699
+ client: BuildData['client'];
1700
1700
  nodes: SSRNodeLoader[];
1701
1701
  /** hashed filename -> import to that file */
1702
1702
  remotes: Record<string, () => Promise<any>>;
@@ -15,36 +15,14 @@ import { basename } from 'node:path';
15
15
  import { fix_css_urls } from '../../../utils/css.js';
16
16
  import { escape_for_interpolation } from '../../../utils/escape.js';
17
17
 
18
- /**
19
- * @overload Build without the client manifest so we can analyse the nodes.
20
- * @param {string} out
21
- * @param {ValidatedKitConfig} kit
22
- * @param {ManifestData} manifest_data
23
- * @param {Manifest} server_manifest
24
- * @param {null} client_manifest
25
- * @param {null} assets_path
26
- * @param {null} client_chunks
27
- * @returns {void}
28
- */
29
- /**
30
- * @overload Or build with the client manifest
31
- * @param {string} out
32
- * @param {ValidatedKitConfig} kit
33
- * @param {ManifestData} manifest_data
34
- * @param {Manifest} server_manifest
35
- * @param {Manifest} client_manifest
36
- * @param {string} assets_path
37
- * @param {Rollup.RollupOutput['output']} client_chunks
38
- * @returns {void}
39
- */
40
18
  /**
41
19
  * @param {string} out
42
20
  * @param {ValidatedKitConfig} kit
43
21
  * @param {ManifestData} manifest_data
44
22
  * @param {Manifest} server_manifest
45
23
  * @param {Manifest | null} client_manifest
46
- * @param {string | null} assets_path
47
- * @param {Rollup.RollupOutput['output'] | null} client_chunks
24
+ * @param {string} assets_path
25
+ * @param {(Rollup.OutputAsset | Rollup.OutputChunk)[]} chunks
48
26
  * @returns {void}
49
27
  */
50
28
  export function build_server_nodes(
@@ -54,7 +32,7 @@ export function build_server_nodes(
54
32
  server_manifest,
55
33
  client_manifest,
56
34
  assets_path,
57
- client_chunks
35
+ chunks
58
36
  ) {
59
37
  mkdirp(`${out}/server/nodes`);
60
38
  mkdirp(`${out}/server/stylesheets`);
@@ -72,8 +50,8 @@ export function build_server_nodes(
72
50
  */
73
51
  let prepare_css_for_inlining = (css) => s(css);
74
52
 
75
- if (client_chunks && kit.inlineStyleThreshold > 0 && kit.output.bundleStrategy === 'split') {
76
- for (const chunk of client_chunks) {
53
+ if (chunks && kit.inlineStyleThreshold > 0 && kit.output.bundleStrategy === 'split') {
54
+ for (const chunk of chunks) {
77
55
  if (chunk.type !== 'asset' || !chunk.fileName.endsWith('.css')) {
78
56
  continue;
79
57
  }
@@ -129,6 +107,9 @@ export function build_server_nodes(
129
107
  }
130
108
  }
131
109
 
110
+ /** path to the `.svelte-kit` directory */
111
+ const out_dir = normalizePath(kit.outDir);
112
+
132
113
  for (let i = 0; i < manifest_data.nodes.length; i++) {
133
114
  const node = manifest_data.nodes[i];
134
115
 
@@ -152,7 +133,11 @@ export function build_server_nodes(
152
133
  /** @type {Set<string>} */
153
134
  const eager_assets = new Set();
154
135
 
155
- if (node.component && client_manifest) {
136
+ const uses_server_component = node.child_pages
137
+ ? node.child_pages.some((child) => child.page_options?.ssr !== false)
138
+ : node.page_options?.ssr !== false;
139
+
140
+ if (node.component && uses_server_component) {
156
141
  exports.push(
157
142
  'let component_cache;',
158
143
  `export const component = async () => component_cache ??= (await import('../${
@@ -182,18 +167,7 @@ export function build_server_nodes(
182
167
  exports.push(`export const server_id = ${s(node.server)};`);
183
168
  }
184
169
 
185
- if (
186
- client_manifest &&
187
- (node.universal || node.component) &&
188
- kit.output.bundleStrategy === 'split'
189
- ) {
190
- const entry_path = `${normalizePath(kit.outDir)}/generated/client-optimized/nodes/${i}.js`;
191
- const entry = find_deps(client_manifest, entry_path, true);
192
-
193
- // Eagerly load client stylesheets and fonts imported by the SSR-ed page to avoid FOUC.
194
- // However, if it is not used during SSR (not present in the server manifest),
195
- // then it can be lazily loaded in the browser.
196
-
170
+ if ((node.universal || node.component) && kit.output.bundleStrategy === 'split') {
197
171
  /** @type {AssetDependencies | undefined} */
198
172
  let component;
199
173
  if (node.component) {
@@ -206,25 +180,41 @@ export function build_server_nodes(
206
180
  universal = find_deps(server_manifest, node.universal, true);
207
181
  }
208
182
 
209
- /** @type {Set<string>} */
210
- const eager_css = new Set();
183
+ if (client_manifest) {
184
+ const entry_path = `${out_dir}/generated/client-optimized/nodes/${i}.js`;
185
+ const entry = find_deps(client_manifest, entry_path, true);
211
186
 
212
- entry.stylesheet_map.forEach((value, filepath) => {
213
- // pages and layouts are renamed to node indexes when optimised for the client
214
- // so we use the original filename instead to check against the server manifest
215
- if (filepath === entry_path) {
216
- filepath = node.component ?? filepath;
217
- }
187
+ // Eagerly load client stylesheets and fonts imported by the SSR-ed page to avoid FOUC.
188
+ // However, if it is not used during SSR (not present in the server manifest),
189
+ // then it can be lazily loaded in the browser.
218
190
 
219
- if (component?.stylesheet_map.has(filepath) || universal?.stylesheet_map.has(filepath)) {
220
- value.css.forEach((file) => eager_css.add(file));
221
- value.assets.forEach((file) => eager_assets.add(file));
222
- }
223
- });
191
+ /** @type {Set<string>} */
192
+ const eager_css = new Set();
193
+
194
+ entry.stylesheet_map.forEach((value, filepath) => {
195
+ // pages and layouts are renamed to node indexes when optimised for the client
196
+ // so we use the original filename instead to check against the server manifest
197
+ if (filepath === entry_path) {
198
+ filepath = node.component ?? filepath;
199
+ }
200
+
201
+ if (component?.stylesheet_map.has(filepath) || universal?.stylesheet_map.has(filepath)) {
202
+ value.css.forEach((file) => eager_css.add(file));
203
+ value.assets.forEach((file) => eager_assets.add(file));
204
+ }
205
+ });
224
206
 
225
- imported = entry.imports;
226
- stylesheets = Array.from(eager_css);
227
- fonts = filter_fonts(Array.from(eager_assets));
207
+ imported = entry.imports;
208
+ stylesheets = Array.from(eager_css);
209
+ fonts = filter_fonts(Array.from(eager_assets));
210
+ } else {
211
+ for (const entry of [component, universal]) {
212
+ if (!entry) continue;
213
+ imported.push(...entry.imports);
214
+ stylesheets.push(...entry.stylesheets);
215
+ fonts.push(...entry.fonts);
216
+ }
217
+ }
228
218
  }
229
219
 
230
220
  exports.push(
@@ -241,7 +231,7 @@ export function build_server_nodes(
241
231
 
242
232
  // Keep track of Vite asset filenames so that we avoid touching unrelated ones
243
233
  // when adjusting the inlined CSS
244
- if (stylesheets_to_inline.size && assets_path && eager_assets.size) {
234
+ if (stylesheets_to_inline.size && eager_assets.size) {
245
235
  vite_assets = new Set(
246
236
  Array.from(eager_assets).map((asset) => {
247
237
  return decodeURIComponent(asset.replace(`${assets_path}/`, ''));
@@ -122,14 +122,6 @@ export function filter_fonts(assets) {
122
122
  return assets.filter((asset) => /\.(woff2?|ttf|otf)$/.test(asset));
123
123
  }
124
124
 
125
- /**
126
- * @param {import('types').ValidatedKitConfig} config
127
- * @returns {string}
128
- */
129
- export function assets_base(config) {
130
- return (config.paths.assets || config.paths.base || '.') + '/';
131
- }
132
-
133
125
  /**
134
126
  * Writes a function with arguments used by a template literal.
135
127
  * This helps us store strings in a module and inject values at runtime.