File tree 2 files changed +8
-41
lines changed
2 files changed +8
-41
lines changed Original file line number Diff line number Diff line change 6
6
< meta name ="viewport " content ="width=device-width, initial-scale=1 " />
7
7
%sveltekit.head%
8
8
</ head >
9
- < body >
9
+ < body data-sveltekit-preload-data =" hover " >
10
10
< div > %sveltekit.body%</ div >
11
11
</ body >
12
12
</ html >
Original file line number Diff line number Diff line change 1
- import { beforeNavigate } from '$app/navigation' ;
2
- import { navigating } from '$app/stores' ;
3
- import { onDestroy } from 'svelte' ;
4
-
5
- function getNavigationStore ( ) {
6
- /** @type {((val?: any) => void)[] } */
7
- let callbacks = [ ] ;
8
-
9
- const navigation = {
10
- ...navigating ,
11
- complete : async ( ) => {
12
- await new Promise ( ( res , _ ) => {
13
- callbacks . push ( res ) ;
14
- } ) ;
15
- }
16
- } ;
17
-
18
- // This used to subscribe inside the callback, but that resolved the promise too early
19
- const unsub = navigating . subscribe ( ( n ) => {
20
- if ( n === null ) {
21
- while ( callbacks . length > 0 ) {
22
- const res = callbacks . pop ( ) ;
23
- res ?. ( ) ;
24
- }
25
- }
26
- } ) ;
27
-
28
- onDestroy ( ( ) => {
29
- unsub ( ) ;
30
- } ) ;
31
-
32
- return navigation ;
33
- }
1
+ import { onNavigate } from '$app/navigation' ;
34
2
35
3
export const preparePageTransition = ( ) => {
36
- const navigation = getNavigationStore ( ) ;
37
-
38
- // before navigating, start a new transition
39
- beforeNavigate ( ( ) => {
4
+ onNavigate ( async ( navigation ) => {
40
5
if ( ! document . startViewTransition ) {
41
6
return ;
42
7
}
43
- const navigationComplete = navigation . complete ( ) ;
44
8
45
- document . startViewTransition ( async ( ) => {
46
- await navigationComplete ;
9
+ return new Promise ( ( oldStateCaptureResolve ) => {
10
+ document . startViewTransition ( async ( ) => {
11
+ oldStateCaptureResolve ( ) ;
12
+ await navigation . complete ;
13
+ } ) ;
47
14
} ) ;
48
15
} ) ;
49
16
} ;
You can’t perform that action at this time.
0 commit comments