@sveltejs/kit 1.0.0-next.210 → 1.0.0-next.214

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/assets/kit.js CHANGED
@@ -598,7 +598,7 @@ async function render_response({
598
598
  navigating: writable(null),
599
599
  session
600
600
  },
601
- page: { url, params },
601
+ page: { url, params, status, error },
602
602
  components: branch.map(({ node }) => node.module.default)
603
603
  };
604
604
 
@@ -1,4 +1,4 @@
1
- import { router as router$1 } from '../internal/singletons.js';
1
+ import { renderer, router as router$1 } from '../internal/singletons.js';
2
2
  import { g as get_base_uri } from '../chunks/utils.js';
3
3
 
4
4
  const router = /** @type {import('../client/router').Router} */ (router$1);
@@ -12,11 +12,21 @@ function guard(name) {
12
12
  };
13
13
  }
14
14
 
15
+ const disableScrollHandling = import.meta.env.SSR
16
+ ? guard('disableScrollHandling')
17
+ : disableScrollHandling_;
15
18
  const goto = import.meta.env.SSR ? guard('goto') : goto_;
16
19
  const invalidate = import.meta.env.SSR ? guard('invalidate') : invalidate_;
17
20
  const prefetch = import.meta.env.SSR ? guard('prefetch') : prefetch_;
18
21
  const prefetchRoutes = import.meta.env.SSR ? guard('prefetchRoutes') : prefetchRoutes_;
19
22
 
23
+ /**
24
+ * @type {import('$app/navigation').goto}
25
+ */
26
+ async function disableScrollHandling_() {
27
+ renderer.disable_scroll_handling();
28
+ }
29
+
20
30
  /**
21
31
  * @type {import('$app/navigation').goto}
22
32
  */
@@ -52,4 +62,4 @@ async function prefetchRoutes_(pathnames) {
52
62
  await Promise.all(promises);
53
63
  }
54
64
 
55
- export { goto, invalidate, prefetch, prefetchRoutes };
65
+ export { disableScrollHandling, goto, invalidate, prefetch, prefetchRoutes };
@@ -57,7 +57,7 @@ const navigating = {
57
57
  };
58
58
 
59
59
  /** @param {string} verb */
