@sveltejs/kit 1.0.0-next.332 → 1.0.0-next.335

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.
@@ -1242,7 +1242,7 @@ async function render_response({
1242
1242
  const init_app = `
1243
1243
  import { start } from ${s(options.prefix + options.manifest._.entry.file)};
1244
1244
  start({
1245
- target: document.querySelector('[data-hydrate="${target}"]').parentNode,
1245
+ target: document.querySelector('[data-sveltekit-hydrate="${target}"]').parentNode,
1246
1246
  paths: ${s(options.paths)},
1247
1247
  session: ${try_serialize($session, (error) => {
1248
1248
  throw new Error(`Failed to serialize session data: ${error.message}`);
@@ -1266,7 +1266,9 @@ async function render_response({
1266
1266
 
1267
1267
  const init_service_worker = `
1268
1268
  if ('serviceWorker' in navigator) {
1269
- navigator.serviceWorker.register('${options.service_worker}');
1269
+ addEventListener('load', () => {
1270
+ navigator.serviceWorker.register('${options.service_worker}');
1271
+ });
1270
1272
  }
1271
1273
  `;
1272
1274
 
@@ -1325,7 +1327,7 @@ async function render_response({
1325
1327
  .map((dep) => `\n\t<link rel="modulepreload" href="${options.prefix + dep}">`)
1326
1328
  .join('');
1327
1329
 
1328
- const attributes = ['type="module"', `data-hydrate="${target}"`];
1330
+ const attributes = ['type="module"', `data-sveltekit-hydrate="${target}"`];
1329
1331
 
1330
1332
  csp.add_script(init_app);
1331
1333
 
@@ -85,7 +85,7 @@ async function create_plugin(config, cwd) {
85
85
  if (!node) throw new Error(`Could not find node for ${url}`);
86
86
 
87
87
  const deps = new Set();
88
- find_deps(node, deps);
88
+ await find_deps(vite, node, deps);
89
89
 
90
90
  /** @type {Record<string, string>} */
91
91
  const styles = {};
@@ -399,16 +399,38 @@ function remove_html_middlewares(server) {
399
399
  }
400
400
 
401
401
  /**
402
+ * @param {import('vite').ViteDevServer} vite
402
403
  * @param {import('vite').ModuleNode} node
403
404
  * @param {Set<import('vite').ModuleNode>} deps
404
405
  */
405
- function find_deps(node, deps) {
406
- for (const dep of node.importedModules) {
407
- if (!deps.has(dep)) {
408
- deps.add(dep);
409
- find_deps(dep, deps);
406
+ function find_deps(vite, node, deps) {
407
+ // since `ssrTransformResult.deps` contains URLs instead of `ModuleNode`s, this process is asynchronous.
408
+ // instead of using `await`, we resolve all branches in parallel.
409
+ /** @type {Promise<void>[]} */
410
+ const branches = [];
411
+
412
+ /** @param {import('vite').ModuleNode} node */
413
+ function add(node) {
414
+ if (!deps.has(node)) {
415
+ deps.add(node);
416
+ branches.push(find_deps(vite, node, deps));
410
417
  }
411
418
  }
419
+
420
+ /** @param {string} url */
421
+ async function add_by_url(url) {
422
+ branches.push(vite.moduleGraph.getModuleByUrl(url).then((node) => node && add(node)));
423
+ }
424
+
425
+ if (node.ssrTransformResult) {
426
+ if (node.ssrTransformResult.deps) {
427
+ node.ssrTransformResult.deps.forEach(add_by_url);
428
+ }
429
+ } else {
430
+ node.importedModules.forEach(add);
431
+ }
432
+
433
+ return Promise.all(branches).then(() => {});
412
434
  }
413
435
 
414
436
  /**
@@ -439,9 +461,9 @@ async function dev({ cwd, port, host, https, config }) {
439
461
  path__default.resolve(cwd, 'node_modules'),
440
462
  path__default.resolve(vite.searchForWorkspaceRoot(cwd), 'node_modules')
441
463
  ])
442
- ],
443
- port: 3000
464
+ ]
444
465
  },
466
+ port: 3000,
445
467
  strictPort: true
446
468
  }
447
469
  },
package/dist/cli.js CHANGED
@@ -870,7 +870,7 @@ async function launch(port, https, base) {
870
870
  exec(`${cmd} ${https ? 'https' : 'http'}://localhost:${port}${base}`);
871
871
  }
872
872
 
873
- const prog = sade('svelte-kit').version('1.0.0-next.332');
873
+ const prog = sade('svelte-kit').version('1.0.0-next.335');
874
874
 
875
875
  prog
876
876
  .command('dev')
@@ -1049,7 +1049,7 @@ async function check_port(port) {
1049
1049
  function welcome({ port, host, https, open, base, loose, allow, cwd }) {
1050
1050
  if (open) launch(port, https, base);
1051
1051
 
1052
- console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.332'}\n`));
1052
+ console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.335'}\n`));
1053
1053
 
1054
1054
  const protocol = https ? 'https:' : 'http:';
1055
1055
  const exposed = typeof host !== 'undefined' && host !== 'localhost' && host !== '127.0.0.1';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/kit",
3
- "version": "1.0.0-next.332",
3
+ "version": "1.0.0-next.335",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/sveltejs/kit",
@@ -15,7 +15,15 @@
15
15
  * }
16
16
  * ```
17
17
  *
18
- * By populating these interfaces, you will gain type safety when using `event.locals`, `event.platform`, `session` and `stuff`:
18
+ * By populating these interfaces, you will gain type safety when using `event.locals`, `event.platform`, `session` and `stuff`.
19
+ *
20
+ * Note that since it's an ambient declaration file, you can't use `import` statements — instead, use the `import(...)` function:
21
+ *
22
+ * ```ts
23
+ * interface Locals {
24
+ * user: import('$lib/types').User;
25
+ * }
26
+ * ```
19
27
  */
20
28
  declare namespace App {
21
29
  /**