@sveltejs/kit 2.43.7 → 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.7",
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
@@ -697,7 +714,8 @@ async function kit({ svelte_config }) {
697
714
  },
698
715
 
699
716
  async transform(code, id, opts) {
700
- 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}`))) {
701
719
  return;
702
720
  }
703
721
 
@@ -770,8 +788,14 @@ async function kit({ svelte_config }) {
770
788
  return `export const ${name} = ${namespace}.${type}('${remote.hash}/${name}');`;
771
789
  });
772
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
+
773
797
  return {
774
- code: `import * as ${namespace} from '__sveltekit/remote';\n\n${exports.join('\n')}\n`
798
+ code: result
775
799
  };
776
800
  },
777
801
 
@@ -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.7';
4
+ export const VERSION = '2.43.8';