Unverified Commit 0cac0898 authored by Hendrik Liebau's avatar Hendrik Liebau Committed by GitHub

Fix cache kind validation (#76064)

Default cache handlers should be allowed and not trigger a build error.
parent 00d3c830
...@@ -43,8 +43,21 @@ struct CustomRoutes { ...@@ -43,8 +43,21 @@ struct CustomRoutes {
pub struct ModularizeImports(FxIndexMap<String, ModularizeImportPackageConfig>); pub struct ModularizeImports(FxIndexMap<String, ModularizeImportPackageConfig>);
#[turbo_tasks::value(transparent)] #[turbo_tasks::value(transparent)]
#[derive(Clone, Debug)]
pub struct CacheKinds(FxHashSet<RcStr>); pub struct CacheKinds(FxHashSet<RcStr>);
impl CacheKinds {
pub fn extend<I: IntoIterator<Item = RcStr>>(&mut self, iter: I) {
self.0.extend(iter);
}
}
impl Default for CacheKinds {
fn default() -> Self {
CacheKinds(["default", "remote"].iter().map(|&s| s.into()).collect())
}
}
#[turbo_tasks::value(serialization = "custom", eq = "manual")] #[turbo_tasks::value(serialization = "custom", eq = "manual")]
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize, OperationValue)] #[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize, OperationValue)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
...@@ -1422,13 +1435,13 @@ impl NextConfig { ...@@ -1422,13 +1435,13 @@ impl NextConfig {
#[turbo_tasks::function] #[turbo_tasks::function]
pub fn cache_kinds(&self) -> Vc<CacheKinds> { pub fn cache_kinds(&self) -> Vc<CacheKinds> {
Vc::cell( let mut cache_kinds = CacheKinds::default();
self.experimental
.cache_handlers if let Some(handlers) = self.experimental.cache_handlers.as_ref() {
.as_ref() cache_kinds.extend(handlers.keys().cloned());
.map(|handlers| handlers.keys().cloned().collect()) }
.unwrap_or_default(),
) cache_kinds.cell()
} }
#[turbo_tasks::function] #[turbo_tasks::function]
......
...@@ -221,7 +221,9 @@ function getBaseSWCOptions({ ...@@ -221,7 +221,9 @@ function getBaseSWCOptions({
isReactServerLayer, isReactServerLayer,
useCacheEnabled, useCacheEnabled,
hashSalt: serverReferenceHashSalt, hashSalt: serverReferenceHashSalt,
cacheKinds: cacheHandlers ? Object.keys(cacheHandlers) : [], cacheKinds: ['default', 'remote'].concat(
cacheHandlers ? Object.keys(cacheHandlers) : []
),
} }
: undefined, : undefined,
// For app router we prefer to bundle ESM, // For app router we prefer to bundle ESM,
......
...@@ -400,6 +400,14 @@ export default class NextNodeServer extends BaseServer< ...@@ -400,6 +400,14 @@ export default class NextNodeServer extends BaseServer<
cacheHandlerGlobal[cacheHandlersSymbol]?.DefaultCache || cacheHandlerGlobal[cacheHandlersSymbol]?.DefaultCache ||
DefaultCacheHandler DefaultCacheHandler
} }
if (
!cacheHandlers.remote &&
cacheHandlerGlobal[cacheHandlersSymbol]?.RemoteCache
) {
cacheHandlerGlobal.__nextCacheHandlers.remote =
cacheHandlerGlobal[cacheHandlersSymbol].RemoteCache
}
} }
} }
......
'use cache: remote'
export default async function Page() {
return <p>hello world</p>
}
import DefaultCacheHandler from 'next/dist/server/lib/cache-handlers/default'
export function register() {
globalThis[Symbol.for('@next/cache-handlers')] = {
RemoteCache: DefaultCacheHandler,
}
}
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
const nextConfig = { const nextConfig = {
experimental: { experimental: {
dynamicIO: true, dynamicIO: true,
cacheHandlers: {}, // overwrite the default config
prerenderEarlyExit: false,
}, },
} }
......
...@@ -33,9 +33,12 @@ describe('use-cache-unknown-cache-kind', () => { ...@@ -33,9 +33,12 @@ describe('use-cache-unknown-cache-kind', () => {
process.env.__NEXT_EXPERIMENTAL_NEW_DEV_OVERLAY === 'true' process.env.__NEXT_EXPERIMENTAL_NEW_DEV_OVERLAY === 'true'
if (isNextStart) { if (isNextStart) {
beforeAll(async () => {
await next.build()
})
it('should fail the build with an error', async () => { it('should fail the build with an error', async () => {
const { cliOutput } = await next.build() const buildOutput = getBuildOutput(next.cliOutput)
const buildOutput = getBuildOutput(cliOutput)
if (isTurbopack) { if (isTurbopack) {
expect(buildOutput).toMatchInlineSnapshot(` expect(buildOutput).toMatchInlineSnapshot(`
...@@ -79,7 +82,16 @@ describe('use-cache-unknown-cache-kind', () => { ...@@ -79,7 +82,16 @@ describe('use-cache-unknown-cache-kind', () => {
`) `)
} }
}) })
it('should not fail the build for default cache kinds', async () => {
expect(next.cliOutput).not.toInclude('Unknown cache kind "remote"')
})
} else { } else {
it('should not show an error for default cache kinds', async () => {
const browser = await next.browser('/remote')
await assertNoRedbox(browser)
})
it('should show a build error', async () => { it('should show a build error', async () => {
const browser = await next.browser('/') const browser = await next.browser('/')
......
...@@ -161,13 +161,13 @@ export class NextDevInstance extends NextInstance { ...@@ -161,13 +161,13 @@ export class NextDevInstance extends NextInstance {
) { ) {
await this.handleDevWatchDelayBeforeChange(filename) await this.handleDevWatchDelayBeforeChange(filename)
try { try {
const cliOutputLengthBefore = this.cliOutput.length let cliOutputLength = this.cliOutput.length
const isServerRunning = this.childProcess && !this.isStopping const isServerRunning = this.childProcess && !this.isStopping
const detectServerRestart = async () => { const detectServerRestart = async () => {
await retry(async () => { await retry(async () => {
const isServerReady = this.serverReadyPattern.test( const isServerReady = this.serverReadyPattern.test(
this.cliOutput.slice(cliOutputLengthBefore) this.cliOutput.slice(cliOutputLength)
) )
if (isServerRunning && !isServerReady) { if (isServerRunning && !isServerReady) {
throw new Error('Server has not finished restarting.') throw new Error('Server has not finished restarting.')
...@@ -202,6 +202,7 @@ export class NextDevInstance extends NextInstance { ...@@ -202,6 +202,7 @@ export class NextDevInstance extends NextInstance {
runWithTempContent runWithTempContent
? async (...args) => { ? async (...args) => {
await waitServerToBeReadyAfterPatchFile() await waitServerToBeReadyAfterPatchFile()
cliOutputLength = this.cliOutput.length
return runWithTempContent(...args) return runWithTempContent(...args)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment