@sveltejs/kit 2.43.6 → 2.43.8

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/kit",
3
- "version": "2.43.6",
3
+ "version": "2.43.8",
4
4
  "description": "SvelteKit is the fastest way to build Svelte apps",
5
5
  "keywords": [
6
6
  "framework",
@@ -234,7 +234,7 @@ export async function dev(vite, vite_config, svelte_config, get_remotes) {
234
234
  // in dev we inline all styles to avoid FOUC. this gets populated lazily so that
235
235
  // components/stylesheets loaded via import() during `load` are included
236
236
  result.inline_styles = async () => {
237
- /** @type {Set<import('vite').ModuleNode>} */
237
+ /** @type {Set<import('vite').ModuleNode | import('vite').EnvironmentModuleNode>} */
238
238
  const deps = new Set();
239
239
 
240
240
  for (const module_node of module_nodes) {
@@ -610,8 +610,8 @@ function remove_static_middlewares(server) {
610
610
 
611
611
  /**
612
612
  * @param {import('vite').ViteDevServer} vite
613
- * @param {import('vite').ModuleNode} node
614
- * @param {Set<import('vite').ModuleNode>} deps
613
+ * @param {import('vite').ModuleNode | import('vite').EnvironmentModuleNode} node
614
+ * @param {Set<import('vite').ModuleNode | import('vite').EnvironmentModuleNode>} deps
615
615
  */
616
616
  async function find_deps(vite, node, deps) {
617
617
  // since `ssrTransformResult.deps` contains URLs instead of `ModuleNode`s, this process is asynchronous.
@@ -619,7 +619,7 @@ async function find_deps(vite, node, deps) {
619
619
  /** @type {Promise<void>[]} */
620
620
  const branches = [];
621
621
 
622
- /** @param {import('vite').ModuleNode} node */
622
+ /** @param {import('vite').ModuleNode | import('vite').EnvironmentModuleNode} node */
623
623
  async function add(node) {
624
624
  if (!deps.has(node)) {
625
625
  deps.add(node);
@@ -629,20 +629,23 @@ async function find_deps(vite, node, deps) {
629
629
 
630
630
  /** @param {string} url */
631
631
  async function add_by_url(url) {
632
- const node = await vite.moduleGraph.getModuleByUrl(url);
632
+ const node = await get_server_module_by_url(vite, url);
633
633
 
634
634
  if (node) {
635
635
  await add(node);
636
636
  }
637
637
  }
638
638
 
639
- if (node.ssrTransformResult) {
640
- if (node.ssrTransformResult.deps) {
641
- node.ssrTransformResult.deps.forEach((url) => branches.push(add_by_url(url)));
639
+ const transform_result =
640
+ /** @type {import('vite').ModuleNode} */ (node).ssrTransformResult || node.transformResult;
641
+
642
+ if (transform_result) {
643
+ if (transform_result.deps) {
644
+ transform_result.deps.forEach((url) => branches.push(add_by_url(url)));
642
645
  }
643
646
 
644
- if (node.ssrTransformResult.dynamicDeps) {
645
- node.ssrTransformResult.dynamicDeps.forEach((url) => branches.push(add_by_url(url)));
647
+ if (transform_result.dynamicDeps) {
648
+ transform_result.dynamicDeps.forEach((url) => branches.push(add_by_url(url)));
646
649
  }
647
650
  } else {
648
651
  node.importedModules.forEach((node) => branches.push(add(node)));
@@ -651,6 +654,16 @@ async function find_deps(vite, node, deps) {
651
654
  await Promise.all(branches);
652
655
  }
653
656
 
657
+ /**
658
+ * @param {import('vite').ViteDevServer} vite
659
+ * @param {string} url
660
+ */
661
+ function get_server_module_by_url(vite, url) {
662
+ return vite.environments
663
+ ? vite.environments.ssr.moduleGraph.getModuleByUrl(url)
664
+ : vite.moduleGraph.getModuleByUrl(url, true);
665
+ }
666
+
654
667
  /**
655
668
  * Determine if a file is being requested with the correct case,
656
669
  * to ensure consistent behaviour between dev and prod and across
@@ -298,6 +298,23 @@ async function kit({ svelte_config }) {
298
298
  `${kit.files.routes}/**/+*.{svelte,js,ts}`,
299
299
  `!${kit.files.routes}/**/+*server.*`
300
300
  ],
301
+ esbuildOptions: {
302
+ plugins: [
303
+ {
304
+ name: 'vite-plugin-sveltekit-setup:optimize',
305
+ setup(build) {
306
+ if (!kit.experimental.remoteFunctions) return;
307
+
308
+ const filter = new RegExp(
309
+ `.remote(${kit.moduleExtensions.join('|')})$`.replaceAll('.', '\\.')
310
+ );
311
+
312
+ // treat .remote.js files as empty for the purposes of prebundling
313
+ build.onLoad({ filter }, () => ({ contents: '' }));
314
+ }
315
+ }
316
+ ]
317
+ },
301
318
  exclude: [
302
319
  // Without this SvelteKit will be prebundled on the client, which means we end up with two versions of Redirect etc.
303
320
  // Also see https://github.com/sveltejs/kit/issues/5952#issuecomment-1218844057
@@ -618,10 +635,27 @@ async function kit({ svelte_config }) {
618
635
  /** @type {Array<{ hash: string, file: string }>} */
619
636
  const remotes = [];
620
637
 
638
+ /**
639
+ * A set of modules that imported by `.remote.ts` modules. By forcing these modules
640
+ * into their own chunks, we ensure that each chunk created for a `.remote.ts`
641
+ * module _only_ contains that module, hopefully avoiding any circular
642
+ * dependency woes that arise from treating chunks as entries
643
+ */
644
+ const imported_by_remotes = new Set();
645
+ let uid = 1;
646
+
621
647
  /** @type {import('vite').Plugin} */
622
648
  const plugin_remote = {
623
649
  name: 'vite-plugin-sveltekit-remote',
624
650
 
651
+ moduleParsed(info) {
652
+ if (svelte_config.kit.moduleExtensions.some((ext) => info.id.endsWith(`.remote${ext}`))) {
653
+ for (const id of info.importedIds) {
654
+ imported_by_remotes.add(id);
655
+ }
656
+ }
657
+ },
658
+
625
659
  config(config) {
626
660
  if (!config.build?.ssr) {
627
661
  // only set manualChunks for the SSR build
@@ -644,14 +678,6 @@ async function kit({ svelte_config }) {
644
678
  config.build.rollupOptions.output = {
645
679
  ...config.build.rollupOptions.output,
646
680
  manualChunks(id, meta) {
647
- // Prevent core runtime and env from ending up in a remote chunk, which could break because of initialization order
648
- if (id === `${runtime_directory}/app/server/index.js`) {
649
- return 'app-server';
650
- }
651
- if (id === `${runtime_directory}/shared-server.js`) {
652
- return 'app-shared-server';
653
- }
654
-
655
681
  // Check if this is a *.remote.ts file
656
682
  if (svelte_config.kit.moduleExtensions.some((ext) => id.endsWith(`.remote${ext}`))) {
657
683
  const relative = posixify(path.relative(cwd, id));
@@ -659,6 +685,10 @@ async function kit({ svelte_config }) {
659
685
  return `remote-${hash(relative)}`;
660
686
  }
661
687
 
688
+ if (imported_by_remotes.has(id)) {
689
+ return `chunk-${uid++}`;
690
+ }
691
+
662
692
  // If there was an existing manualChunks function, call it
663
693
  if (typeof manualChunks === 'function') {
664
694
  return manualChunks(id, meta);
@@ -684,7 +714,8 @@ async function kit({ svelte_config }) {
684
714
  },
685
715
 
686
716
  async transform(code, id, opts) {
687
- if (!svelte_config.kit.moduleExtensions.some((ext) => id.endsWith(`.remote${ext}`))) {
717
+ const normalized = normalize_id(id, normalized_lib, normalized_cwd);
718
+ if (!svelte_config.kit.moduleExtensions.some((ext) => normalized.endsWith(`.remote${ext}`))) {
688
719
  return;
689
720
  }
690
721
 
@@ -757,8 +788,14 @@ async function kit({ svelte_config }) {
757
788
  return `export const ${name} = ${namespace}.${type}('${remote.hash}/${name}');`;
758
789
  });
759
790
 
791
+ let result = `import * as ${namespace} from '__sveltekit/remote';\n\n${exports.join('\n')}\n`;
792
+
793
+ if (dev_server) {
794
+ result += `\nimport.meta.hot?.accept();\n`;
795
+ }
796
+
760
797
  return {
761
- code: `import * as ${namespace} from '__sveltekit/remote';\n\n${exports.join('\n')}\n`
798
+ code: result
762
799
  };
763
800
  },
764
801
 
@@ -13,7 +13,7 @@ import { convert_formdata, flatten_issues } from '../../../utils.js';
13
13
  *
14
14
  * @template Output
15
15
  * @overload
16
- * @param {() => Output} fn
16
+ * @param {() => MaybePromise<Output>} fn
17
17
  * @returns {RemoteForm<void, Output>}
18
18
  * @since 2.27
19
19
  */
@@ -1,17 +1,28 @@
1
1
  /** @import { RemoteQueryFunction } from '@sveltejs/kit' */
2
2
  /** @import { RemoteFunctionResponse } from 'types' */
3
3
  import { app_dir, base } from '$app/paths/internal/client';
4
- import { app, goto, remote_responses } from '../client.js';
4
+ import { app, goto, query_map, remote_responses } from '../client.js';
5
5
  import { tick } from 'svelte';
6
6
  import { create_remote_function, remote_request } from './shared.svelte.js';
7
7
  import * as devalue from 'devalue';
8
8
  import { HttpError, Redirect } from '@sveltejs/kit/internal';
9
+ import { DEV } from 'esm-env';
9
10
 
10
11
  /**
11
12
  * @param {string} id
12
13
  * @returns {RemoteQueryFunction<any, any>}
13
14
  */
14
15
  export function query(id) {
16
+ if (DEV) {
17
+ // If this reruns as part of HMR, refresh the query
18
+ for (const [key, entry] of query_map) {
19
+ if (key === id || key.startsWith(id + '/')) {
20
+ // use optional chaining in case a prerender function was turned into a query
21
+ entry.resource.refresh?.();
22
+ }
23
+ }
24
+ }
25
+
15
26
  return create_remote_function(id, (cache_key, payload) => {
16
27
  return new Query(cache_key, async () => {
17
28
  if (Object.hasOwn(remote_responses, cache_key)) {
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 = '2.43.6';
4
+ export const VERSION = '2.43.8';
package/types/index.d.ts CHANGED
@@ -3061,7 +3061,7 @@ declare module '$app/server' {
3061
3061
  *
3062
3062
  * @since 2.27
3063
3063
  */
3064
- export function form<Output>(fn: () => Output): RemoteForm<void, Output>;
3064
+ export function form<Output>(fn: () => MaybePromise<Output>): RemoteForm<void, Output>;
3065
3065
  /**
3066
3066
  * Creates a form object that can be spread onto a `<form>` element.
3067
3067
  *