@@ -2,7 +2,8 @@ import { FallbackMode } from '../../lib/fallback'
2
2
import type { Params } from '../../server/request/params'
3
3
import {
4
4
assignErrorIfEmpty ,
5
- generateParamPrefixCombinations ,
5
+ generateAllParamCombinations ,
6
+ calculateFallbackMode ,
6
7
filterUniqueParams ,
7
8
generateRouteStaticParams ,
8
9
} from './app'
@@ -356,7 +357,7 @@ describe('generateParamPrefixCombinations', () => {
356
357
{ id : '2' , name : 'test' } ,
357
358
]
358
359
359
- const unique = generateParamPrefixCombinations ( [ 'id' ] , params , [ ] )
360
+ const unique = generateAllParamCombinations ( [ 'id' ] , params , [ ] )
360
361
361
362
expect ( unique ) . toEqual ( [ { id : '1' } , { id : '2' } ] )
362
363
} )
@@ -369,11 +370,7 @@ describe('generateParamPrefixCombinations', () => {
369
370
{ lang : 'fr' , region : 'CA' , page : 'about' } ,
370
371
]
371
372
372
- const unique = generateParamPrefixCombinations (
373
- [ 'lang' , 'region' ] ,
374
- params ,
375
- [ ]
376
- )
373
+ const unique = generateAllParamCombinations ( [ 'lang' , 'region' ] , params , [ ] )
377
374
378
375
expect ( unique ) . toEqual ( [
379
376
{ lang : 'en' } ,
@@ -386,20 +383,20 @@ describe('generateParamPrefixCombinations', () => {
386
383
it ( 'should handle parameter value collisions' , ( ) => {
387
384
const params = [ { slug : [ 'foo' , 'bar' ] } , { slug : 'foo,bar' } ]
388
385
389
- const unique = generateParamPrefixCombinations ( [ 'slug' ] , params , [ ] )
386
+ const unique = generateAllParamCombinations ( [ 'slug' ] , params , [ ] )
390
387
391
388
expect ( unique ) . toEqual ( [ { slug : [ 'foo' , 'bar' ] } , { slug : 'foo,bar' } ] )
392
389
} )
393
390
394
391
it ( 'should handle empty inputs' , ( ) => {
395
392
// Empty routeParamKeys
396
- expect ( generateParamPrefixCombinations ( [ ] , [ { id : '1' } ] , [ ] ) ) . toEqual ( [ ] )
393
+ expect ( generateAllParamCombinations ( [ ] , [ { id : '1' } ] , [ ] ) ) . toEqual ( [ ] )
397
394
398
395
// Empty routeParams
399
- expect ( generateParamPrefixCombinations ( [ 'id' ] , [ ] , [ ] ) ) . toEqual ( [ ] )
396
+ expect ( generateAllParamCombinations ( [ 'id' ] , [ ] , [ ] ) ) . toEqual ( [ ] )
400
397
401
398
// Both empty
402
- expect ( generateParamPrefixCombinations ( [ ] , [ ] , [ ] ) ) . toEqual ( [ ] )
399
+ expect ( generateAllParamCombinations ( [ ] , [ ] , [ ] ) ) . toEqual ( [ ] )
403
400
} )
404
401
405
402
it ( 'should handle undefined parameters' , ( ) => {
@@ -409,7 +406,7 @@ describe('generateParamPrefixCombinations', () => {
409
406
{ id : '3' } , // missing name key
410
407
]
411
408
412
- const unique = generateParamPrefixCombinations ( [ 'id' , 'name' ] , params , [ ] )
409
+ const unique = generateAllParamCombinations ( [ 'id' , 'name' ] , params , [ ] )
413
410
414
411
expect ( unique ) . toEqual ( [
415
412
{ id : '1' } ,
@@ -426,7 +423,7 @@ describe('generateParamPrefixCombinations', () => {
426
423
{ lang : 'fr' } , // missing region and category
427
424
]
428
425
429
- const unique = generateParamPrefixCombinations (
426
+ const unique = generateAllParamCombinations (
430
427
[ 'lang' , 'region' , 'category' ] ,
431
428
params ,
432
429
[ ]
@@ -450,7 +447,7 @@ describe('generateParamPrefixCombinations', () => {
450
447
{ slug : 'U:undefined' } , // String that looks like undefined prefix
451
448
]
452
449
453
- const unique = generateParamPrefixCombinations ( [ 'slug' ] , params , [ ] )
450
+ const unique = generateAllParamCombinations ( [ 'slug' ] , params , [ ] )
454
451
455
452
expect ( unique ) . toEqual ( [
456
453
{ slug : [ 'foo' , 'bar' ] } ,
@@ -468,7 +465,7 @@ describe('generateParamPrefixCombinations', () => {
468
465
{ slug : [ 'foo' , 'bar|baz' ] } , // Array with pipe in element
469
466
]
470
467
471
- const unique = generateParamPrefixCombinations ( [ 'slug' ] , params , [ ] )
468
+ const unique = generateAllParamCombinations ( [ 'slug' ] , params , [ ] )
472
469
473
470
expect ( unique ) . toEqual ( [ { slug : 'foo|bar' } , { slug : [ 'foo' , 'bar|baz' ] } ] )
474
471
} )
@@ -480,7 +477,7 @@ describe('generateParamPrefixCombinations', () => {
480
477
{ a : '1' , b : '2' , c : '3' , d : '7' } ,
481
478
]
482
479
483
- const unique = generateParamPrefixCombinations (
480
+ const unique = generateAllParamCombinations (
484
481
[ 'a' , 'b' , 'c' , 'd' , 'e' ] ,
485
482
params ,
486
483
[ ]
@@ -505,7 +502,7 @@ describe('generateParamPrefixCombinations', () => {
505
502
{ lang : 'fr' , region : 'CA' , slug : 'about' } ,
506
503
]
507
504
508
- const unique = generateParamPrefixCombinations (
505
+ const unique = generateAllParamCombinations (
509
506
[ 'lang' , 'region' , 'slug' ] ,
510
507
params ,
511
508
[ 'lang' , 'region' ] // Root params
@@ -529,7 +526,7 @@ describe('generateParamPrefixCombinations', () => {
529
526
{ category : 'sports' , slug : 'news' } ,
530
527
]
531
528
532
- const unique = generateParamPrefixCombinations (
529
+ const unique = generateAllParamCombinations (
533
530
[ 'category' , 'slug' ] ,
534
531
params ,
535
532
[ ] // No root params
@@ -552,7 +549,7 @@ describe('generateParamPrefixCombinations', () => {
552
549
{ lang : 'fr' , page : 'home' } ,
553
550
]
554
551
555
- const unique = generateParamPrefixCombinations (
552
+ const unique = generateAllParamCombinations (
556
553
[ 'lang' , 'page' ] ,
557
554
params ,
558
555
[ 'lang' ] // Single root param
@@ -575,7 +572,7 @@ describe('generateParamPrefixCombinations', () => {
575
572
{ page : 'contact' } , // Missing lang root param
576
573
]
577
574
578
- const unique = generateParamPrefixCombinations (
575
+ const unique = generateAllParamCombinations (
579
576
[ 'lang' , 'page' ] ,
580
577
params ,
581
578
[ 'lang' ] // Root param
@@ -596,7 +593,7 @@ describe('generateParamPrefixCombinations', () => {
596
593
{ category : 'sports' , slug : 'news' } ,
597
594
]
598
595
599
- const unique = generateParamPrefixCombinations (
596
+ const unique = generateAllParamCombinations (
600
597
[ 'category' , 'slug' ] ,
601
598
params ,
602
599
[ 'lang' , 'region' ] // Root params not in route params
@@ -620,7 +617,7 @@ describe('generateParamPrefixCombinations', () => {
620
617
{ lang : 'en' , locale : 'us' } , // Missing slug parameter
621
618
]
622
619
623
- const unique = generateParamPrefixCombinations (
620
+ const unique = generateAllParamCombinations (
624
621
[ 'lang' , 'locale' , 'slug' ] , // All route params
625
622
params ,
626
623
[ 'lang' , 'locale' ] // Root params
@@ -637,7 +634,7 @@ describe('generateParamPrefixCombinations', () => {
637
634
// This might be what's happening for the [slug] route
638
635
const params : Params [ ] = [ ] // No generateStaticParams results
639
636
640
- const unique = generateParamPrefixCombinations (
637
+ const unique = generateAllParamCombinations (
641
638
[ 'lang' , 'locale' , 'slug' ] , // All route params
642
639
params ,
643
640
[ 'lang' , 'locale' ] // Root params
@@ -1027,3 +1024,73 @@ describe('generateRouteStaticParams', () => {
1027
1024
} )
1028
1025
} )
1029
1026
} )
1027
+
1028
+ describe ( 'calculateFallbackMode' , ( ) => {
1029
+ it ( 'should return NOT_FOUND when dynamic params are disabled' , ( ) => {
1030
+ const result = calculateFallbackMode ( false , [ ] , FallbackMode . PRERENDER )
1031
+
1032
+ expect ( result ) . toBe ( FallbackMode . NOT_FOUND )
1033
+ } )
1034
+
1035
+ it ( 'should return NOT_FOUND when dynamic params are disabled regardless of root params' , ( ) => {
1036
+ const result = calculateFallbackMode (
1037
+ false ,
1038
+ [ 'rootParam' ] ,
1039
+ FallbackMode . BLOCKING_STATIC_RENDER
1040
+ )
1041
+
1042
+ expect ( result ) . toBe ( FallbackMode . NOT_FOUND )
1043
+ } )
1044
+
1045
+ it ( 'should return BLOCKING_STATIC_RENDER when dynamic params are enabled and root params exist' , ( ) => {
1046
+ const result = calculateFallbackMode (
1047
+ true ,
1048
+ [ 'rootParam1' , 'rootParam2' ] ,
1049
+ FallbackMode . PRERENDER
1050
+ )
1051
+
1052
+ expect ( result ) . toBe ( FallbackMode . BLOCKING_STATIC_RENDER )
1053
+ } )
1054
+
1055
+ it ( 'should return base fallback mode when dynamic params are enabled and no root params' , ( ) => {
1056
+ const result = calculateFallbackMode ( true , [ ] , FallbackMode . PRERENDER )
1057
+
1058
+ expect ( result ) . toBe ( FallbackMode . PRERENDER )
1059
+ } )
1060
+
1061
+ it ( 'should return base fallback mode when dynamic params are enabled and empty root params' , ( ) => {
1062
+ const result = calculateFallbackMode (
1063
+ true ,
1064
+ [ ] ,
1065
+ FallbackMode . BLOCKING_STATIC_RENDER
1066
+ )
1067
+
1068
+ expect ( result ) . toBe ( FallbackMode . BLOCKING_STATIC_RENDER )
1069
+ } )
1070
+
1071
+ it ( 'should return NOT_FOUND when dynamic params are enabled but no base fallback mode provided' , ( ) => {
1072
+ const result = calculateFallbackMode ( true , [ ] , undefined )
1073
+
1074
+ expect ( result ) . toBe ( FallbackMode . NOT_FOUND )
1075
+ } )
1076
+
1077
+ it ( 'should prioritize root params over base fallback mode' , ( ) => {
1078
+ const result = calculateFallbackMode (
1079
+ true ,
1080
+ [ 'rootParam' ] ,
1081
+ FallbackMode . PRERENDER
1082
+ )
1083
+
1084
+ expect ( result ) . toBe ( FallbackMode . BLOCKING_STATIC_RENDER )
1085
+ } )
1086
+
1087
+ it ( 'should handle single root param correctly' , ( ) => {
1088
+ const result = calculateFallbackMode (
1089
+ true ,
1090
+ [ 'singleParam' ] ,
1091
+ FallbackMode . PRERENDER
1092
+ )
1093
+
1094
+ expect ( result ) . toBe ( FallbackMode . BLOCKING_STATIC_RENDER )
1095
+ } )
1096
+ } )
0 commit comments