@sveltejs/kit 1.0.0-next.185 → 1.0.0-next.189

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.
@@ -47,9 +47,7 @@ async function prefetchRoutes_(pathnames) {
47
47
  ? router.routes.filter((route) => pathnames.some((pathname) => route[0].test(pathname)))
48
48
  : router.routes;
49
49
 
50
- const promises = matching
51
- .filter(/** @returns {r is import('types/internal').CSRPage} */ (r) => r && r.length > 1)
52
- .map((r) => Promise.all(r[1].map((load) => load())));
50
+ const promises = matching.map((r) => Promise.all(r[1].map((load) => load())));
53
51
 
54
52
  await Promise.all(promises);
55
53
  }
@@ -44,6 +44,8 @@ class Router {
44
44
  this.base = base;
45
45
  this.routes = routes;
46
46
  this.trailing_slash = trailing_slash;
47
+ /** Keeps tracks of multiple navigations caused by redirects during rendering */
48
+ this.navigating = 0;
47
49
 
48
50
  /** @type {import('./renderer').Renderer} */
49
51
  this.renderer = renderer;
@@ -258,6 +260,11 @@ class Router {
258
260
  throw new Error('Attempted to navigate to a URL that does not belong to this app');
259
261
  }
260
262
 
263
+ if (!this.navigating) {
264
+ dispatchEvent(new CustomEvent('sveltekit:navigation-start'));
265
+ }
266
+ this.navigating++;
267
+
261
268
  // remove trailing slashes
262
269
  if (info.path !== '/') {
263
270
  const has_trailing_slash = info.path.endsWith('/');
@@ -274,12 +281,12 @@ class Router {
274
281
  }
275
282
  }
276
283
 
277
- this.renderer.notify({
278
- path: info.path,
279
- query: info.query
280
- });
284
+ await this.renderer.handle_navigation(info, chain, false, { hash, scroll, keepfocus });
281
285
 
282
- await this.renderer.update(info, chain, false, { hash, scroll, keepfocus });
286
+ this.navigating--;
287
+ if (!this.navigating) {
288
+ dispatchEvent(new CustomEvent('sveltekit:navigation-end'));
289
+ }
283
290
  }
284
291
  }
285
292
 
@@ -577,10 +584,13 @@ class Renderer {
577
584
  this._init(result);
578
585
  }
579
586
 
