@@ -182,17 +182,65 @@ describe('navigation-guard', () => {
182
182
it ( 'collects all loaders from lazy loaded pages with repeated navigation' , async ( ) => {
183
183
setupApp ( { isSSR : false } )
184
184
const router = getRouter ( )
185
+
186
+ const { promise, resolve } = Promise . withResolvers < void > ( )
187
+
185
188
router . addRoute ( {
186
189
name : '_test' ,
187
190
path : '/fetch' ,
188
- component : ( ) =>
189
- import ( '../../tests/data-loaders/ComponentWithLoader.vue' ) ,
191
+ component : async ( ) => {
192
+ await promise
193
+
194
+ return import ( '../../tests/data-loaders/ComponentWithLoader.vue' )
195
+ } ,
190
196
} )
191
197
192
198
void router . push ( '/fetch' )
193
199
194
- // simulate repeated navigation while the async component is loading
200
+ // wait a tick to ensure first navigation is started
195
201
await Promise . resolve ( )
202
+
203
+ const secondNavPromise = router . push ( '/fetch' )
204
+ resolve ( )
205
+ await secondNavPromise
206
+
207
+ const set = router . currentRoute . value . meta [ LOADER_SET_KEY ]
208
+ expect ( [ ...set ! ] ) . toEqual ( [ useDataOne , useDataTwo ] )
209
+
210
+ for ( const record of router . currentRoute . value . matched ) {
211
+ expect ( record . meta [ LOADER_SET_PROMISES_KEY ] ) . toBeUndefined ( )
212
+ }
213
+ } )
214
+
215
+ it ( 'collects all loaders from lazy loaded pages when first navigation fails' , async ( ) => {
216
+ setupApp ( { isSSR : false } )
217
+ const router = getRouter ( )
218
+
219
+ let first = true
220
+ router . addRoute ( {
221
+ name : '_test' ,
222
+ path : '/fetch' ,
223
+ component : async ( ) => {
224
+ if ( first ) {
225
+ first = false
226
+
227
+ throw new Error ( 'Failed to load component' )
228
+ }
229
+
230
+ return import ( '../../tests/data-loaders/ComponentWithLoader.vue' )
231
+ } ,
232
+ } )
233
+
234
+ const firstNavPromise = router . push ( '/fetch' )
235
+ await expect ( firstNavPromise ) . rejects . toThrow ( Error )
236
+
237
+ // Verify loaders collection cleanup after failure
238
+ const rec = getRouter ( )
239
+ . getRoutes ( )
240
+ . find ( ( r ) => r . name === '_test' ) !
241
+ expect ( rec . meta [ LOADER_SET_KEY ] ) . toBeUndefined ( )
242
+ expect ( rec . meta [ LOADER_SET_PROMISES_KEY ] ) . toBeUndefined ( )
243
+
196
244
await router . push ( '/fetch' )
197
245
198
246
const set = router . currentRoute . value . meta [ LOADER_SET_KEY ]
0 commit comments