File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed
open-next/src/core/routing
tests-unit/tests/core/routing Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -243,7 +243,11 @@ export function fixCacheHeaderForHtmlPages(
243
243
const localizedPath = localizePath ( internalEvent ) ;
244
244
// WORKAROUND: `NextServer` does not set cache headers for HTML pages
245
245
// https://opennext.js.org/aws/v2/advanced/workaround#workaround-nextserver-does-not-set-cache-headers-for-html-pages
246
- if ( HtmlPages . includes ( localizedPath ) ) {
246
+ // We need to not cache if the request contains an `x-middleware-prefetch` header
247
+ if (
248
+ HtmlPages . includes ( localizedPath ) &&
249
+ ! internalEvent . headers [ "x-middleware-prefetch" ]
250
+ ) {
247
251
headers [ CommonHeaders . CACHE_CONTROL ] =
248
252
"public, max-age=0, s-maxage=31536000, must-revalidate" ;
249
253
}
Original file line number Diff line number Diff line change @@ -487,6 +487,7 @@ describe("fixCacheHeaderForHtmlPages", () => {
487
487
fixCacheHeaderForHtmlPages (
488
488
{
489
489
rawPath : "/my-html-page" ,
490
+ headers : { } ,
490
491
} ,
491
492
headers ,
492
493
) ;
@@ -496,6 +497,23 @@ describe("fixCacheHeaderForHtmlPages", () => {
496
497
) ;
497
498
} ) ;
498
499
500
+ it ( "should not add cache-control header for html page but with an `x-middleware-prefetch` header" , ( ) => {
501
+ const headers : Record < string , string > = { } ;
502
+ config . HtmlPages . push ( "/my-html-page" ) ;
503
+
504
+ fixCacheHeaderForHtmlPages (
505
+ {
506
+ rawPath : "/my-html-page" ,
507
+ headers : {
508
+ "x-middleware-prefetch" : "1" ,
509
+ } ,
510
+ } ,
511
+ headers ,
512
+ ) ;
513
+
514
+ expect ( headers ) . not . toHaveProperty ( "cache-control" ) ;
515
+ } ) ;
516
+
499
517
it ( "should not add cache-control header for non html page" , ( ) => {
500
518
const headers : Record < string , string > = { } ;
501
519
You can’t perform that action at this time.
0 commit comments