Skip to content

Commit da024c1

Browse files
authored
[cache components] move experimental.cacheHandlers out of experimental (#85157)
Moves this flag out of experimental so that custom `use cache` handlers can be configured alongside the cache components release.
1 parent 7a80195 commit da024c1

File tree

27 files changed

+95
-119
lines changed

27 files changed

+95
-119
lines changed

crates/next-api/src/next_server_nft.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ impl ServerNftJsonAsset {
187187
let cache_handlers = self
188188
.project
189189
.next_config()
190-
.experimental_cache_handlers(project_path.clone())
190+
.cache_handlers(project_path.clone())
191191
.await?;
192192

193193
// These are used by packages/next/src/server/require-hook.ts

crates/next-core/src/next_config.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ pub struct NextConfig {
8686
cache_max_memory_size: Option<f64>,
8787
/// custom path to a cache handler to use
8888
cache_handler: Option<RcStr>,
89-
89+
cache_handlers: Option<FxIndexMap<RcStr, RcStr>>,
9090
env: FxIndexMap<String, JsonValue>,
9191
experimental: ExperimentalConfig,
9292
images: ImageConfig,
@@ -823,7 +823,6 @@ pub struct ExperimentalConfig {
823823
adjust_font_fallbacks_with_size_adjust: Option<bool>,
824824
after: Option<bool>,
825825
app_document_preloading: Option<bool>,
826-
cache_handlers: Option<FxIndexMap<RcStr, RcStr>>,
827826
cache_life: Option<FxIndexMap<String, CacheLifeProfile>>,
828827
case_sensitive_routes: Option<bool>,
829828
cpus: Option<f64>,
@@ -1601,11 +1600,8 @@ impl NextConfig {
16011600
}
16021601

16031602
#[turbo_tasks::function]
1604-
pub fn experimental_cache_handlers(
1605-
&self,
1606-
project_path: FileSystemPath,
1607-
) -> Result<Vc<FileSystemPathVec>> {
1608-
if let Some(handlers) = &self.experimental.cache_handlers {
1603+
pub fn cache_handlers(&self, project_path: FileSystemPath) -> Result<Vc<FileSystemPathVec>> {
1604+
if let Some(handlers) = &self.cache_handlers {
16091605
Ok(Vc::cell(
16101606
handlers
16111607
.values()
@@ -1763,7 +1759,7 @@ impl NextConfig {
17631759
pub fn cache_kinds(&self) -> Vc<CacheKinds> {
17641760
let mut cache_kinds = CacheKinds::default();
17651761

1766-
if let Some(handlers) = self.experimental.cache_handlers.as_ref() {
1762+
if let Some(handlers) = self.cache_handlers.as_ref() {
17671763
cache_kinds.extend(handlers.keys().cloned());
17681764
}
17691765

crates/next-custom-transforms/src/transforms/server_actions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3191,7 +3191,7 @@ fn emit_error(error_kind: ServerActionsErrorKind) {
31913191
span,
31923192
formatdoc! {
31933193
r#"
3194-
Unknown cache kind "{cache_kind}". Please configure a cache handler for this kind in the `experimental.cacheHandlers` object in your Next.js config.
3194+
Unknown cache kind "{cache_kind}". Please configure a cache handler for this kind in the `cacheHandlers` object in your Next.js config.
31953195
"#
31963196
},
31973197
),

crates/next-custom-transforms/tests/errors/server-actions/server-graph/16/output.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
x Unknown cache kind "x". Please configure a cache handler for this kind in the `experimental.cacheHandlers` object in your Next.js config.
1+
x Unknown cache kind "x". Please configure a cache handler for this kind in the `cacheHandlers` object in your Next.js config.
22
|
33
,-[input.js:1:1]
44
1 | 'use cache: x'

crates/next-custom-transforms/tests/errors/server-actions/server-graph/17/output.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
x Unknown cache kind "x". Please configure a cache handler for this kind in the `experimental.cacheHandlers` object in your Next.js config.
1+
x Unknown cache kind "x". Please configure a cache handler for this kind in the `cacheHandlers` object in your Next.js config.
22
|
33
,-[input.js:2:1]
44
1 | export async function foo() {

packages/next/errors.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -898,5 +898,7 @@
898898
"897": "Expected HTML document to start with doctype prefix",
899899
"898": "When using Cache Components, all `generateStaticParams` functions must return at least one result. This is to ensure that we can perform build-time validation that there is no other dynamic accesses that would cause a runtime error.\n\nLearn more: https://nextjs.org/docs/messages/empty-generate-static-params",
900900
"899": "Both \"%s\" and \"%s\" files are detected. Please use \"%s\" instead. Learn more: https://nextjs.org/docs/messages/middleware-to-proxy",
901-
"900": "Both %s file \"./%s\" and %s file \"./%s\" are detected. Please use \"./%s\" only. Learn more: https://nextjs.org/docs/messages/middleware-to-proxy"
901+
"900": "Both %s file \"./%s\" and %s file \"./%s\" are detected. Please use \"./%s\" only. Learn more: https://nextjs.org/docs/messages/middleware-to-proxy",
902+
"901": "Invalid \"cacheHandlers\" provided, expected an object e.g. { default: '/my-handler.js' }, received %s",
903+
"902": "Invalid handler fields configured for \"cacheHandlers\":\\n%s"
902904
}

packages/next/src/build/collect-build-traces.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,7 @@ export async function collectBuildTraces({
140140
})
141141
)
142142

143-
const { cacheHandler } = config
144-
const { cacheHandlers } = config.experimental
143+
const { cacheHandler, cacheHandlers } = config
145144

146145
// ensure we trace any dependencies needed for custom
147146
// incremental cache handler

packages/next/src/build/entries.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -616,9 +616,7 @@ export function getEdgeServerEntry(opts: {
616616
middlewareConfig: Buffer.from(
617617
JSON.stringify(opts.middlewareConfig || {})
618618
).toString('base64'),
619-
cacheHandlers: JSON.stringify(
620-
opts.config.experimental.cacheHandlers || {}
621-
),
619+
cacheHandlers: JSON.stringify(opts.config.cacheHandlers || {}),
622620
}
623621

624622
return {
@@ -685,7 +683,7 @@ export function getEdgeServerEntry(opts: {
685683
JSON.stringify(opts.middlewareConfig || {})
686684
).toString('base64'),
687685
serverActions: opts.config.experimental.serverActions,
688-
cacheHandlers: JSON.stringify(opts.config.experimental.cacheHandlers || {}),
686+
cacheHandlers: JSON.stringify(opts.config.cacheHandlers || {}),
689687
}
690688

691689
return {

packages/next/src/build/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2228,7 +2228,7 @@ export default async function build(
22282228
cacheComponents: isAppCacheComponentsEnabled,
22292229
authInterrupts: isAuthInterruptsEnabled,
22302230
cacheHandler: config.cacheHandler,
2231-
cacheHandlers: config.experimental.cacheHandlers,
2231+
cacheHandlers: config.cacheHandlers,
22322232
isrFlushToDisk: ciEnvironment.hasNextSupport
22332233
? false
22342234
: config.experimental.isrFlushToDisk,
@@ -2523,7 +2523,7 @@ export default async function build(
25232523
const normalizedCacheHandlers: Record<string, string> = {}
25242524

25252525
for (const [key, value] of Object.entries(
2526-
config.experimental.cacheHandlers || {}
2526+
config.cacheHandlers || {}
25272527
)) {
25282528
if (key && value) {
25292529
normalizedCacheHandlers[key] = path.relative(distDir, value)
@@ -2543,9 +2543,9 @@ export default async function build(
25432543
cacheHandler: cacheHandler
25442544
? path.relative(distDir, cacheHandler)
25452545
: config.cacheHandler,
2546+
cacheHandlers: normalizedCacheHandlers,
25462547
experimental: {
25472548
...config.experimental,
2548-
cacheHandlers: normalizedCacheHandlers,
25492549
trustHostHeader: ciEnvironment.hasNextSupport,
25502550
isExperimentalCompile: isCompileMode,
25512551
},

packages/next/src/build/static-paths/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ export async function buildAppStaticPaths({
747747
isrFlushToDisk?: boolean
748748
fetchCacheKeyPrefix?: string
749749
cacheHandler?: string
750-
cacheHandlers?: NextConfigComplete['experimental']['cacheHandlers']
750+
cacheHandlers?: NextConfigComplete['cacheHandlers']
751751
cacheLifeProfiles?: {
752752
[profile: string]: import('../../server/use-cache/cache-life').CacheLife
753753
}

0 commit comments

Comments
 (0)