Skip to content

Commit fe07468

Browse files
committed
fix: handle shared-cache-controls rename
1 parent 5f86878 commit fe07468

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

src/run/handlers/cache.cts

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -200,15 +200,28 @@ export class NetlifyCacheHandler implements CacheHandlerForMultipleVersions {
200200
try {
201201
const prerenderManifest = await this.getPrerenderManifest(this.options.serverDistDir)
202202
if (typeof cacheControl !== 'undefined') {
203-
// instead of `revalidate` property, we might get `cacheControls` ( https://github.com/vercel/next.js/pull/76207 )
204-
// then we need to keep track of revalidate values via SharedCacheControls
205-
const { SharedCacheControls } = await import(
206-
// @ts-expect-error supporting multiple next version, this module is not resolvable with currently used dev dependency
207-
// eslint-disable-next-line import/no-unresolved, n/no-missing-import
208-
'next/dist/server/lib/incremental-cache/shared-cache-controls.js'
209-
)
210-
const sharedCacheControls = new SharedCacheControls(prerenderManifest)
211-
sharedCacheControls.set(key, cacheControl)
203+
try {
204+
// instead of `revalidate` property, we might get `cacheControls` ( https://github.com/vercel/next.js/pull/76207 )
205+
// then we need to keep track of revalidate values via SharedCacheControls
206+
207+
// https://github.com/vercel/next.js/pull/80588 renamed shared-cache-controls module
208+
const { SharedCacheControls } = await import(
209+
// @ts-expect-error supporting multiple next version, this module is not resolvable with currently used dev dependency
210+
// eslint-disable-next-line import/no-unresolved, n/no-missing-import
211+
'next/dist/server/lib/incremental-cache/shared-cache-controls.external.js'
212+
)
213+
const sharedCacheControls = new SharedCacheControls(prerenderManifest)
214+
sharedCacheControls.set(key, cacheControl)
215+
} catch {
216+
// attempting to use shared-cache-controls before https://github.com/vercel/next.js/pull/80588 was merged
217+
const { SharedCacheControls } = await import(
218+
// @ts-expect-error supporting multiple next version, this module is not resolvable with currently used dev dependency
219+
// eslint-disable-next-line import/no-unresolved, n/no-missing-import
220+
'next/dist/server/lib/incremental-cache/shared-cache-controls.js'
221+
)
222+
const sharedCacheControls = new SharedCacheControls(prerenderManifest)
223+
sharedCacheControls.set(key, cacheControl)
224+
}
212225
} else if (typeof revalidate === 'number' || revalidate === false) {
213226
// if we don't get cacheControls, but we still get revalidate, it should mean we are before
214227
// https://github.com/vercel/next.js/pull/76207

0 commit comments

Comments
 (0)