@@ -14,6 +14,7 @@ import {
1414 IS_SSR_KEY ,
1515 LOADER_ENTRIES_KEY ,
1616 LOADER_SET_KEY ,
17+ LOADER_SET_PROMISES_KEY ,
1718 NAVIGATION_RESULTS_KEY ,
1819 PENDING_LOCATION_KEY ,
1920} from './meta-extensions'
@@ -105,6 +106,7 @@ export function setupLoaderGuard({
105106 const lazyLoadingPromises : Promise < unknown > [ ] = [ ]
106107
107108 for ( const record of to . matched ) {
109+ console . log ( 'record' , record . meta [ LOADER_SET_KEY ] )
108110 // we only need to do this once per record as these changes are preserved
109111 // by the router
110112 if ( ! record . meta [ LOADER_SET_KEY ] ) {
@@ -114,6 +116,7 @@ export function setupLoaderGuard({
114116 // add all the loaders from the components to the set
115117 for ( const componentName in record . components ) {
116118 const component : unknown = record . components [ componentName ]
119+ console . log ( 'component' , component , isAsyncModule ( component ) )
117120
118121 // we only add async modules because otherwise the component doesn't have any loaders and the user should add
119122 // them with the `loaders` array
@@ -143,10 +146,17 @@ export function setupLoaderGuard({
143146 }
144147 }
145148 }
149+ console . log ( 'v' , viewModule )
146150 } )
147151
152+ record . meta [ LOADER_SET_PROMISES_KEY ] ??= [ ]
153+ record . meta [ LOADER_SET_PROMISES_KEY ] . push ( promise )
148154 lazyLoadingPromises . push ( promise )
149155 }
156+ } else if ( record . meta [ LOADER_SET_PROMISES_KEY ] ) {
157+ // When repeated navigation happen on the same route, loaders might still be
158+ // resolved from async modules, so we need to wait for them to resolve.
159+ lazyLoadingPromises . push ( ...record . meta [ LOADER_SET_PROMISES_KEY ] )
150160 }
151161 }
152162
@@ -156,6 +166,7 @@ export function setupLoaderGuard({
156166 // merge the whole set of loaders
157167 for ( const loader of record . meta [ LOADER_SET_KEY ] ! ) {
158168 to . meta [ LOADER_SET_KEY ] ! . add ( loader )
169+ to . meta [ LOADER_SET_PROMISES_KEY ] = undefined
159170 }
160171 }
161172 // we return nothing to remove the value to allow the navigation
0 commit comments