60
- const error = (verb) => {
60
+ const throw_error = (verb) => {
61
61
  throw new Error(
62
62
  ssr
63
63
  ? `Can only ${verb} session store in browser`
@@ -77,8 +77,8 @@ const session = {
77
77
 
78
78
  return store.subscribe(fn);
79
79
  },
80
- set: () => error('set'),
81
- update: () => error('update')
80
+ set: () => throw_error('set'),
81
+ update: () => throw_error('update')
82
82
  };
83
83
 
84
84
  export { getStores, navigating, page, session, stores };
@@ -1,9 +1,18 @@
1
1
  /** @type {import('./router').Router?} */
2
2
  let router;
3
3
 
4
- /** @param {import('./router').Router?} _ */
5
- function init(_) {
6
- router = _;
4
+ /** @type {import('./renderer').Renderer} */
5
+ let renderer;
6
+
7
+ /**
8
+ * @param {{
9
+ * router: import('./router').Router?;
10
+ * renderer: import('./renderer').Renderer;
11
+ * }} opts
12
+ */
13
+ function init(opts) {
14
+ router = opts.router;
15
+ renderer = opts.renderer;
7
16
  }
8
17
 
9
- export { init, router };
18
+ export { init, renderer, router };
@@ -466,6 +466,8 @@ class Renderer {
466
466
  this.session_id = 1;
467
467
  this.invalid = new Set();
468
468
  this.invalidating = null;
469
+ this.autoscroll = true;
470
+ this.updating = false;
469
471
 
470
472
  /** @type {import('./types').NavigationState} */
471
473
  this.current = {
@@ -508,6 +510,16 @@ class Renderer {
508
510
  ready = true;
509
511
  }
510
512
 
513
+ disable_scroll_handling() {
514
+ if (import.meta.env.DEV && this.started && !this.updating) {
515
+ throw new Error('Can only disable scroll handling during navigation');
516
+ }
517
+
518
+ if (this.updating || !this.started) {
519
+ this.autoscroll = false;
520
+ }
521
+ }
522
+
511
523
  /**
512
524
  * @param {{
513
525
  * status: number;
@@ -563,7 +575,7 @@ class Renderer {
563
575
 
564
576
  result = error_args
565
577
  ? await this._load_error(error_args)
566
- : await this._get_navigation_result_from_branch({ url, params, branch });
578
+ : await this._get_navigation_result_from_branch({ url, params, branch, status, error });
567
579
  } catch (e) {
568
580
  if (error) throw e;
569
581
 
@@ -637,6 +649,8 @@ class Renderer {
637
649
  }
638
650
  }
639
651
 
652
+ this.updating = true;
653
+
640
654
  if (this.started) {
641
655
  this.current = navigation_result.state;
642
656
 
@@ -655,26 +669,9 @@ class Renderer {
655
669
  document.body.focus();
656
670
  }
657
671
 
658
- const old_page_y_offset = Math.round(pageYOffset);
659
- const old_max_page_y_offset = document.documentElement.scrollHeight - innerHeight;
660
-
661
672
  await 0;
662
673
 
663
- const new_page_y_offset = Math.round(pageYOffset);
664
- const new_max_page_y_offset = document.documentElement.scrollHeight - innerHeight;
665
-
666
- // After `await 0`, the `onMount()` function in the component executed.
667
- // Check if no scrolling happened on mount.
668
- const no_scroll_happened =
669
- // In most cases, we can compare whether `pageYOffset` changed between navigation
670
- new_page_y_offset === Math.min(old_page_y_offset, new_max_page_y_offset) ||
671
- // But if the page is scrolled to/near the bottom, the browser would also scroll
672
- // to/near the bottom of the new page on navigation. Since we can't detect when this
673
- // behaviour happens, we naively compare by the y offset from the bottom of the page.
674
- old_max_page_y_offset - old_page_y_offset === new_max_page_y_offset - new_page_y_offset;
675
-
676
- // If there was no scrolling, we run on our custom scroll handling
677
- if (no_scroll_happened) {
674
+ if (this.autoscroll) {
678
675
  const deep_linked = hash && document.getElementById(hash.slice(1));
679
676
  if (scroll) {
680
677
  scrollTo(scroll.x, scroll.y);
@@ -694,6 +691,8 @@ class Renderer {
694
691
 
695
692
  this.loading.promise = null;
696
693
  this.loading.id = null;
694
+ this.autoscroll = true;
695
+ this.updating = false;
697
696
 
698
697
  if (!this.router) return;
699
698
 
@@ -800,9 +799,11 @@ class Renderer {
800
799
  * url: URL;
801
800
  * params: Record<string, string>;
802
801
  * branch: Array<import('./types').BranchNode | undefined>;
802
+ * status: number;
803
+ * error?: Error;
803
804
  * }} opts
804
805
  */
805
- async _get_navigation_result_from_branch({ url, params, branch }) {
806
+ async _get_navigation_result_from_branch({ url, params, branch, status, error }) {
806
807
  const filtered = /** @type {import('./types').BranchNode[] } */ (branch.filter(Boolean));
807
808
  const redirect = filtered.find((f) => f.loaded && f.loaded.redirect);
808
809
 
@@ -826,7 +827,7 @@ class Renderer {
826
827
  }
827
828
 
828
829
  if (!this.current.url || url.href !== this.current.url.href) {
829
- result.props.page = { url, params };
830
+ result.props.page = { url, params, status, error };
830
831
 
831
832
  // TODO remove this for 1.0
832
833
  /**
@@ -1120,12 +1121,12 @@ class Renderer {
1120
1121
  }
1121
1122
  }
1122
1123
 
1123
- return await this._get_navigation_result_from_branch({ url, params, branch });
1124
+ return await this._get_navigation_result_from_branch({ url, params, branch, status, error });
1124
1125
  }
1125
1126
 
1126
1127
  /**
1127
1128
  * @param {{
1128
- * status?: number;
1129
+ * status: number;
1129
1130
  * error: Error;
1130
1131
  * url: URL;
1131
1132
  * }} opts
@@ -1153,7 +1154,7 @@ class Renderer {
1153
1154
  })
1154
1155
  ];
1155
1156
 
1156
- return await this._get_navigation_result_from_branch({ url, params, branch });
1157
+ return await this._get_navigation_result_from_branch({ url, params, branch, status, error });
1157
1158
  }
1158
1159
  }
1159
1160
 
@@ -1200,7 +1201,7 @@ async function start({ paths, target, session, route, spa, trailing_slash, hydra
1200
1201
  })
1201
1202
  : null;
1202
1203
 
1203
- init(router);
1204
+ init({ router, renderer });
1204
1205
  set_paths(paths);
1205
1206
 
1206
1207
  if (hydrate) await renderer.start(hydrate);