File tree Expand file tree Collapse file tree 3 files changed +29
-3
lines changed
fixtures/server-components/app/api/static/[slug] Expand file tree Collapse file tree 3 files changed +29
-3
lines changed Original file line number Diff line number Diff line change @@ -159,14 +159,20 @@ export class NetlifyCacheHandler implements CacheHandler {
159159
160160 console . debug ( `[NetlifyCacheHandler.set]: ${ key } ` )
161161
162+ let value = data
163+
162164 if ( data ?. kind === 'ROUTE' ) {
163- // @ts -expect-error gotta find a better solution for this
164- data . body = data . body . toString ( 'base64' )
165+ // don't mutate data, as it's used for the initial response - instead create a new object
166+ value = {
167+ ...data ,
168+ // @ts -expect-error gotta find a better solution for this
169+ body : data . body . toString ( 'base64' ) ,
170+ }
165171 }
166172
167173 await this . blobStore . setJSON ( blobKey , {
168174 lastModified,
169- value : data ,
175+ value,
170176 } )
171177
172178 if ( data ?. kind === 'PAGE' ) {
Original file line number Diff line number Diff line change 1+ import { NextRequest , NextResponse } from 'next/server'
2+
3+ export function generateStaticParams ( ) {
4+ return [ { slug : 'first' } , { slug : 'second' } ]
5+ }
6+
7+ export const GET = ( _req : NextRequest , { params } ) => {
8+ return NextResponse . json ( { params } )
9+ }
Original file line number Diff line number Diff line change @@ -313,6 +313,8 @@ describe('plugin', () => {
313313 expect ( blobEntries . map ( ( { key } ) => decodeBlobKey ( key ) ) . sort ( ) ) . toEqual ( [
314314 '/404' ,
315315 '/api/revalidate-handler' ,
316+ '/api/static/first' ,
317+ '/api/static/second' ,
316318 '/index' ,
317319 '/revalidate-fetch' ,
318320 '/static-fetch-1' ,
@@ -444,4 +446,13 @@ describe('route', () => {
444446 ) . toBe ( 1 )
445447 ctx . blobServerGetSpy . mockClear ( )
446448 } )
449+
450+ test < FixtureTestContext > ( 'cacheable route handler response not produced at build is served correctly' , async ( ctx ) => {
451+ await createFixture ( 'server-components' , ctx )
452+ await runPlugin ( ctx )
453+
454+ const call2 = await invokeFunction ( ctx , { url : '/api/static/not-in-generateStaticParams' } )
455+
456+ expect ( call2 . body ) . toBe ( '{"params":{"slug":"not-in-generateStaticParams"}}' )
457+ } )
447458} )
You can’t perform that action at this time.
0 commit comments