Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 152a496

Browse files
committedFeb 28, 2025··
Define expire as number | undefined in CacheControl
1 parent b08a160 commit 152a496

File tree

9 files changed

+31
-23
lines changed

9 files changed

+31
-23
lines changed
 

Diff for: ‎packages/next/src/export/routes/app-page.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ export async function exportAppPage(
139139
const { metadata } = result
140140
const {
141141
flightData,
142-
cacheControl = { revalidate: false },
142+
cacheControl = { revalidate: false, expire: undefined },
143143
postponed,
144144
fetchTags,
145145
fetchMetrics,
@@ -298,7 +298,7 @@ export async function exportAppPage(
298298
})
299299
}
300300

301-
return { cacheControl: { revalidate: 0 }, fetchMetrics }
301+
return { cacheControl: { revalidate: 0, expire: undefined }, fetchMetrics }
302302
}
303303
}
304304

Diff for: ‎packages/next/src/export/routes/app-route.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,14 @@ export async function exportAppRoute(
114114
// unless specifically opted into
115115
experimental.dynamicIO !== true
116116
) {
117-
return { cacheControl: { revalidate: 0 } }
117+
return { cacheControl: { revalidate: 0, expire: undefined } }
118118
}
119119

120120
const response = await module.handle(request, context)
121121

122122
const isValidStatus = response.status < 400 || response.status === 404
123123
if (!isValidStatus) {
124-
return { cacheControl: { revalidate: 0 } }
124+
return { cacheControl: { revalidate: 0, expire: undefined } }
125125
}
126126

127127
const blob = await response.blob()
@@ -173,6 +173,6 @@ export async function exportAppRoute(
173173
throw err
174174
}
175175

176-
return { cacheControl: { revalidate: 0 } }
176+
return { cacheControl: { revalidate: 0, expire: undefined } }
177177
}
178178
}

Diff for: ‎packages/next/src/export/routes/pages.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,10 @@ export async function exportPagesPage(
219219

220220
return {
221221
ampValidations,
222-
cacheControl: metadata.cacheControl ?? { revalidate: false },
222+
cacheControl: metadata.cacheControl ?? {
223+
revalidate: false,
224+
expire: undefined,
225+
},
223226
ssgNotFound,
224227
}
225228
}

Diff for: ‎packages/next/src/server/app-render/app-render.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1433,7 +1433,7 @@ async function renderToHTMLOrFlightImpl(
14331433
// If force static is specifically set to false, we should not revalidate
14341434
// the page.
14351435
if (workStore.forceStatic === false || response.collectedRevalidate === 0) {
1436-
metadata.cacheControl = { revalidate: 0 }
1436+
metadata.cacheControl = { revalidate: 0, expire: undefined }
14371437
} else {
14381438
// Copy the cache control value onto the render result metadata.
14391439
metadata.cacheControl = {

Diff for: ‎packages/next/src/server/base-server.ts

+15-10
Original file line numberDiff line numberDiff line change
@@ -3118,7 +3118,7 @@ export default abstract class Server<
31183118
typeof postponed !== 'undefined'
31193119
) {
31203120
return {
3121-
cacheControl: { revalidate: 1 },
3121+
cacheControl: { revalidate: 1, expire: undefined },
31223122
isFallback: false,
31233123
value: {
31243124
kind: CachedRouteKind.PAGES,
@@ -3311,7 +3311,7 @@ export default abstract class Server<
33113311
// If this is a resume request in minimal mode it is streamed with dynamic
33123312
// content and should not be cached.
33133313
if (minimalPostponed) {
3314-
cacheControl = { revalidate: 0 }
3314+
cacheControl = { revalidate: 0, expire: undefined }
33153315
}
33163316

33173317
// If this is in minimal mode and this is a flight request that isn't a
@@ -3323,18 +3323,18 @@ export default abstract class Server<
33233323
!isPrefetchRSCRequest &&
33243324
isRoutePPREnabled
33253325
) {
3326-
cacheControl = { revalidate: 0 }
3326+
cacheControl = { revalidate: 0, expire: undefined }
33273327
} else if (!this.renderOpts.dev || (hasServerProps && !isNextDataRequest)) {
33283328
// If this is a preview mode request, we shouldn't cache it
33293329
if (isPreviewMode) {
3330-
cacheControl = { revalidate: 0 }
3330+
cacheControl = { revalidate: 0, expire: undefined }
33313331
}
33323332

33333333
// If this isn't SSG, then we should set change the header only if it is
33343334
// not set already.
33353335
else if (!isSSG) {
33363336
if (!res.getHeader('Cache-Control')) {
3337-
cacheControl = { revalidate: 0 }
3337+
cacheControl = { revalidate: 0, expire: undefined }
33383338
}
33393339
}
33403340

@@ -3350,9 +3350,10 @@ export default abstract class Server<
33503350
cacheControl = {
33513351
revalidate:
33523352
typeof notFoundRevalidate === 'undefined' ? 0 : notFoundRevalidate,
3353+
expire: undefined,
33533354
}
33543355
} else if (is500Page) {
3355-
cacheControl = { revalidate: 0 }
3356+
cacheControl = { revalidate: 0, expire: undefined }
33563357
} else if (cacheEntry.cacheControl) {
33573358
// If the cache entry has a cache control with a revalidate value that's
33583359
// a number, use it.
@@ -3372,7 +3373,7 @@ export default abstract class Server<
33723373
// Otherwise if the revalidate value is false, then we should use the
33733374
// cache time of one year.
33743375
else {
3375-
cacheControl = { revalidate: CACHE_ONE_YEAR }
3376+
cacheControl = { revalidate: CACHE_ONE_YEAR, expire: undefined }
33763377
}
33773378
}
33783379
}
@@ -3563,7 +3564,7 @@ export default abstract class Server<
35633564
// postponed state.
35643565
// TODO: distinguish `force-static` from pages with no postponed state (static)
35653566
cacheControl: isDynamicRSCRequest
3566-
? { revalidate: 0 }
3567+
? { revalidate: 0, expire: undefined }
35673568
: cacheEntry.cacheControl,
35683569
}
35693570
}
@@ -3607,7 +3608,11 @@ export default abstract class Server<
36073608
})
36083609
)
36093610

