@@ -670,10 +670,32 @@ describe('<Link prefetch={true}> (runtime prefetch)', () => {
670
670
} )
671
671
672
672
describe ( 'cache stale time handling' , ( ) => {
673
- it ( 'includes short-lived public caches with a long enough staleTime' , async ( ) => {
674
- // If a cache has an expiration time under 5min (DYNAMIC_EXPIRE), we omit it from static prerenders.
675
- // However, it should still be included in a runtime prefetch if it's stale time is above 30s. (RUNTIME_PREFETCH_DYNAMIC_STALE)
676
-
673
+ it . each ( [
674
+ {
675
+ // If a cache has an expiration time under 5min (DYNAMIC_EXPIRE), we omit it from static prerenders.
676
+ // However, it should still be included in a runtime prefetch if its stale time is >=30s. (RUNTIME_PREFETCH_DYNAMIC_STALE)
677
+ description :
678
+ 'includes short-lived public caches with a long enough staleTime' ,
679
+ staticContent : 'This page uses a short-lived public cache' ,
680
+ path : '/caches/public-short-expire-long-stale' ,
681
+ } ,
682
+ {
683
+ // If a cache has an expiration time under 5min (DYNAMIC_EXPIRE), we omit it from static prerenders.
684
+ // However, it should still be included in a runtime prefetch if its stale time is >=30s. (RUNTIME_PREFETCH_DYNAMIC_STALE)
685
+ // `cacheLife("seconds")` is deliberately set to have a stale time of 30s to stay above this treshold.
686
+ description : 'includes public caches with cacheLife("seconds")' ,
687
+ staticContent : 'This page uses a short-lived public cache' ,
688
+ path : '/caches/public-seconds' ,
689
+ } ,
690
+ {
691
+ // A Private cache will always be omitted from static prerenders.
692
+ // However, it should still be included in a runtime prefetch if its stale time is >=30s. (RUNTIME_PREFETCH_DYNAMIC_STALE)
693
+ // `cacheLife("seconds")` is deliberately set to have a stale time of 30s to stay above this treshold.
694
+ description : 'includes private caches with cacheLife("seconds")' ,
695
+ staticContent : 'This page uses a short-lived private cache' ,
696
+ path : '/caches/private-seconds' ,
697
+ } ,
698
+ ] ) ( '$description' , async ( { path, staticContent } ) => {
677
699
let page : Playwright . Page
678
700
const browser = await next . browser ( '/' , {
679
701
beforePageLoad ( p : Playwright . Page ) {
@@ -682,22 +704,20 @@ describe('<Link prefetch={true}> (runtime prefetch)', () => {
682
704
} )
683
705
const act = createRouterAct ( page )
684
706
685
- const STATIC_CONTENT = 'This page uses a short-lived public cache'
686
707
const DYNAMICALLY_PREFETCHABLE_CONTENT = 'Short-lived cached content'
687
708
688
709
// Reveal the link to trigger a static prefetch
689
710
await act ( async ( ) => {
690
711
const linkToggle = await browser . elementByCss (
691
- `input[data-prefetch="auto"][data-link-accordion="/caches/public-short-expire-long-stale "]`
712
+ `input[data-prefetch="auto"][data-link-accordion="${ path } "]`
692
713
)
693
714
await linkToggle . click ( )
694
715
} , [
695
716
// Should include the static shell
696
717
{
697
- includes : STATIC_CONTENT ,
718
+ includes : staticContent ,
698
719
} ,
699
720
// Should not include the short-lived cache
700
- // (We set the `expire` value to be under 5min, so it will be excluded from prerenders)
701
721
{
702
722
includes : DYNAMICALLY_PREFETCHABLE_CONTENT ,
703
723
block : 'reject' ,
@@ -707,12 +727,11 @@ describe('<Link prefetch={true}> (runtime prefetch)', () => {
707
727
// Reveal the link to trigger a runtime prefetch
708
728
await act ( async ( ) => {
709
729
const linkToggle = await browser . elementByCss (
710
- `input[data-prefetch="runtime"][data-link-accordion="/caches/public-short-expire-long-stale "]`
730
+ `input[data-prefetch="runtime"][data-link-accordion="${ path } "]`
711
731
)
712
732
await linkToggle . click ( )
713
733
} , [
714
734
// Should include the short-lived cache
715
- // (We set `stale` to be above 30s, which means it shouldn't be omitted)
716
735
{
717
736
includes : DYNAMICALLY_PREFETCHABLE_CONTENT ,
718
737
} ,
@@ -721,9 +740,7 @@ describe('<Link prefetch={true}> (runtime prefetch)', () => {
721
740
// Navigate to the page. We didn't include any uncached IO, so the page is fully prefetched,
722
741
// and this shouldn't issue any more requests
723
742
await act ( async ( ) => {
724
- await browser
725
- . elementByCss ( `a[href="/caches/public-short-expire-long-stale"]` )
726
- . click ( )
743
+ await browser . elementByCss ( `a[href="${ path } "]` ) . click ( )
727
744
} , 'no-requests' )
728
745
729
746
expect ( await browser . elementByCss ( 'main' ) . text ( ) ) . toInclude (
0 commit comments