Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix: handle shared-cache-controls rename #2974

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions src/run/handlers/cache.cts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,16 @@ export async function getStaticProps({ params }) {
}
}

export const getStaticPaths = () => {
/** @type {import('next').GetStaticPaths} */
export const getStaticPaths = ({ locales }) => {
return {
paths: [
{
params: {
slug: 'prerendered',
},
},
],
].flatMap((pathDescription) => locales.map((locale) => ({ ...pathDescription, locale }))),
Comment on lines +30 to +39
Copy link
Contributor Author

@pieh pieh Jun 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was wrong setup which was resulting in not prerendering not-default locale. This make sure that prerendered page is actually prerendered for all locales.

This "fixes" one of the e2e failure that was supposed to be testing prerendered case for non default locale, but in practice it was testing not prerendered case

fallback: true,
}
}
Expand Down
Loading