Skip to content

Commit a4a03e1

Browse files
authored
fix: handle shared-cache-controls rename (#2974)
* fix: handle shared-cache-controls rename * test: make sure fixture prerender non-default locale as well
1 parent 5f86878 commit a4a03e1

File tree

2 files changed

+25
-11
lines changed
  • src/run/handlers
  • tests/fixtures/page-router-base-path-i18n/pages/fallback-true

2 files changed

+25
-11
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

tests/fixtures/page-router-base-path-i18n/pages/fallback-true/[slug].js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,16 @@ export async function getStaticProps({ params }) {
2727
}
2828
}
2929

30-
export const getStaticPaths = () => {
30+
/** @type {import('next').GetStaticPaths} */
31+
export const getStaticPaths = ({ locales }) => {
3132
return {
3233
paths: [
3334
{
3435
params: {
3536
slug: 'prerendered',
3637
},
3738
},
38-
],
39+
].flatMap((pathDescription) => locales.map((locale) => ({ ...pathDescription, locale }))),
3940
fallback: true,
4041
}
4142
}

0 commit comments

Comments
 (0)