File tree 3 files changed +29
-3
lines changed
fixtures/server-components/app/api/static/[slug]
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 {
159
159
160
160
console . debug ( `[NetlifyCacheHandler.set]: ${ key } ` )
161
161
162
+ let value = data
163
+
162
164
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
+ }
165
171
}
166
172
167
173
await this . blobStore . setJSON ( blobKey , {
168
174
lastModified,
169
- value : data ,
175
+ value,
170
176
} )
171
177
172
178
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', () => {
313
313
expect ( blobEntries . map ( ( { key } ) => decodeBlobKey ( key ) ) . sort ( ) ) . toEqual ( [
314
314
'/404' ,
315
315
'/api/revalidate-handler' ,
316
+ '/api/static/first' ,
317
+ '/api/static/second' ,
316
318
'/index' ,
317
319
'/revalidate-fetch' ,
318
320
'/static-fetch-1' ,
@@ -444,4 +446,13 @@ describe('route', () => {
444
446
) . toBe ( 1 )
445
447
ctx . blobServerGetSpy . mockClear ( )
446
448
} )
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
+ } )
447
458
} )
You can’t perform that action at this time.
0 commit comments