@@ -1202,134 +1202,75 @@ describe("Lazy Route Discovery (Fog of War)", () => {
1202
1202
unsubscribe ( ) ;
1203
1203
} ) ;
1204
1204
1205
- it ( ' does not re-call for previously called "good" paths' , async ( ) => {
1205
+ it ( " does not re-patch previously patched routes" , async ( ) => {
1206
1206
let count = 0 ;
1207
1207
router = createRouter ( {
1208
1208
history : createMemoryHistory ( ) ,
1209
1209
routes : [
1210
1210
{
1211
1211
path : "/" ,
1212
1212
} ,
1213
- {
1214
- id : "param" ,
1215
- path : ":param" ,
1216
- } ,
1217
1213
] ,
1218
- async patchRoutesOnNavigation ( ) {
1214
+ async patchRoutesOnNavigation ( { patch } ) {
1219
1215
count ++ ;
1216
+ patch ( null , [
1217
+ {
1218
+ id : "param" ,
1219
+ path : ":param" ,
1220
+ } ,
1221
+ ] ) ;
1220
1222
await tick ( ) ;
1221
- // Nothing to patch - there is no better static route in this case
1222
1223
} ,
1223
1224
} ) ;
1224
1225
1225
- await router . navigate ( "/whatever" ) ;
1226
- expect ( count ) . toBe ( 1 ) ;
1227
- expect ( router . state . location . pathname ) . toBe ( "/whatever" ) ;
1226
+ await router . navigate ( "/a" ) ;
1227
+ expect ( router . state . location . pathname ) . toBe ( "/a" ) ;
1228
1228
expect ( router . state . matches . map ( ( m ) => m . route . id ) ) . toEqual ( [ "param" ] ) ;
1229
-
1230
- await router . navigate ( "/" ) ;
1231
1229
expect ( count ) . toBe ( 1 ) ;
1232
- expect ( router . state . location . pathname ) . toBe ( "/" ) ;
1233
-
1234
- await router . navigate ( "/whatever" ) ;
1235
- expect ( count ) . toBe ( 1 ) ; // Not called again
1236
- expect ( router . state . location . pathname ) . toBe ( "/whatever" ) ;
1237
- expect ( router . state . matches . map ( ( m ) => m . route . id ) ) . toEqual ( [ "param" ] ) ;
1238
- } ) ;
1239
-
1240
- it ( "does not re-call for previously called 404 paths" , async ( ) => {
1241
- let count = 0 ;
1242
- router = createRouter ( {
1243
- history : createMemoryHistory ( ) ,
1244
- routes : [
1230
+ expect ( router . routes ) . toMatchInlineSnapshot ( `
1231
+ [
1245
1232
{
1246
- id : "index" ,
1247
- path : "/" ,
1233
+ "children": undefined,
1234
+ "hasErrorBoundary": false,
1235
+ "id": "0",
1236
+ "path": "/",
1248
1237
},
1249
1238
{
1250
- id : "static" ,
1251
- path : "static" ,
1239
+ "children": undefined,
1240
+ "hasErrorBoundary": false,
1241
+ "id": "param",
1242
+ "path": ":param",
1252
1243
},
1253
- ] ,
1254
- async patchRoutesOnNavigation ( ) {
1255
- count ++ ;
1256
- } ,
1257
- } ) ;
1258
-
1259
- await router . navigate ( "/junk" ) ;
1260
- expect ( count ) . toBe ( 1 ) ;
1261
- expect ( router . state . location . pathname ) . toBe ( "/junk" ) ;
1262
- expect ( router . state . errors ?. index ) . toEqual (
1263
- new ErrorResponseImpl (
1264
- 404 ,
1265
- "Not Found" ,
1266
- new Error ( 'No route matches URL "/junk"' ) ,
1267
- true
1268
- )
1269
- ) ;
1244
+ ]
1245
+ ` ) ;
1270
1246
1271
1247
await router . navigate ( "/" ) ;
1272
- expect ( count ) . toBe ( 1 ) ;
1273
1248
expect ( router . state . location . pathname ) . toBe ( "/" ) ;
1274
- expect ( router . state . errors ) . toBeNull ( ) ;
1275
-
1276
- await router . navigate ( "/junk" ) ;
1277
1249
expect ( count ) . toBe ( 1 ) ;
1278
- expect ( router . state . location . pathname ) . toBe ( "/junk" ) ;
1279
- expect ( router . state . errors ?. index ) . toEqual (
1280
- new ErrorResponseImpl (
1281
- 404 ,
1282
- "Not Found" ,
1283
- new Error ( 'No route matches URL "/junk"' ) ,
1284
- true
1285
- )
1286
- ) ;
1287
- } ) ;
1288
1250
1289
- it ( "caps internal fifo queue at 1000 paths" , async ( ) => {
1290
- let count = 0 ;
1291
- router = createRouter ( {
1292
- history : createMemoryHistory ( ) ,
1293
- routes : [
1251
+ await router . navigate ( "/b" ) ;
1252
+ expect ( router . state . location . pathname ) . toBe ( "/b" ) ;
1253
+ expect ( router . state . matches . map ( ( m ) => m . route . id ) ) . toEqual ( [ "param" ] ) ;
1254
+ expect ( router . state . errors ) . toBeNull ( ) ;
1255
+ // Called again
1256
+ expect ( count ) . toBe ( 2 ) ;
1257
+ // But not patched again
1258
+ expect ( router . routes ) . toMatchInlineSnapshot ( `
1259
+ [
1294
1260
{
1295
- path : "/" ,
1261
+ "children": undefined,
1262
+ "hasErrorBoundary": false,
1263
+ "id": "0",
1264
+ "path": "/",
1296
1265
},
1297
1266
{
1298
- id : "param" ,
1299
- path : ":param" ,
1267
+ "children": undefined,
1268
+ "hasErrorBoundary": false,
1269
+ "id": "param",
1270
+ "path": ":param",
1300
1271
},
1301
- ] ,
1302
- async patchRoutesOnNavigation ( ) {
1303
- count ++ ;
1304
- // Nothing to patch - there is no better static route in this case
1305
- } ,
1306
- } ) ;
1307
-
1308
- // Fill it up with 1000 paths
1309
- for ( let i = 1 ; i <= 1000 ; i ++ ) {
1310
- await router . navigate ( `/path-${ i } ` ) ;
1311
- expect ( count ) . toBe ( i ) ;
1312
- expect ( router . state . location . pathname ) . toBe ( `/path-${ i } ` ) ;
1313
-
1314
- await router . navigate ( "/" ) ;
1315
- expect ( count ) . toBe ( i ) ;
1316
- expect ( router . state . location . pathname ) . toBe ( "/" ) ;
1317
- }
1318
-
1319
- // Don't call patchRoutesOnNavigation since this is the first item in the queue
1320
- await router . navigate ( `/path-1` ) ;
1321
- expect ( count ) . toBe ( 1000 ) ;
1322
- expect ( router . state . location . pathname ) . toBe ( `/path-1` ) ;
1323
-
1324
- // Call patchRoutesOnNavigation and evict the first item
1325
- await router . navigate ( `/path-1001` ) ;
1326
- expect ( count ) . toBe ( 1001 ) ;
1327
- expect ( router . state . location . pathname ) . toBe ( `/path-1001` ) ;
1328
-
1329
- // Call patchRoutesOnNavigation since this item was evicted
1330
- await router . navigate ( `/path-1` ) ;
1331
- expect ( count ) . toBe ( 1002 ) ;
1332
- expect ( router . state . location . pathname ) . toBe ( `/path-1` ) ;
1272
+ ]
1273
+ ` ) ;
1333
1274
} ) ;
1334
1275
1335
1276
describe ( "errors" , ( ) => {
0 commit comments