Skip to content

Commit

Permalink
Add config for opting out of optimistic client cache behavior (#38774)
Browse files Browse the repository at this point in the history
* Add config for opting out of optimistic client cache behavior

* update test
  • Loading branch information
ijjk committed Jul 26, 2022
1 parent 0de6269 commit 7fa7204
Show file tree
Hide file tree
Showing 5 changed files with 219 additions and 176 deletions.
3 changes: 3 additions & 0 deletions packages/next/build/webpack-config.ts
Expand Up @@ -1526,6 +1526,9 @@ export default async function getBaseWebpackConfig(
'process.env.__NEXT_NEW_LINK_BEHAVIOR': JSON.stringify(
config.experimental.newNextLinkBehavior
),
'process.env.__NEXT_OPTIMISTIC_CLIENT_CACHE': JSON.stringify(
config.experimental.optimisticClientCache
),
'process.env.__NEXT_CROSS_ORIGIN': JSON.stringify(crossOrigin),
'process.browser': JSON.stringify(isClient),
'process.env.__NEXT_TEST_MODE': JSON.stringify(
Expand Down
3 changes: 3 additions & 0 deletions packages/next/server/config-schema.ts
Expand Up @@ -328,6 +328,9 @@ const configSchema = {
},
] as any,
},
optimisticClientCache: {
type: 'boolean',
},
outputFileTracingRoot: {
minLength: 1,
type: 'string',
Expand Down
2 changes: 2 additions & 0 deletions packages/next/server/config-shared.ts
Expand Up @@ -79,6 +79,7 @@ export interface NextJsWebpackConfig {
}

export interface ExperimentalConfig {
optimisticClientCache?: boolean
legacyBrowsers?: boolean
browsersListForSwc?: boolean
manualClientBasePath?: boolean
Expand Down Expand Up @@ -517,6 +518,7 @@ export const defaultConfig: NextConfig = {
swcMinify: false,
output: !!process.env.NEXT_PRIVATE_STANDALONE ? 'standalone' : undefined,
experimental: {
optimisticClientCache: true,
runtime: undefined,
manualClientBasePath: false,
// TODO: change default in next major release (current v12.1.5)
Expand Down
4 changes: 3 additions & 1 deletion packages/next/shared/lib/router/router.ts
Expand Up @@ -2158,7 +2158,9 @@ export default class Router implements BaseRouter {
persistCache: !this.isPreview,
isPrefetch: true,
unstable_skipClientCache:
options.unstable_skipClientCache || options.priority,
options.unstable_skipClientCache ||
(options.priority &&
!!process.env.__NEXT_OPTIMISTIC_CLIENT_CACHE),
}).then(() => false)
: false
}),
Expand Down

0 comments on commit 7fa7204

Please sign in to comment.