@@ -1227,7 +1227,6 @@ type GenerateParamsResult = {
1227
1227
config ?: AppConfig
1228
1228
isDynamicSegment ?: boolean
1229
1229
segmentPath : string
1230
- getStaticPaths ?: GetStaticPaths
1231
1230
generateStaticParams ?: GenerateStaticParams
1232
1231
isLayout ?: boolean
1233
1232
}
@@ -1306,7 +1305,7 @@ export async function collectGenerateParams(tree: LoaderTree) {
1306
1305
1307
1306
const isDynamicSegment = / ^ \[ .+ \] $ / . test ( page )
1308
1307
1309
- const { generateStaticParams, getStaticPaths } = mod || { }
1308
+ const { generateStaticParams } = mod || { }
1310
1309
1311
1310
if ( isDynamicSegment && isClientComponent && generateStaticParams ) {
1312
1311
throw new Error (
@@ -1323,20 +1322,14 @@ export async function collectGenerateParams(tree: LoaderTree) {
1323
1322
isDynamicSegment,
1324
1323
segmentPath,
1325
1324
config,
1326
- getStaticPaths : ! isClientComponent ? getStaticPaths : undefined ,
1327
1325
generateStaticParams : ! isClientComponent
1328
1326
? generateStaticParams
1329
1327
: undefined ,
1330
1328
}
1331
1329
1332
1330
// If the configuration contributes to the static generation, then add it
1333
1331
// to the list.
1334
- if (
1335
- result . config ||
1336
- result . generateStaticParams ||
1337
- result . getStaticPaths ||
1338
- isDynamicSegment
1339
- ) {
1332
+ if ( result . config || result . generateStaticParams || isDynamicSegment ) {
1340
1333
generateParams . push ( result )
1341
1334
}
1342
1335
@@ -1431,145 +1424,131 @@ export async function buildAppStaticPaths({
1431
1424
} ,
1432
1425
} ,
1433
1426
async ( ) : Promise < PartialStaticPathsResult > => {
1434
- const pageEntry = generateParams [ generateParams . length - 1 ]
1427
+ let hadAllParamsGenerated = false
1435
1428
1436
- // if the page has legacy getStaticPaths we call it like normal
1437
- if ( typeof pageEntry ?. getStaticPaths === 'function' ) {
1438
- return buildStaticPaths ( {
1439
- page,
1440
- configFileName,
1441
- getStaticPaths : pageEntry . getStaticPaths ,
1442
- } )
1443
- } else {
1444
- // if generateStaticParams is being used we iterate over them
1445
- // collecting them from each level
1446
- let hadAllParamsGenerated = false
1447
-
1448
- const buildParams = async (
1449
- paramsItems : Params [ ] = [ { } ] ,
1450
- idx = 0
1451
- ) : Promise < Params [ ] > => {
1452
- const current = generateParams [ idx ]
1453
-
1454
- if ( idx === generateParams . length ) {
1455
- return paramsItems
1456
- }
1429
+ const buildParams = async (
1430
+ paramsItems : Params [ ] = [ { } ] ,
1431
+ idx = 0
1432
+ ) : Promise < Params [ ] > => {
1433
+ const current = generateParams [ idx ]
1457
1434
1458
- if (
1459
- typeof current . generateStaticParams !== 'function' &&
1460
- idx < generateParams . length
1461
- ) {
1462
- if ( current . isDynamicSegment ) {
1463
- // This dynamic level has no generateStaticParams so we change
1464
- // this flag to false, but it could be covered by a later
1465
- // generateStaticParams so it could be set back to true.
1466
- hadAllParamsGenerated = false
1467
- }
1468
- return buildParams ( paramsItems , idx + 1 )
1435
+ if ( idx === generateParams . length ) {
1436
+ return paramsItems
1437
+ }
1438
+
1439
+ if (
1440
+ typeof current . generateStaticParams !== 'function' &&
1441
+ idx < generateParams . length
1442
+ ) {
1443
+ if ( current . isDynamicSegment ) {
1444
+ // This dynamic level has no generateStaticParams so we change
1445
+ // this flag to false, but it could be covered by a later
1446
+ // generateStaticParams so it could be set back to true.
1447
+ hadAllParamsGenerated = false
1469
1448
}
1470
- hadAllParamsGenerated = true
1449
+ return buildParams ( paramsItems , idx + 1 )
1450
+ }
1451
+ hadAllParamsGenerated = true
1471
1452
1472
- const newParams : Params [ ] = [ ]
1453
+ const newParams : Params [ ] = [ ]
1473
1454
1474
- if ( current . generateStaticParams ) {
1475
- const store = ComponentMod . staticGenerationAsyncStorage . getStore ( )
1455
+ if ( current . generateStaticParams ) {
1456
+ const store = ComponentMod . staticGenerationAsyncStorage . getStore ( )
1476
1457
1477
- if ( store ) {
1478
- if ( typeof current ?. config ?. fetchCache !== 'undefined' ) {
1479
- store . fetchCache = current . config . fetchCache
1480
- }
1481
- if ( typeof current ?. config ?. revalidate !== 'undefined' ) {
1482
- store . revalidate = current . config . revalidate
1483
- }
1484
- if ( current ?. config ?. dynamic === 'force-dynamic' ) {
1485
- store . forceDynamic = true
1486
- }
1458
+ if ( store ) {
1459
+ if ( typeof current ?. config ?. fetchCache !== 'undefined' ) {
1460
+ store . fetchCache = current . config . fetchCache
1487
1461
}
1488
-
1489
- for ( const params of paramsItems ) {
1490
- const result = await current . generateStaticParams ( {
1491
- params,
1492
- } )
1493
-
1494
- // TODO: validate the result is valid here or wait for buildStaticPaths to validate?
1495
- for ( const item of result ) {
1496
- newParams . push ( { ...params , ...item } )
1497
- }
1462
+ if ( typeof current ?. config ?. revalidate !== 'undefined' ) {
1463
+ store . revalidate = current . config . revalidate
1464
+ }
1465
+ if ( current ?. config ?. dynamic === 'force-dynamic' ) {
1466
+ store . forceDynamic = true
1498
1467
}
1499
1468
}
1500
1469
1501
- if ( idx < generateParams . length ) {
1502
- return buildParams ( newParams , idx + 1 )
1470
+ for ( const params of paramsItems ) {
1471
+ const result = await current . generateStaticParams ( {
1472
+ params,
1473
+ } )
1474
+
1475
+ // TODO: validate the result is valid here or wait for buildStaticPaths to validate?
1476
+ for ( const item of result ) {
1477
+ newParams . push ( { ...params , ...item } )
1478
+ }
1503
1479
}
1480
+ }
1504
1481
1505
- return newParams
1482
+ if ( idx < generateParams . length ) {
1483
+ return buildParams ( newParams , idx + 1 )
1506
1484
}
1507
1485
1508
- const builtParams = await buildParams ( )
1486
+ return newParams
1487
+ }
1509
1488
1510
- if (
1511
- generateParams . some (
1512
- ( generate ) => generate . config ?. dynamicParams === true
1513
- ) &&
1514
- nextConfigOutput === 'export'
1515
- ) {
1516
- throw new Error (
1517
- '"dynamicParams: true" cannot be used with "output: export". See more info here: https://nextjs.org/docs/app/building-your-application/deploying/static-exports'
1518
- )
1519
- }
1489
+ const builtParams = await buildParams ( )
1520
1490
1521
- // TODO: dynamic params should be allowed to be granular per segment but
1522
- // we need additional information stored/leveraged in the prerender
1523
- // manifest to allow this behavior.
1524
- const dynamicParams = generateParams . every (
1525
- ( param ) => param . config ?. dynamicParams !== false
1491
+ if (
1492
+ generateParams . some (
1493
+ ( generate ) => generate . config ?. dynamicParams === true
1494
+ ) &&
1495
+ nextConfigOutput === 'export'
1496
+ ) {
1497
+ throw new Error (
1498
+ '"dynamicParams: true" cannot be used with "output: export". See more info here: https://nextjs.org/docs/app/building-your-application/deploying/static-exports'
1526
1499
)
1500
+ }
1527
1501
1528
- const isProduction = process . env . NODE_ENV === 'production'
1502
+ // TODO: dynamic params should be allowed to be granular per segment but
1503
+ // we need additional information stored/leveraged in the prerender
1504
+ // manifest to allow this behavior.
1505
+ const dynamicParams = generateParams . every (
1506
+ ( param ) => param . config ?. dynamicParams !== false
1507
+ )
1529
1508
1530
- const supportsStaticGeneration = hadAllParamsGenerated || isProduction
1509
+ const isProduction = process . env . NODE_ENV === 'production'
1531
1510
1532
- const supportsPPRFallbacks =
1533
- isRoutePPREnabled && isAppPPRFallbacksEnabled
1511
+ const supportsStaticGeneration = hadAllParamsGenerated || isProduction
1534
1512
1535
- const fallbackMode = dynamicParams
1536
- ? supportsStaticGeneration
1537
- ? supportsPPRFallbacks
1538
- ? FallbackMode . PRERENDER
1539
- : FallbackMode . BLOCKING_STATIC_RENDER
1540
- : undefined
1541
- : FallbackMode . NOT_FOUND
1513
+ const supportsPPRFallbacks = isRoutePPREnabled && isAppPPRFallbacksEnabled
1542
1514
1543
- let result : PartialStaticPathsResult = {
1544
- fallbackMode,
1545
- prerenderedRoutes : undefined ,
1546
- }
1515
+ const fallbackMode = dynamicParams
1516
+ ? supportsStaticGeneration
1517
+ ? supportsPPRFallbacks
1518
+ ? FallbackMode . PRERENDER
1519
+ : FallbackMode . BLOCKING_STATIC_RENDER
1520
+ : undefined
1521
+ : FallbackMode . NOT_FOUND
1547
1522
1548
- if ( hadAllParamsGenerated && fallbackMode ) {
1549
- result = await buildStaticPaths ( {
1550
- staticPathsResult : {
1551
- fallback : fallbackModeToStaticPathsResult ( fallbackMode ) ,
1552
- paths : builtParams . map ( ( params ) => ( { params } ) ) ,
1553
- } ,
1554
- page,
1555
- configFileName,
1556
- appDir : true ,
1557
- } )
1558
- }
1523
+ let result : PartialStaticPathsResult = {
1524
+ fallbackMode,
1525
+ prerenderedRoutes : undefined ,
1526
+ }
1559
1527
1560
- // If the fallback mode is a prerender, we want to include the dynamic
1561
- // route in the prerendered routes too.
1562
- if ( isRoutePPREnabled && isAppPPRFallbacksEnabled ) {
1563
- result . prerenderedRoutes ??= [ ]
1564
- result . prerenderedRoutes . unshift ( {
1565
- path : page ,
1566
- encoded : page ,
1567
- fallbackRouteParams : getParamKeys ( page ) ,
1568
- } )
1569
- }
1528
+ if ( hadAllParamsGenerated && fallbackMode ) {
1529
+ result = await buildStaticPaths ( {
1530
+ staticPathsResult : {
1531
+ fallback : fallbackModeToStaticPathsResult ( fallbackMode ) ,
1532
+ paths : builtParams . map ( ( params ) => ( { params } ) ) ,
1533
+ } ,
1534
+ page,
1535
+ configFileName,
1536
+ appDir : true ,
1537
+ } )
1538
+ }
1570
1539
1571
- return result
1540
+ // If the fallback mode is a prerender, we want to include the dynamic
1541
+ // route in the prerendered routes too.
1542
+ if ( isRoutePPREnabled && isAppPPRFallbacksEnabled ) {
1543
+ result . prerenderedRoutes ??= [ ]
1544
+ result . prerenderedRoutes . unshift ( {
1545
+ path : page ,
1546
+ encoded : page ,
1547
+ fallbackRouteParams : getParamKeys ( page ) ,
1548
+ } )
1572
1549
}
1550
+
1551
+ return result
1573
1552
}
1574
1553
)
1575
1554
}
0 commit comments