@sveltejs/kit 1.0.0-next.213 → 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.
|
@@ -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 };
|
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
/** @type {import('./router').Router?} */
|
|
2
2
|
let router;
|
|
3
3
|
|
|
4
|
-
/** @
|
|
5
|
-
|
|
6
|
-
|
|
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;
|
|
@@ -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
|
-
|
|
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
|
|
|
@@ -1202,7 +1201,7 @@ async function start({ paths, target, session, route, spa, trailing_slash, hydra
|
|
|
1202
1201
|
})
|
|
1203
1202
|
: null;
|
|
1204
1203
|
|
|
1205
|
-
init(router);
|
|
1204
|
+
init({ router, renderer });
|
|
1206
1205
|
set_paths(paths);
|
|
1207
1206
|
|
|
1208
1207
|
if (hydrate) await renderer.start(hydrate);
|
package/dist/cli.js
CHANGED
|
@@ -887,7 +887,7 @@ async function launch(port, https) {
|
|
|
887
887
|
exec(`${cmd} ${https ? 'https' : 'http'}://localhost:${port}`);
|
|
888
888
|
}
|
|
889
889
|
|
|
890
|
-
const prog = sade('svelte-kit').version('1.0.0-next.
|
|
890
|
+
const prog = sade('svelte-kit').version('1.0.0-next.214');
|
|
891
891
|
|
|
892
892
|
prog
|
|
893
893
|
.command('dev')
|
|
@@ -1039,7 +1039,7 @@ async function check_port(port) {
|
|
|
1039
1039
|
function welcome({ port, host, https, open, loose, allow, cwd }) {
|
|
1040
1040
|
if (open) launch(port, https);
|
|
1041
1041
|
|
|
1042
|
-
console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.
|
|
1042
|
+
console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.214'}\n`));
|
|
1043
1043
|
|
|
1044
1044
|
const protocol = https ? 'https:' : 'http:';
|
|
1045
1045
|
const exposed = typeof host !== 'undefined' && host !== 'localhost' && host !== '127.0.0.1';
|
package/package.json
CHANGED
|
@@ -26,6 +26,11 @@ declare module '$app/env' {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
declare module '$app/navigation' {
|
|
29
|
+
/**
|
|
30
|
+
* Disable SvelteKit's built-in scroll handling for the current navigation, in case you need to manually control the scroll position.
|
|
31
|
+
* This is generally discouraged, since it breaks user expectations.
|
|
32
|
+
*/
|
|
33
|
+
export function disableScrollHandling(): void;
|
|
29
34
|
/**
|
|
30
35
|
* Returns a Promise that resolves when SvelteKit navigates (or fails to navigate, in which case the promise rejects) to the specified href.
|
|
31
36
|
*
|