From fe074682acda0794a565d8d6be659b0c66e7ae82 Mon Sep 17 00:00:00 2001 From: Michal Piechowiak Date: Mon, 23 Jun 2025 17:13:28 +0200 Subject: [PATCH 1/2] fix: handle shared-cache-controls rename --- src/run/handlers/cache.cts | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/run/handlers/cache.cts b/src/run/handlers/cache.cts index bfb86555ba..bfd7815635 100644 --- a/src/run/handlers/cache.cts +++ b/src/run/handlers/cache.cts @@ -200,15 +200,28 @@ export class NetlifyCacheHandler implements CacheHandlerForMultipleVersions { try { const prerenderManifest = await this.getPrerenderManifest(this.options.serverDistDir) if (typeof cacheControl !== 'undefined') { - // instead of `revalidate` property, we might get `cacheControls` ( https://github.com/vercel/next.js/pull/76207 ) - // then we need to keep track of revalidate values via SharedCacheControls - const { SharedCacheControls } = await import( - // @ts-expect-error supporting multiple next version, this module is not resolvable with currently used dev dependency - // eslint-disable-next-line import/no-unresolved, n/no-missing-import - 'next/dist/server/lib/incremental-cache/shared-cache-controls.js' - ) - const sharedCacheControls = new SharedCacheControls(prerenderManifest) - sharedCacheControls.set(key, cacheControl) + try { + // instead of `revalidate` property, we might get `cacheControls` ( https://github.com/vercel/next.js/pull/76207 ) + // then we need to keep track of revalidate values via SharedCacheControls + + // https://github.com/vercel/next.js/pull/80588 renamed shared-cache-controls module + const { SharedCacheControls } = await import( + // @ts-expect-error supporting multiple next version, this module is not resolvable with currently used dev dependency + // eslint-disable-next-line import/no-unresolved, n/no-missing-import + 'next/dist/server/lib/incremental-cache/shared-cache-controls.external.js' + ) + const sharedCacheControls = new SharedCacheControls(prerenderManifest) + sharedCacheControls.set(key, cacheControl) + } catch { + // attempting to use shared-cache-controls before https://github.com/vercel/next.js/pull/80588 was merged + const { SharedCacheControls } = await import( + // @ts-expect-error supporting multiple next version, this module is not resolvable with currently used dev dependency + // eslint-disable-next-line import/no-unresolved, n/no-missing-import + 'next/dist/server/lib/incremental-cache/shared-cache-controls.js' + ) + const sharedCacheControls = new SharedCacheControls(prerenderManifest) + sharedCacheControls.set(key, cacheControl) + } } else if (typeof revalidate === 'number' || revalidate === false) { // if we don't get cacheControls, but we still get revalidate, it should mean we are before // https://github.com/vercel/next.js/pull/76207 From fab585a462cfb87fb0022bcb198fefadcb39586c Mon Sep 17 00:00:00 2001 From: Michal Piechowiak Date: Tue, 24 Jun 2025 10:45:38 +0200 Subject: [PATCH 2/2] test: make sure fixture prerender non-default locale as well --- .../page-router-base-path-i18n/pages/fallback-true/[slug].js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/fixtures/page-router-base-path-i18n/pages/fallback-true/[slug].js b/tests/fixtures/page-router-base-path-i18n/pages/fallback-true/[slug].js index 5e85c57657..7f241bce57 100644 --- a/tests/fixtures/page-router-base-path-i18n/pages/fallback-true/[slug].js +++ b/tests/fixtures/page-router-base-path-i18n/pages/fallback-true/[slug].js @@ -27,7 +27,8 @@ export async function getStaticProps({ params }) { } } -export const getStaticPaths = () => { +/** @type {import('next').GetStaticPaths} */ +export const getStaticPaths = ({ locales }) => { return { paths: [ { @@ -35,7 +36,7 @@ export const getStaticPaths = () => { slug: 'prerendered', }, }, - ], + ].flatMap((pathDescription) => locales.map((locale) => ({ ...pathDescription, locale }))), fallback: true, } }