3610-
return { type: 'html', body, cacheControl: { revalidate: 0 } }
3611+
return {
3612+
type: 'html',
3613+
body,
3614+
cacheControl: { revalidate: 0, expire: undefined },
3615+
}
36113616
}
36123617

36133618
// This request has postponed, so let's create a new transformer that the
@@ -3654,7 +3659,7 @@ export default abstract class Server<
36543659
// We don't want to cache the response if it has postponed data because
36553660
// the response being sent to the client it's dynamic parts are streamed
36563661
// to the client on the same request.
3657-
cacheControl: { revalidate: 0 },
3662+
cacheControl: { revalidate: 0, expire: undefined },
36583663
}
36593664
} else if (isNextDataRequest) {
36603665
return {

Diff for: ‎packages/next/src/server/image-optimizer.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ export class ImageOptimizerCache {
416416
revalidateAfter:
417417
Math.max(maxAge, this.nextConfig.images.minimumCacheTTL) * 1000 +
418418
Date.now(),
419-
cacheControl: { revalidate: maxAge },
419+
cacheControl: { revalidate: maxAge, expire: undefined },
420420
isStale: now > expireAt,
421421
isFallback: false,
422422
}

Diff for: ‎packages/next/src/server/lib/cache-control.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export type Revalidate = number | false
1111

1212
export interface CacheControl {
1313
revalidate: Revalidate
14-
expire?: number
14+
expire: number | undefined
1515
}
1616

1717
export function getCacheControlHeader({

Diff for: ‎packages/next/src/server/next-server.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,7 @@ export default class NextNodeServer extends BaseServer<
957957
upstreamEtag,
958958
},
959959
isFallback: false,
960-
cacheControl: { revalidate: maxAge },
960+
cacheControl: { revalidate: maxAge, expire: undefined },
961961
}
962962
},
963963
{

Diff for: ‎packages/next/src/server/render.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1049,8 +1049,8 @@ export async function renderToHTMLImpl(
10491049
'props' in data ? data.props : undefined
10501050
)
10511051

1052-
// pass up revalidate and props for export
1053-
metadata.cacheControl = { revalidate }
1052+
// pass up cache control and props for export
1053+
metadata.cacheControl = { revalidate, expire: undefined }
10541054
metadata.pageData = props
10551055

10561056
// this must come after revalidate is added to renderResultMeta
@@ -1123,7 +1123,7 @@ export async function renderToHTMLImpl(
11231123
})
11241124
)
11251125
canAccessRes = false
1126-
metadata.cacheControl = { revalidate: 0 }
1126+
metadata.cacheControl = { revalidate: 0, expire: undefined }
11271127
} catch (serverSidePropsError: any) {
11281128
// remove not found error code to prevent triggering legacy
11291129
// 404 rendering

0 commit comments

Comments
 (0)
Please sign in to comment.