@@ -121,9 +121,6 @@ export function create_client({ target, session, base, trailing_slash }) {
121
121
} ) ;
122
122
ready = true ;
123
123
124
- /** Keeps tracks of multiple navigations caused by redirects during rendering */
125
- let navigating = 0 ;
126
-
127
124
let router_enabled = true ;
128
125
129
126
// keeping track of the history index in order to prevent popstate navigation events if needed
@@ -158,9 +155,6 @@ export function create_client({ target, session, base, trailing_slash }) {
158
155
/** @type {{} } */
159
156
let token ;
160
157
161
- /** @type {{} } */
162
- let navigating_token ;
163
-
164
158
/**
165
159
* @param {string } href
166
160
* @param {{ noscroll?: boolean; replaceState?: boolean; keepfocus?: boolean; state?: any } } opts
@@ -206,6 +200,7 @@ export function create_client({ target, session, base, trailing_slash }) {
206
200
}
207
201
208
202
/**
203
+ * Returns `true` if update completes, `false` if it is aborted
209
204
* @param {URL } url
210
205
* @param {string[] } redirect_chain
211
206
* @param {boolean } no_cache
@@ -237,11 +232,11 @@ export function create_client({ target, session, base, trailing_slash }) {
237
232
238
233
if ( ! navigation_result ) {
239
234
await native_navigation ( url ) ;
240
- return ; // unnecessary, but TypeScript prefers it this way
235
+ return false ; // unnecessary, but TypeScript prefers it this way
241
236
}
242
237
243
238
// abort if user navigated during update
244
- if ( token !== current_token ) return ;
239
+ if ( token !== current_token ) return false ;
245
240
246
241
invalidated . length = 0 ;
247
242
@@ -263,7 +258,7 @@ export function create_client({ target, session, base, trailing_slash }) {
263
258
await native_navigation ( new URL ( navigation_result . redirect , location . href ) ) ;
264
259
}
265
260
266
- return ;
261
+ return false ;
267
262
}
268
263
} else if ( navigation_result . props ?. page ?. status >= 400 ) {
269
264
const updated = await stores . updated . check ( ) ;
@@ -346,6 +341,8 @@ export function create_client({ target, session, base, trailing_slash }) {
346
341
347
342
const leaf_node = navigation_result . state . branch [ navigation_result . state . branch . length - 1 ] ;
348
343
router_enabled = leaf_node ?. module . router !== false ;
344
+
345
+ return true ;
349
346
}
350
347
351
348
/** @param {import('./types').NavigationResult } result */
@@ -898,29 +895,20 @@ export function create_client({ target, session, base, trailing_slash }) {
898
895
899
896
accepted ( ) ;
900
897
901
- navigating ++ ;
902
-
903
- const current_navigating_token = ( navigating_token = { } ) ;
904
-
905
898
if ( started ) {
906
899
stores . navigating . set ( {
907
900
from : current . url ,
908
901
to : normalized
909
902
} ) ;
910
903
}
911
904
912
- await update ( normalized , redirect_chain , false , {
905
+ const completed = await update ( normalized , redirect_chain , false , {
913
906
scroll,
914
907
keepfocus,
915
908
details
916
909
} ) ;
917
910
918
- navigating -- ;
919
-
920
- // navigation was aborted
921
- if ( navigating_token !== current_navigating_token ) return ;
922
-
923
- if ( ! navigating ) {
911
+ if ( completed ) {
924
912
const navigation = { from, to : normalized } ;
925
913
callbacks . after_navigate . forEach ( ( fn ) => fn ( navigation ) ) ;
926
914
@@ -1113,11 +1101,6 @@ export function create_client({ target, session, base, trailing_slash }) {
1113
1101
// Ignore if <a> has a target
1114
1102
if ( is_svg_a_element ? a . target . baseVal : a . target ) return ;
1115
1103
1116
- if ( url . href === location . href ) {
1117
- if ( ! location . hash ) event . preventDefault ( ) ;
1118
- return ;
1119
- }
1120
-
1121
1104
// Check if new url only differs by hash and use the browser default behavior in that case
1122
1105
// This will ensure the `hashchange` event is fired
1123
1106
// Removing the hash does a full page navigation in the browser, so make sure a hash is present
@@ -1142,7 +1125,7 @@ export function create_client({ target, session, base, trailing_slash }) {
1142
1125
redirect_chain : [ ] ,
1143
1126
details : {
1144
1127
state : { } ,
1145
- replaceState : false
1128
+ replaceState : url . href === location . href
1146
1129
} ,
1147
1130
accepted : ( ) => event . preventDefault ( ) ,
1148
1131
blocked : ( ) => event . preventDefault ( )
0 commit comments