Skip to content
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
2 changes: 1 addition & 1 deletion crates/next-api/src/next_server_nft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ impl ServerNftJsonAsset {
let cache_handlers = self
.project
.next_config()
.experimental_cache_handlers(project_path.clone())
.cache_handlers(project_path.clone())
.await?;

// These are used by packages/next/src/server/require-hook.ts
Expand Down
12 changes: 4 additions & 8 deletions crates/next-core/src/next_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pub struct NextConfig {
cache_max_memory_size: Option<f64>,
/// custom path to a cache handler to use
cache_handler: Option<RcStr>,

cache_handlers: Option<FxIndexMap<RcStr, RcStr>>,
env: FxIndexMap<String, JsonValue>,
experimental: ExperimentalConfig,
images: ImageConfig,
Expand Down Expand Up @@ -823,7 +823,6 @@ pub struct ExperimentalConfig {
adjust_font_fallbacks_with_size_adjust: Option<bool>,
after: Option<bool>,
app_document_preloading: Option<bool>,
cache_handlers: Option<FxIndexMap<RcStr, RcStr>>,
cache_life: Option<FxIndexMap<String, CacheLifeProfile>>,
case_sensitive_routes: Option<bool>,
cpus: Option<f64>,
Expand Down Expand Up @@ -1603,11 +1602,8 @@ impl NextConfig {
}

#[turbo_tasks::function]
pub fn experimental_cache_handlers(
&self,
project_path: FileSystemPath,
) -> Result<Vc<FileSystemPathVec>> {
if let Some(handlers) = &self.experimental.cache_handlers {
pub fn cache_handlers(&self, project_path: FileSystemPath) -> Result<Vc<FileSystemPathVec>> {
if let Some(handlers) = &self.cache_handlers {
Ok(Vc::cell(
handlers
.values()
Expand Down Expand Up @@ -1765,7 +1761,7 @@ impl NextConfig {
pub fn cache_kinds(&self) -> Vc<CacheKinds> {
let mut cache_kinds = CacheKinds::default();

if let Some(handlers) = self.experimental.cache_handlers.as_ref() {
if let Some(handlers) = self.cache_handlers.as_ref() {
cache_kinds.extend(handlers.keys().cloned());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3191,7 +3191,7 @@ fn emit_error(error_kind: ServerActionsErrorKind) {
span,
formatdoc! {
r#"
Unknown cache kind "{cache_kind}". Please configure a cache handler for this kind in the `experimental.cacheHandlers` object in your Next.js config.
Unknown cache kind "{cache_kind}". Please configure a cache handler for this kind in the `cacheHandlers` object in your Next.js config.
"#
},
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
x Unknown cache kind "x". Please configure a cache handler for this kind in the `experimental.cacheHandlers` object in your Next.js config.
x Unknown cache kind "x". Please configure a cache handler for this kind in the `cacheHandlers` object in your Next.js config.
|
,-[input.js:1:1]
1 | 'use cache: x'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
x Unknown cache kind "x". Please configure a cache handler for this kind in the `experimental.cacheHandlers` object in your Next.js config.
x Unknown cache kind "x". Please configure a cache handler for this kind in the `cacheHandlers` object in your Next.js config.
|
,-[input.js:2:1]
1 | export async function foo() {
Expand Down
4 changes: 3 additions & 1 deletion packages/next/errors.json
Original file line number Diff line number Diff line change
Expand Up @@ -898,5 +898,7 @@
"897": "Expected HTML document to start with doctype prefix",
"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",
"899": "Both \"%s\" and \"%s\" files are detected. Please use \"%s\" instead. Learn more: https://nextjs.org/docs/messages/middleware-to-proxy",
"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"
"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": "Invalid \"cacheHandlers\" provided, expected an object e.g. { default: '/my-handler.js' }, received %s",
"902": "Invalid handler fields configured for \"cacheHandlers\":\\n%s"
}
3 changes: 1 addition & 2 deletions packages/next/src/build/collect-build-traces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ export async function collectBuildTraces({
})
)

const { cacheHandler } = config
const { cacheHandlers } = config.experimental
const { cacheHandler, cacheHandlers } = config

// ensure we trace any dependencies needed for custom
// incremental cache handler
Expand Down
6 changes: 2 additions & 4 deletions packages/next/src/build/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -616,9 +616,7 @@ export function getEdgeServerEntry(opts: {
middlewareConfig: Buffer.from(
JSON.stringify(opts.middlewareConfig || {})
).toString('base64'),
cacheHandlers: JSON.stringify(
opts.config.experimental.cacheHandlers || {}
),
cacheHandlers: JSON.stringify(opts.config.cacheHandlers || {}),
}

return {
Expand Down Expand Up @@ -685,7 +683,7 @@ export function getEdgeServerEntry(opts: {
JSON.stringify(opts.middlewareConfig || {})
).toString('base64'),
serverActions: opts.config.experimental.serverActions,
cacheHandlers: JSON.stringify(opts.config.experimental.cacheHandlers || {}),
cacheHandlers: JSON.stringify(opts.config.cacheHandlers || {}),
}

return {
Expand Down
6 changes: 3 additions & 3 deletions packages/next/src/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2224,7 +2224,7 @@ export default async function build(
cacheComponents: isAppCacheComponentsEnabled,
authInterrupts: isAuthInterruptsEnabled,
cacheHandler: config.cacheHandler,
cacheHandlers: config.experimental.cacheHandlers,
cacheHandlers: config.cacheHandlers,
isrFlushToDisk: ciEnvironment.hasNextSupport
? false
: config.experimental.isrFlushToDisk,
Expand Down Expand Up @@ -2519,7 +2519,7 @@ export default async function build(
const normalizedCacheHandlers: Record<string, string> = {}

for (const [key, value] of Object.entries(
config.experimental.cacheHandlers || {}
config.cacheHandlers || {}
)) {
if (key && value) {
normalizedCacheHandlers[key] = path.relative(distDir, value)
Expand All @@ -2539,9 +2539,9 @@ export default async function build(
cacheHandler: cacheHandler
? path.relative(distDir, cacheHandler)
: config.cacheHandler,
cacheHandlers: normalizedCacheHandlers,
experimental: {
...config.experimental,
cacheHandlers: normalizedCacheHandlers,
trustHostHeader: ciEnvironment.hasNextSupport,
isExperimentalCompile: isCompileMode,
},
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/build/static-paths/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ export async function buildAppStaticPaths({
isrFlushToDisk?: boolean
fetchCacheKeyPrefix?: string
cacheHandler?: string
cacheHandlers?: NextConfigComplete['experimental']['cacheHandlers']
cacheHandlers?: NextConfigComplete['cacheHandlers']
cacheLifeProfiles?: {
[profile: string]: import('../../server/use-cache/cache-life').CacheLife
}
Expand Down
34 changes: 14 additions & 20 deletions packages/next/src/build/swc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -859,26 +859,20 @@ function bindingToApi(
? path.relative(projectPath, nextConfigSerializable.cacheHandler)
: nextConfigSerializable.cacheHandler)
}
if (nextConfigSerializable.experimental?.cacheHandlers) {
nextConfigSerializable.experimental = {
...nextConfigSerializable.experimental,
cacheHandlers: Object.fromEntries(
Object.entries(
nextConfigSerializable.experimental.cacheHandlers as Record<
string,
string
>
)
.filter(([_, value]) => value != null)
.map(([key, value]) => [
key,
'./' +
(path.isAbsolute(value)
? path.relative(projectPath, value)
: value),
])
),
}
if (nextConfigSerializable.cacheHandlers) {
nextConfigSerializable.cacheHandlers = Object.fromEntries(
Object.entries(
nextConfigSerializable.cacheHandlers as Record<string, string>
)
.filter(([_, value]) => value != null)
.map(([key, value]) => [
key,
'./' +
(path.isAbsolute(value)
? path.relative(projectPath, value)
: value),
])
)
}

if (nextConfigSerializable.turbopack != null) {
Expand Down
4 changes: 2 additions & 2 deletions packages/next/src/build/swc/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function getBaseSWCOptions({
serverReferenceHashSalt: string
bundleLayer?: WebpackLayerName
isCacheComponents?: boolean
cacheHandlers?: ExperimentalConfig['cacheHandlers']
cacheHandlers?: NextConfig['cacheHandlers']
useCacheEnabled?: boolean
trackDynamicImports?: boolean
}) {
Expand Down Expand Up @@ -412,7 +412,7 @@ export function getLoaderSWCOptions({
serverComponents?: boolean
serverReferenceHashSalt: string
bundleLayer?: WebpackLayerName
cacheHandlers: ExperimentalConfig['cacheHandlers']
cacheHandlers: NextConfig['cacheHandlers']
useCacheEnabled?: boolean
trackDynamicImports?: boolean
}) {
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/build/webpack/loaders/next-swc-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ async function loaderTransform(
serverReferenceHashSalt,
bundleLayer,
esm,
cacheHandlers: nextConfig.experimental?.cacheHandlers,
cacheHandlers: nextConfig.cacheHandlers,
useCacheEnabled: nextConfig.experimental?.useCache,
trackDynamicImports,
})
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/export/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ export async function exportPages(
// skip writing to disk in minimal mode for now, pending some
// changes to better support it
flushToDisk: !hasNextSupport,
cacheHandlers: nextConfig.experimental.cacheHandlers,
cacheHandlers: nextConfig.cacheHandlers,
})

renderOpts.incrementalCache = incrementalCache
Expand Down
1 change: 1 addition & 0 deletions packages/next/src/server/config-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ export const configSchema: zod.ZodType<NextConfig> = z.lazy(() =>
bundlePagesRouterDependencies: z.boolean().optional(),
cacheComponents: z.boolean().optional(),
cacheHandler: z.string().min(1).optional(),
cacheHandlers: z.record(z.string(), z.string().optional()).optional(),
cacheLife: z
.record(
z.object({
Expand Down
39 changes: 15 additions & 24 deletions packages/next/src/server/config-shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,12 +272,8 @@ export interface LoggingConfig {
export interface ExperimentalConfig {
adapterPath?: string
useSkewCookie?: boolean
cacheHandlers?: {
default?: string
remote?: string
static?: string
[handlerName: string]: string | undefined
}
/** @deprecated use top-level `cacheHandlers` instead */
cacheHandlers?: NextConfig['cacheHandlers']
multiZoneDraftMode?: boolean
appNavFailHandling?: boolean
prerenderEarlyExit?: boolean
Expand Down Expand Up @@ -308,19 +304,7 @@ export interface ExperimentalConfig {
/**
* @deprecated use top-level `cacheLife` instead
*/
cacheLife?: {
[profile: string]: {
// How long the client can cache a value without checking with the server.
stale?: number
// How frequently you want the cache to refresh on the server.
// Stale values may be served while revalidating.
revalidate?: number
// In the worst case scenario, where you haven't had traffic in a while,
// how stale can a value be until you prefer deopting to dynamic.
// Must be longer than revalidate.
expire?: number
}
}
cacheLife?: NextConfig['cacheLife']
// decimal for percent for possible false positives
// e.g. 0.01 for 10% potential false matches lower
// percent increases size of the filter
Expand Down Expand Up @@ -1017,6 +1001,13 @@ export interface NextConfig {
*/
cacheHandler?: string | undefined

cacheHandlers?: {
default?: string
remote?: string
static?: string
[handlerName: string]: string | undefined
}

/**
* Configure the in-memory cache size in bytes. Defaults to 50 MB.
* If `cacheMaxMemorySize: 0`, this disables in-memory caching entirely.
Expand Down Expand Up @@ -1452,14 +1443,14 @@ export const defaultConfig = Object.freeze({
expire: 60 * 60 * 24 * 365, // 1 year
},
},
cacheHandlers: {
default: process.env.NEXT_DEFAULT_CACHE_HANDLER_PATH,
remote: process.env.NEXT_REMOTE_CACHE_HANDLER_PATH,
static: process.env.NEXT_STATIC_CACHE_HANDLER_PATH,
},
experimental: {
adapterPath: process.env.NEXT_ADAPTER_PATH || undefined,
useSkewCookie: false,
cacheHandlers: {
default: process.env.NEXT_DEFAULT_CACHE_HANDLER_PATH,
remote: process.env.NEXT_REMOTE_CACHE_HANDLER_PATH,
static: process.env.NEXT_STATIC_CACHE_HANDLER_PATH,
},
cssChunking: true,
multiZoneDraftMode: false,
appNavFailHandling: false,
Expand Down
19 changes: 13 additions & 6 deletions packages/next/src/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,13 @@ function assignDefaultsAndValidate(
configFileName,
silent
)
warnOptionHasBeenMovedOutOfExperimental(
result,
'cacheHandlers',
'cacheHandlers',
configFileName,
silent
)

if ((result.experimental as any).outputStandalone) {
if (!silent) {
Expand Down Expand Up @@ -1146,16 +1153,16 @@ function assignDefaultsAndValidate(
}
}

if (result.experimental?.cacheHandlers) {
if (result.cacheHandlers) {
const allowedHandlerNameRegex = /[a-z-]/

if (typeof result.experimental.cacheHandlers !== 'object') {
if (typeof result.cacheHandlers !== 'object') {
throw new Error(
`Invalid "experimental.cacheHandlers" provided, expected an object e.g. { default: '/my-handler.js' }, received ${JSON.stringify(result.experimental.cacheHandlers)}`
`Invalid "cacheHandlers" provided, expected an object e.g. { default: '/my-handler.js' }, received ${JSON.stringify(result.cacheHandlers)}`
)
}

const handlerKeys = Object.keys(result.experimental.cacheHandlers)
const handlerKeys = Object.keys(result.cacheHandlers)
const invalidHandlerItems: Array<{ key: string; reason: string }> = []

for (const key of handlerKeys) {
Expand All @@ -1172,7 +1179,7 @@ function assignDefaultsAndValidate(
})
} else {
const handlerPath = (
result.experimental.cacheHandlers as {
result.cacheHandlers as {
[handlerName: string]: string | undefined
}
)[key]
Expand All @@ -1186,7 +1193,7 @@ function assignDefaultsAndValidate(
}
if (invalidHandlerItems.length) {
throw new Error(
`Invalid handler fields configured for "experimental.cacheHandler":\n${invalidHandlerItems.map((item) => `${key}: ${item.reason}`).join('\n')}`
`Invalid handler fields configured for "cacheHandlers":\n${invalidHandlerItems.map((item) => `${key}: ${item.reason}`).join('\n')}`
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/server/dev/next-dev-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ export default class DevServer extends Server {
isAppPath,
requestHeaders,
cacheHandler: this.nextConfig.cacheHandler,
cacheHandlers: this.nextConfig.experimental.cacheHandlers,
cacheHandlers: this.nextConfig.cacheHandlers,
cacheLifeProfiles: this.nextConfig.cacheLife,
fetchCacheKeyPrefix: this.nextConfig.experimental.fetchCacheKeyPrefix,
isrFlushToDisk: this.nextConfig.experimental.isrFlushToDisk,
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/server/dev/static-paths-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export async function loadStaticPaths({
cacheMaxMemorySize: number
requestHeaders: IncrementalCache['requestHeaders']
cacheHandler?: string
cacheHandlers?: NextConfigComplete['experimental']['cacheHandlers']
cacheHandlers?: NextConfigComplete['cacheHandlers']
cacheLifeProfiles?: {
[profile: string]: import('../../server/use-cache/cache-life').CacheLife
}
Expand Down
5 changes: 1 addition & 4 deletions packages/next/src/server/next-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -459,10 +459,7 @@ export default class NextNodeServer extends BaseServer<
}

private async loadCustomCacheHandlers() {
const {
cacheMaxMemorySize,
experimental: { cacheHandlers },
} = this.nextConfig
const { cacheMaxMemorySize, cacheHandlers } = this.nextConfig
if (!cacheHandlers) return

// If we've already initialized the cache handlers interface, don't do it
Expand Down
5 changes: 1 addition & 4 deletions packages/next/src/server/route-modules/route-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,10 +381,7 @@ export abstract class RouteModule<
nextConfig: NextConfigComplete
) {
if (process.env.NEXT_RUNTIME !== 'edge') {
const {
cacheMaxMemorySize,
experimental: { cacheHandlers },
} = nextConfig
const { cacheMaxMemorySize, cacheHandlers } = nextConfig
if (!cacheHandlers) return

// If we've already initialized the cache handlers interface, don't do it
Expand Down
Loading
Loading