@sveltejs/kit 1.0.0-next.276 → 1.0.0-next.277

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.
@@ -45,8 +45,8 @@ async function invalidate_(resource) {
45
45
  /**
46
46
  * @type {import('$app/navigation').prefetch}
47
47
  */
48
- function prefetch_(href) {
49
- return router.prefetch(new URL(href, get_base_uri(document)));
48
+ async function prefetch_(href) {
49
+ await router.prefetch(new URL(href, get_base_uri(document)));
50
50
  }
51
51
 
52
52
  /**
@@ -86,6 +86,7 @@ class Router {
86
86
  renderer.router = this;
87
87
 
88
88
  this.enabled = true;
89
+ this.initialized = false;
89
90
 
90
91
  // make it possible to reset focus
91
92
  document.body.setAttribute('tabindex', '-1');
@@ -223,11 +224,8 @@ class Router {
223
224
  this.hash_navigating = true;
224
225
 
225
226
  this.#update_scroll_positions();
227
+ this.renderer.update_page_store(new URL(url.href));
226
228
 
227
- const info = this.parse(url);
228
- if (info) {
229
- return this.renderer.update(info, [], false);
230
- }
231
229
  return;
232
230
  }
233
231
 
@@ -280,6 +278,8 @@ class Router {
280
278
  );
281
279
  }
282
280
  });
281
+
282
+ this.initialized = true;
283
283
  }
284
284
 
285
285
  #update_scroll_positions() {
@@ -306,7 +306,8 @@ class Router {
306
306
  id: url.pathname + url.search,
307
307
  routes: this.routes.filter(([pattern]) => pattern.test(path)),
308
308
  url,
309
- path
309
+ path,
310
+ initial: !this.initialized
310
311
  };
311
312
  }
312
313
  }
@@ -356,7 +357,7 @@ class Router {
356
357
 
357
358
  /**
358
359
  * @param {URL} url
359
- * @returns {Promise<import('./types').NavigationResult>}
360
+ * @returns {Promise<import('./types').NavigationResult | undefined>}
360
361
  */
361
362
  async prefetch(url) {
362
363
  const info = this.parse(url);
@@ -704,7 +705,7 @@ class Renderer {
704
705
  /** @type {Map<string, import('./types').NavigationResult>} */
705
706
  this.cache = new Map();
706
707
 
707
- /** @type {{id: string | null, promise: Promise<import('./types').NavigationResult> | null}} */
708
+ /** @type {{id: string | null, promise: Promise<import('./types').NavigationResult | undefined> | null}} */
708
709
  this.loading = {
709
710
  id: null,
710
711
  promise: null
@@ -871,6 +872,11 @@ class Renderer {
871
872
  const token = (this.token = {});
872
873
  let navigation_result = await this._get_navigation_result(info, no_cache);
873
874
 
875
+ if (!navigation_result) {
876
+ location.href = info.url.href;
877
+ return;
878
+ }
879
+
874
880
  // abort if user navigated during update
875
881
  if (token !== this.token) return;
876
882
 
@@ -950,6 +956,10 @@ class Renderer {
950
956
  this.autoscroll = true;
951
957
  this.updating = false;
952
958
 
959
+ if (navigation_result.props.page) {
960
+ this.page = navigation_result.props.page;
961
+ }
962
+
953
963
  if (!this.router) return;
954
964
 
955
965
  const leaf_node = navigation_result.state.branch[navigation_result.state.branch.length - 1];
@@ -962,7 +972,7 @@ class Renderer {
962
972
 
963
973
  /**
964
974
  * @param {import('./types').NavigationInfo} info
965
- * @returns {Promise<import('./types').NavigationResult>}
975
+ * @returns {Promise<import('./types').NavigationResult | undefined>}
966
976
  */
967
977
  load(info) {
968
978
  this.loading.promise = this._get_navigation_result(info, false);
@@ -987,6 +997,12 @@ class Renderer {
987
997
  return this.invalidating;
988
998
  }
989
999
 
1000
+ /** @param {URL} url */
1001
+ update_page_store(url) {
1002
+ this.stores.page.set({ ...this.page, url });
1003
+ this.stores.page.notify();
1004
+ }
1005
+
990
1006
  /** @param {import('./types').NavigationResult} result */
991
1007
  _init(result) {
992
1008
  this.current = result.state;
@@ -994,6 +1010,8 @@ class Renderer {
994
1010
  const style = document.querySelector('style[data-svelte]');
995
1011
  if (style) style.remove();
996
1012
 
1013
+ this.page = result.props.page;
1014
+
997
1015
  this.root = new this.Root({
998
1016
  target: this.target,
999
1017
  props: {
@@ -1014,7 +1032,7 @@ class Renderer {
1014
1032
  /**
1015
1033
  * @param {import('./types').NavigationInfo} info
1016
1034
  * @param {boolean} no_cache
1017
- * @returns {Promise<import('./types').NavigationResult>}
1035
+ * @returns {Promise<import('./types').NavigationResult | undefined>}
1018
1036
  */
1019
1037
  async _get_navigation_result(info, no_cache) {
1020
1038
  if (this.loading.id === info.id && this.loading.promise) {
@@ -1047,11 +1065,13 @@ class Renderer {
1047
1065
  if (result) return result;
1048
1066
  }
1049
1067
 
1050
- return await this._load_error({
1051
- status: 404,
1052
- error: new Error(`Not found: ${info.url.pathname}`),
1053
- url: info.url
1054
- });
1068
+ if (info.initial) {
1069
+ return await this._load_error({
1070
+ status: 404,
1071
+ error: new Error(`Not found: ${info.url.pathname}`),
1072
+ url: info.url
1073
+ });
1074
+ }
1055
1075
  }
1056
1076
 
1057
1077
  /**
@@ -1221,12 +1221,15 @@ async function render_response({
1221
1221
  `;
1222
1222
 
1223
1223
  if (options.amp) {
1224
+ // inline_style contains CSS files (i.e. `import './styles.css'`)
1225
+ // rendered.css contains the CSS from `<style>` tags in Svelte components
1226
+ const styles = `${inlined_style}\n${rendered.css.code}`;
1224
1227
  head += `
1225
1228
  <style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style>
1226
1229
  <noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
1227
1230
  <script async src="https://cdn.ampproject.org/v0.js"></script>
1228
1231
 
1229
- <style amp-custom>${inlined_style}\n${rendered.css.code}</style>`;
1232
+ <style amp-custom>${styles}</style>`;
1230
1233
 
1231
1234
  if (options.service_worker) {
1232
1235
  head +=
@@ -1258,6 +1261,8 @@ async function render_response({
1258
1261
  }
1259
1262
 
1260
1263
  if (styles.has(dep)) {
1264
+ // don't load stylesheets that are already inlined
1265
+ // include them in disabled state so that Vite can detect them and doesn't try to add them
1261
1266
  attributes.push('disabled', 'media="(max-width: 0)"');
1262
1267
  }
1263
1268
 
@@ -108,6 +108,7 @@ async function create_plugin(config, cwd) {
108
108
  entry: url.endsWith('.svelte') ? url : url + '?import',
109
109
  css: [],
110
110
  js: [],
111
+ // in dev we inline all styles to avoid FOUC
111
112
  styles
112
113
  };
113
114
  };
@@ -422,6 +423,11 @@ async function dev({ cwd, port, host, https, config }) {
422
423
  plugins: [
423
424
  svelte({
424
425
  extensions: config.extensions,
426
+ // In AMP mode, we know that there are no conditional component imports. In that case, we
427
+ // don't need to include CSS for components that are imported but unused, so we can just
428
+ // include rendered CSS.
429
+ // This would also apply if hydrate and router are both false, but we don't know if one
430
+ // has been enabled at the page level, so we don't do anything there.
425
431
  emitCss: !config.kit.amp,
426
432
  compilerOptions: {
427
433
  hydratable: !!config.kit.browser.hydrate
@@ -211,6 +211,11 @@ async function build_client({
211
211
  plugins: [
212
212
  svelte({
213
213
  extensions: config.extensions,
214
+ // In AMP mode, we know that there are no conditional component imports. In that case, we
215
+ // don't need to include CSS for components that are imported but unused, so we can just
216
+ // include rendered CSS.
217
+ // This would also apply if hydrate and router are both false, but we don't know if one
218
+ // has been enabled at the page level, so we don't do anything there.
214
219
  emitCss: !config.kit.amp,
215
220
  compilerOptions: {
216
221
  hydratable: !!config.kit.browser.hydrate
@@ -13,6 +13,8 @@ function generate_manifest(
13
13
  routes = build_data.manifest_data.routes,
14
14
  format = 'esm'
15
15
  ) {
16
+ /** @typedef {{ index: number, path: string }} LookupEntry */
17
+ /** @type {Map<string, LookupEntry>} */
16
18
  const bundled_nodes = new Map();
17
19
 
18
20
  // 0 and 1 are special, they correspond to the root layout and root error nodes
@@ -52,6 +54,9 @@ function generate_manifest(
52
54
  assets.push(build_data.service_worker);
53
55
  }
54
56
 
57
+ /** @param {string} id */
58
+ const get_index = (id) => id && /** @type {LookupEntry} */ (bundled_nodes.get(id)).index;
59
+
55
60
  // prettier-ignore
56
61
  return `{
57
62
  appDir: ${s(build_data.app_dir)},
@@ -71,8 +76,8 @@ function generate_manifest(
71
76
  params: ${get_params(route.params)},
72
77
  path: ${route.path ? s(route.path) : null},
73
78
  shadow: ${route.shadow ? importer(`${relative_path}/${build_data.server.vite_manifest[route.shadow].file}`) : null},
74
- a: ${s(route.a.map(component => component && bundled_nodes.get(component).index))},
75
- b: ${s(route.b.map(component => component && bundled_nodes.get(component).index))}
79
+ a: ${s(route.a.map(get_index))},
80
+ b: ${s(route.b.map(get_index))}
76
81
  }`.replace(/^\t\t/gm, '');
77
82
  } else {
78
83
  if (!build_data.server.vite_manifest[route.file]) {
package/dist/cli.js CHANGED
@@ -998,7 +998,7 @@ async function launch(port, https) {
998
998
  exec(`${cmd} ${https ? 'https' : 'http'}://localhost:${port}`);
999
999
  }
1000
1000
 
1001
- const prog = sade('svelte-kit').version('1.0.0-next.276');
1001
+ const prog = sade('svelte-kit').version('1.0.0-next.277');
1002
1002
 
1003
1003
  prog
1004
1004
  .command('dev')
@@ -1156,7 +1156,7 @@ async function check_port(port) {
1156
1156
  function welcome({ port, host, https, open, loose, allow, cwd }) {
1157
1157
  if (open) launch(port, https);
1158
1158
 
1159
- console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.276'}\n`));
1159
+ console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.277'}\n`));
1160
1160
 
1161
1161
  const protocol = https ? 'https:' : 'http:';
1162
1162
  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.276",
3
+ "version": "1.0.0-next.277",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/sveltejs/kit",