@@ -5440,8 +5440,8 @@ async function callLoaderOrAction({
54405440 | LoaderFunction < unknown >
54415441 | ActionFunction < unknown > ;
54425442
5443- // If we have a route. lazy promise , await that first
5444- if ( lazyHandlerPromise ) {
5443+ // If we have a promise for a lazy route , await that first
5444+ if ( lazyHandlerPromise || lazyRoutePromise ) {
54455445 if ( handler ) {
54465446 // Run statically defined handler in parallel with lazy()
54475447 let handlerError ;
@@ -5453,13 +5453,14 @@ async function callLoaderOrAction({
54535453 handlerError = e ;
54545454 } ) ,
54555455 lazyHandlerPromise ,
5456+ lazyRoutePromise ,
54565457 ] ) ;
54575458 if ( handlerError !== undefined ) {
54585459 throw handlerError ;
54595460 }
54605461 result = value ! ;
54615462 } else {
5462- // Load lazy loader/action, then run any returned handler
5463+ // Load lazy loader/action before running it
54635464 await lazyHandlerPromise ;
54645465
54655466 handler = match . route [ type ] as
@@ -5468,7 +5469,8 @@ async function callLoaderOrAction({
54685469 if ( handler ) {
54695470 // Handler still runs even if we got interrupted to maintain consistency
54705471 // with un-abortable behavior of handler execution on non-lazy or
5471- // previously-lazy-loaded routes
5472+ // previously-lazy-loaded routes. We also ensure the entire lazy
5473+ // route is loaded before continuing.
54725474 [ result ] = await Promise . all ( [ runHandler ( handler ) , lazyRoutePromise ] ) ;
54735475 } else if ( type === "action" ) {
54745476 let url = new URL ( request . url ) ;
@@ -5479,7 +5481,7 @@ async function callLoaderOrAction({
54795481 routeId : match . route . id ,
54805482 } ) ;
54815483 } else {
5482- // lazy() route has no loader to run. Short circuit here so we don't
5484+ // lazy route has no loader to run. Short circuit here so we don't
54835485 // hit the invariant below that errors on returning undefined.
54845486 return { type : ResultType . data , result : undefined } ;
54855487 }
0 commit comments