580
- /** @param {{ path: string, query: URLSearchParams }} destination */
581
- notify({ path, query }) {
582
- dispatchEvent(new CustomEvent('sveltekit:navigation-start'));
583
-
587
+ /**
588
+ * @param {import('./types').NavigationInfo} info
589
+ * @param {string[]} chain
590
+ * @param {boolean} no_cache
591
+ * @param {{hash?: string, scroll: { x: number, y: number } | null, keepfocus: boolean}} [opts]
592
+ */
593
+ async handle_navigation(info, chain, no_cache, opts) {
584
594
  if (this.started) {
585
595
  this.stores.navigating.set({
586
596
  from: {
@@ -588,11 +598,13 @@ class Renderer {
588
598
  query: this.current.page.query
589
599
  },
590
600
  to: {
591
- path,
592
- query
601
+ path: info.path,
602
+ query: info.query
593
603
  }
594
604
  });
595
605
  }
606
+
607
+ await this.update(info, chain, no_cache, opts);
596
608
  }
597
609
 
598
610
  /**
@@ -664,11 +676,12 @@ class Renderer {
664
676
  }
665
677
 
666
678
  await 0;
667
- dispatchEvent(new CustomEvent('sveltekit:navigation-end'));
679
+
668
680
  this.loading.promise = null;
669
681
  this.loading.id = null;
670
682
 
671
683
  if (!this.router) return;
684
+
672
685
  const leaf_node = navigation_result.state.branch[navigation_result.state.branch.length - 1];
673
686
  if (leaf_node && leaf_node.module.router === false) {
674
687
  this.router.disable();
@@ -736,21 +749,13 @@ class Renderer {
736
749
  for (let i = 0; i < info.routes.length; i += 1) {
737
750
  const route = info.routes[i];
738
751
 
739
- // check if endpoint route
740
- if (route.length === 1) {
741
- return { reload: true, props: {}, state: this.current };
742
- }
743
-
744
752
  // load code for subsequent routes immediately, if they are as
745
753
  // likely to match the current path/query as the current one
746
754
  let j = i + 1;
747
755
  while (j < info.routes.length) {
748
756
  const next = info.routes[j];
749
757
  if (next[0].toString() === route[0].toString()) {
750
- // if it's a page route
751
- if (next.length !== 1) {
752
- next[1].forEach((loader) => loader());
753
- }
758
+ next[1].forEach((loader) => loader());
754
759
  j += 1;
755
760
  } else {
756
761
  break;
@@ -1128,7 +1133,7 @@ class Renderer {
1128
1133
  }
1129
1134
  }
1130
1135
 
1131
- // @ts-expect-error - value will be replaced on build step
1136
+ // @ts-expect-error - doesn't exist yet. generated by Rollup
1132
1137
 
1133
1138
  /**
1134
1139
  * @param {{
@@ -4295,7 +4295,7 @@ class Watcher extends EventEmitter {
4295
4295
  });
4296
4296
 
4297
4297
  /** @type {[any, string[]]} */
4298
- let [merged_config, conflicts] = deep_merge(modified_vite_config, {
4298
+ const [merged_config, conflicts] = deep_merge(modified_vite_config, {
4299
4299
  configFile: false,
4300
4300
  root: this.cwd,
4301
4301
  resolve: {
@@ -4329,13 +4329,17 @@ class Watcher extends EventEmitter {
4329
4329
 
4330
4330
  // optional config from command-line flags
4331
4331
  // these should take precedence, but not print conflict warnings
4332
- [merged_config] = deep_merge(merged_config, {
4333
- server: {
4334
- host: this.host,
4335
- https: this.https,
4336
- port: this.port
4337
- }
4338
- });
4332
+ if (this.host) {
4333
+ merged_config.server.host = this.host;
4334
+ }
4335
+ // https is already enabled then do nothing. it could be an object and we
4336
+ // don't want to overwrite with a boolean
4337
+ if (this.https && !merged_config.server.https) {
4338
+ merged_config.server.https = this.https;
4339
+ }
4340
+ if (this.port) {
4341
+ merged_config.server.port = this.port;
4342
+ }
4339
4343
 
4340
4344
  this.vite = await vite.createServer(merged_config);
4341
4345
  remove_html_middlewares(this.vite.middlewares);
@@ -171,8 +171,6 @@ function generate_client_manifest(manifest_data, base) {
171
171
  if (params) tuple.push(params);
172
172
 
173
173
  return `// ${route.a[route.a.length - 1]}\n\t\t[${tuple.join(', ')}]`;
174
- } else {
175
- return `// ${route.file}\n\t\t[${route.pattern}]`;
176
174
  }
177
175
  })
178
176
  .join(',\n\n\t\t')}
package/dist/cli.js CHANGED
@@ -817,7 +817,7 @@ async function launch(port, https) {
817
817
  exec(`${cmd} ${https ? 'https' : 'http'}://localhost:${port}`);
818
818
  }
819
819
 
820
- const prog = sade('svelte-kit').version('1.0.0-next.185');
820
+ const prog = sade('svelte-kit').version('1.0.0-next.189');
821
821
 
822
822
  prog
823
823
  .command('dev')
@@ -847,11 +847,14 @@ prog
847
847
  throw Error('Could not find server');
848
848
  }
849
849
  // we never start the server on a socket path, so address will be of type AddressInfo
850
- const chosen_port = /** @type {import('net').AddressInfo} */ (
850
+ const address_info = /** @type {import('net').AddressInfo} */ (
851
851
  watcher.vite.httpServer.address()
852
- ).port;
852
+ );
853
+
854
+ https = https || !!config.kit.vite().server?.https;
855
+ open = open || !!config.kit.vite().server?.open;
853
856
 
854
- welcome({ port: chosen_port, host, https, open });
857
+ welcome({ port: address_info.port, host: address_info.address, https, open });
855
858
  } catch (error) {
856
859
  handle_error(error);
857
860
  }
@@ -966,7 +969,7 @@ async function check_port(port) {
966
969
  function welcome({ port, host, https, open }) {
967
970
  if (open) launch(port, https);
968
971
 
969
- console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.185'}\n`));
972
+ console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.189'}\n`));
970
973
 
971
974
  const protocol = https ? 'https:' : 'http:';
972
975
  const exposed = typeof host !== 'undefined' && host !== 'localhost' && host !== '127.0.0.1';
package/dist/ssr.js CHANGED
@@ -876,7 +876,10 @@ async function load_node({
876
876
 
877
877
  // handle fetch requests for static assets. e.g. prebaked data, etc.
878
878
  // we need to support everything the browser's fetch supports
879
- const filename = resolved.replace(options.paths.assets, '').slice(1);
879
+ const prefix = options.paths.assets || options.paths.base;
880
+ const filename = (
881
+ resolved.startsWith(prefix) ? resolved.slice(prefix.length) : resolved
882
+ ).slice(1);
880
883
  const filename_html = `${filename}/index.html`; // path may also match path/index.html
881
884
  const asset = options.manifest.assets.find(
882
885
  (d) => d.file === filename || d.file === filename_html
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/kit",
3
- "version": "1.0.0-next.185",
3
+ "version": "1.0.0-next.189",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/sveltejs/kit",
@@ -12,7 +12,7 @@
12
12
  "@sveltejs/vite-plugin-svelte": "^1.0.0-next.30",
13
13
  "cheap-watch": "^1.0.4",
14
14
  "sade": "^1.7.4",
15
- "vite": "^2.6.7"
15
+ "vite": "^2.6.10"
16
16
  },
17
17
  "devDependencies": {
18
18
  "@rollup/plugin-replace": "^3.0.0",
@@ -103,11 +103,7 @@ export interface SSREndpoint {
103
103
 
104
104
  export type SSRRoute = SSREndpoint | SSRPage;
105
105
 
106
- export type CSRPage = [RegExp, CSRComponentLoader[], CSRComponentLoader[], GetParams?];
107
-
108
- export type CSREndpoint = [RegExp];
109
-
110
- export type CSRRoute = CSREndpoint | CSRPage;
106
+ export type CSRRoute = [RegExp, CSRComponentLoader[], CSRComponentLoader[], GetParams?];
111
107
 
112
108
  export interface SSRManifest {
113
109
  assets: Asset[];