@@ -23,7 +23,7 @@ import { useRouteAnnouncer } from '#app/composables/route-announcer'
2323import { encodeRoutePath , encodeURL , resolveRouteObject } from '#app/composables/router'
2424import { useRuntimeHook } from '#app/composables/runtime-hook'
2525
26- import { shouldLoadPayload } from '#app/composables/payload'
26+ import { loadPayload , shouldLoadPayload } from '#app/composables/payload'
2727import { NuxtPage } from '#components'
2828import { isTestingAppManifest } from '../matrix'
2929
@@ -34,6 +34,12 @@ registerEndpoint('/api/test', defineEventHandler(event => ({
3434 headers : Object . fromEntries ( event . headers . entries ( ) ) ,
3535} ) ) )
3636
37+ // the test environment builds with `ssr: false`, which disables payload extraction
38+ vi . mock ( '#build/nuxt.config.mjs' , async importOriginal => ( {
39+ ...await importOriginal < Record < string , unknown > > ( ) ,
40+ payloadExtraction : true ,
41+ } ) )
42+
3743describe ( 'app config' , ( ) => {
3844 it ( 'can be updated' , ( ) => {
3945 const appConfig = useAppConfig ( )
@@ -440,6 +446,9 @@ describe.skipIf(!isTestingAppManifest)('app manifests', () => {
440446 },
441447 },
442448 "wildcard": {
449+ "/isr": {
450+ "isr": 60,
451+ },
443452 "/pre": {
444453 "prerender": true,
445454 },
@@ -513,6 +522,20 @@ describe('compiled route rules', () => {
513522 const shouldLoadRedirect = await shouldLoadPayload ( '/pre/test' )
514523 expect ( shouldLoadRedirect ) . toBe ( false )
515524 } )
525+
526+ it ( 'should only use `force-cache` for immutable prerendered payloads' , async ( ) => {
527+ const fetchSpy = vi . spyOn ( globalThis , 'fetch' ) . mockImplementation ( ( ) => Promise . resolve ( new Response ( '[{"data":1},{}]' ) ) )
528+ try {
529+ await loadPayload ( '/pre/thing' )
530+ expect ( fetchSpy . mock . calls [ 0 ] ! [ 1 ] ) . toMatchObject ( { cache : 'force-cache' } )
531+
532+ // cached (isr/swr/cache) payloads can change within a deploy, so the browser cache must be revalidated
533+ await loadPayload ( '/isr/thing' )
534+ expect ( fetchSpy . mock . calls [ 1 ] ! [ 1 ] ) . toMatchObject ( { cache : 'default' } )
535+ } finally {
536+ fetchSpy . mockRestore ( )
537+ }
538+ } )
516539} )
517540
518541describe ( 'useRuntimeHook' , ( ) => {
0 commit comments