@@ -34,7 +34,7 @@ function page_store(value) {
3434
3535/**
3636 * @param {RequestInfo } resource
37- * @param {RequestInit } opts
37+ * @param {RequestInit } [ opts]
3838 */
3939function initial_fetch ( resource , opts ) {
4040 const url = typeof resource === 'string' ? resource : resource . url ;
@@ -82,7 +82,9 @@ export class Renderer {
8282
8383 /** @type {import('./types').NavigationState } */
8484 this . current = {
85+ // @ts -ignore
8586 page : null ,
87+ // @ts -ignore
8688 session_id : null ,
8789 branch : [ ]
8890 } ;
@@ -114,7 +116,7 @@ export class Renderer {
114116 this . session_id += 1 ;
115117
116118 const info = this . router . parse ( new URL ( location . href ) ) ;
117- this . update ( info , [ ] , true ) ;
119+ if ( info ) this . update ( info , [ ] , true ) ;
118120 } ) ;
119121 ready = true ;
120122 }
@@ -137,12 +139,6 @@ export class Renderer {
137139 /** @type {import('./types').NavigationResult | undefined } */
138140 let result ;
139141
140- /** @type {number | undefined } */
141- let new_status ;
142-
143- /** @type {Error | undefined } new_error */
144- let new_error ;
145-
146142 try {
147143 for ( let i = 0 ; i < nodes . length ; i += 1 ) {
148144 const is_leaf = i === nodes . length - 1 ;
@@ -160,8 +156,12 @@ export class Renderer {
160156 if ( node && node . loaded ) {
161157 if ( node . loaded . error ) {
162158 if ( error ) throw node . loaded . error ;
163- new_status = node . loaded . status ;
164- new_error = node . loaded . error ;
159+ result = await this . _load_error ( {
160+ status : node . loaded . status ,
161+ error : node . loaded . error ,
162+ path : page . path ,
163+ query : page . query
164+ } ) ;
165165 } else if ( node . loaded . context ) {
166166 context = {
167167 ...context ,
@@ -175,14 +175,9 @@ export class Renderer {
175175 } catch ( e ) {
176176 if ( error ) throw e ;
177177
178- new_status = 500 ;
179- new_error = e ;
180- }
181-
182- if ( new_error ) {
183178 result = await this . _load_error ( {
184- status : new_status ,
185- error : new_error ,
179+ status : 500 ,
180+ error : e ,
186181 path : page . path ,
187182 query : page . query
188183 } ) ;
@@ -203,6 +198,7 @@ export class Renderer {
203198 dispatchEvent ( new CustomEvent ( 'sveltekit:navigation-start' ) ) ;
204199
205200 if ( this . started ) {
201+ // @ts -ignore
206202 this . stores . navigating . set ( {
207203 from : {
208204 path : this . current . page . path ,
@@ -269,6 +265,7 @@ export class Renderer {
269265 this . loading . promise = null ;
270266 this . loading . id = null ;
271267
268+ if ( ! this . router ) return ;
272269 const leaf_node = navigation_result . state . branch [ navigation_result . state . branch . length - 1 ] ;
273270 if ( leaf_node && leaf_node . module . router === false ) {
274271 this . router . disable ( ) ;
@@ -294,8 +291,8 @@ export class Renderer {
294291
295292 if ( ! this . invalidating ) {
296293 this . invalidating = Promise . resolve ( ) . then ( async ( ) => {
297- const info = this . router . parse ( new URL ( location . href ) ) ;
298- await this . update ( info , [ ] , true ) ;
294+ const info = this . router && this . router . parse ( new URL ( location . href ) ) ;
295+ if ( info ) await this . update ( info , [ ] , true ) ;
299296
300297 this . invalidating = null ;
301298 } ) ;
@@ -330,6 +327,7 @@ export class Renderer {
330327 */
331328 async _get_navigation_result ( info , no_cache ) {
332329 if ( this . loading . id === info . id ) {
330+ // @ts -ignore if the id is defined then the promise is too
333331 return this . loading . promise ;
334332 }
335333
@@ -338,7 +336,7 @@ export class Renderer {
338336
339337 // check if endpoint route
340338 if ( route . length === 1 ) {
341- return { reload : true } ;
339+ return { reload : true , props : { } , state : this . current } ;
342340 }
343341
344342 // load code for subsequent routes immediately, if they are as
@@ -399,7 +397,8 @@ export class Renderer {
399397 } ;
400398
401399 for ( let i = 0 ; i < filtered . length ; i += 1 ) {
402- if ( filtered [ i ] . loaded ) result . props [ `props_${ i } ` ] = await filtered [ i ] . loaded . props ;
400+ const loaded = filtered [ i ] . loaded ;
401+ if ( loaded ) result . props [ `props_${ i } ` ] = await loaded . props ;
403402 }
404403
405404 if (
@@ -534,7 +533,7 @@ export class Renderer {
534533 /**
535534 * @param {import('./types').NavigationCandidate } selected
536535 * @param {boolean } no_cache
537- * @returns {Promise<import('./types').NavigationResult> }
536+ * @returns {Promise<import('./types').NavigationResult | undefined> } undefined if fallthrough
538537 */
539538 async _load ( { route, path, query } , no_cache ) {
540539 const key = `${ path } ?${ query } ` ;
@@ -545,6 +544,7 @@ export class Renderer {
545544 }
546545
547546 const [ pattern , a , b , get_params ] = route ;
547+ // @ts -ignore - the pattern is for the route which we've already matched to this path
548548 const params = get_params ? get_params ( pattern . exec ( path ) ) : { } ;
549549
550550 const changed = this . current . page && {
@@ -610,7 +610,9 @@ export class Renderer {
610610
611611 if ( node . loaded . redirect ) {
612612 return {
613- redirect : node . loaded . redirect
613+ redirect : node . loaded . redirect ,
614+ props : { } ,
615+ state : this . current
614616 } ;
615617 }
616618
@@ -651,7 +653,7 @@ export class Renderer {
651653 context : node_loaded . context
652654 } ) ;
653655
654- if ( error_loaded && error_loaded . loaded . error ) {
656+ if ( error_loaded && error_loaded . loaded && error_loaded . loaded . error ) {
655657 continue ;
656658 }
657659
@@ -713,7 +715,7 @@ export class Renderer {
713715 error,
714716 module : await this . fallback [ 1 ] ,
715717 page,
716- context : node && node . loaded && node . loaded . context
718+ context : ( node && node . loaded && node . loaded . context ) || { }
717719 } )
718720 ] ;
719721
0 commit comments