Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
0cac0898
Unverified
Commit
0cac0898
authored
Feb 17, 2025
by
Hendrik Liebau
Committed by
GitHub
Feb 17, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix cache kind validation (#76064)
Default cache handlers should be allowed and not trigger a build error.
parent
00d3c830
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
62 additions
and
12 deletions
+62
-12
next_config.rs
crates/next-core/src/next_config.rs
+20
-7
options.ts
packages/next/src/build/swc/options.ts
+3
-1
next-server.ts
packages/next/src/server/next-server.ts
+8
-0
page.tsx
.../app-dir/use-cache-unknown-cache-kind/app/remote/page.tsx
+5
-0
instrumentation.ts
...e/app-dir/use-cache-unknown-cache-kind/instrumentation.ts
+7
-0
next.config.js
test/e2e/app-dir/use-cache-unknown-cache-kind/next.config.js
+2
-0
use-cache-unknown-cache-kind.test.ts
...e-unknown-cache-kind/use-cache-unknown-cache-kind.test.ts
+14
-2
next-dev.ts
test/lib/next-modes/next-dev.ts
+3
-2
No files found.
crates/next-core/src/next_config.rs
View file @
0cac0898
...
...
@@ -43,8 +43,21 @@ struct CustomRoutes {
pub
struct
ModularizeImports
(
FxIndexMap
<
String
,
ModularizeImportPackageConfig
>
);
#[turbo_tasks
::
value(transparent)]
#[derive(Clone,
Debug)]
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"
)]
#[derive(Clone,
Debug,
Default,
PartialEq,
Serialize,
Deserialize,
OperationValue)]
#[serde(rename_all
=
"camelCase"
)]
...
...
@@ -1422,13 +1435,13 @@ impl NextConfig {
#[turbo_tasks
::
function]
pub
fn
cache_kinds
(
&
self
)
->
Vc
<
CacheKinds
>
{
Vc
::
cell
(
self
.experimental
.cache_handlers
.as_ref
()
.map
(|
handlers
|
handlers
.keys
()
.cloned
()
.collect
())
.unwrap_or_default
(),
)
let
mut
cache_kinds
=
CacheKinds
::
default
();
if
let
Some
(
handlers
)
=
self
.experimental.cache_handlers
.as_ref
()
{
cache_kinds
.extend
(
handlers
.keys
()
.cloned
());
}
cache_kinds
.cell
(
)
}
#[turbo_tasks
::
function]
...
...
packages/next/src/build/swc/options.ts
View file @
0cac0898
...
...
@@ -221,7 +221,9 @@ function getBaseSWCOptions({
isReactServerLayer
,
useCacheEnabled
,
hashSalt
:
serverReferenceHashSalt
,
cacheKinds
:
cacheHandlers
?
Object
.
keys
(
cacheHandlers
)
:
[],
cacheKinds
:
[
'default'
,
'remote'
].
concat
(
cacheHandlers
?
Object
.
keys
(
cacheHandlers
)
:
[]
),
}
:
undefined
,
// For app router we prefer to bundle ESM,
...
...
packages/next/src/server/next-server.ts
View file @
0cac0898
...
...
@@ -400,6 +400,14 @@ export default class NextNodeServer extends BaseServer<
cacheHandlerGlobal
[
cacheHandlersSymbol
]?.
DefaultCache
||
DefaultCacheHandler
}
if
(
!
cacheHandlers
.
remote
&&
cacheHandlerGlobal
[
cacheHandlersSymbol
]?.
RemoteCache
)
{
cacheHandlerGlobal
.
__nextCacheHandlers
.
remote
=
cacheHandlerGlobal
[
cacheHandlersSymbol
].
RemoteCache
}
}
}
...
...
test/e2e/app-dir/use-cache-unknown-cache-kind/app/remote/page.tsx
0 → 100644
View file @
0cac0898
'use cache: remote'
export
default
async
function
Page
()
{
return
<
p
>
hello world
</
p
>
}
test/e2e/app-dir/use-cache-unknown-cache-kind/instrumentation.ts
0 → 100644
View file @
0cac0898
import
DefaultCacheHandler
from
'next/dist/server/lib/cache-handlers/default'
export
function
register
()
{
globalThis
[
Symbol
.
for
(
'@next/cache-handlers'
)]
=
{
RemoteCache
:
DefaultCacheHandler
,
}
}
test/e2e/app-dir/use-cache-unknown-cache-kind/next.config.js
View file @
0cac0898
...
...
@@ -4,6 +4,8 @@
const
nextConfig
=
{
experimental
:
{
dynamicIO
:
true
,
cacheHandlers
:
{},
// overwrite the default config
prerenderEarlyExit
:
false
,
},
}
...
...
test/e2e/app-dir/use-cache-unknown-cache-kind/use-cache-unknown-cache-kind.test.ts
View file @
0cac0898
...
...
@@ -33,9 +33,12 @@ describe('use-cache-unknown-cache-kind', () => {
process
.
env
.
__NEXT_EXPERIMENTAL_NEW_DEV_OVERLAY
===
'true'
if
(
isNextStart
)
{
beforeAll
(
async
()
=>
{
await
next
.
build
()
})
it
(
'should fail the build with an error'
,
async
()
=>
{
const
{
cliOutput
}
=
await
next
.
build
()
const
buildOutput
=
getBuildOutput
(
cliOutput
)
const
buildOutput
=
getBuildOutput
(
next
.
cliOutput
)
if
(
isTurbopack
)
{
expect
(
buildOutput
).
toMatchInlineSnapshot
(
`
...
...
@@ -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
{
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
()
=>
{
const
browser
=
await
next
.
browser
(
'/'
)
...
...
test/lib/next-modes/next-dev.ts
View file @
0cac0898
...
...
@@ -161,13 +161,13 @@ export class NextDevInstance extends NextInstance {
)
{
await
this
.
handleDevWatchDelayBeforeChange
(
filename
)
try
{
const
cliOutputLengthBefore
=
this
.
cliOutput
.
length
let
cliOutputLength
=
this
.
cliOutput
.
length
const
isServerRunning
=
this
.
childProcess
&&
!
this
.
isStopping
const
detectServerRestart
=
async
()
=>
{
await
retry
(
async
()
=>
{
const
isServerReady
=
this
.
serverReadyPattern
.
test
(
this
.
cliOutput
.
slice
(
cliOutputLength
Before
)
this
.
cliOutput
.
slice
(
cliOutputLength
)
)
if
(
isServerRunning
&&
!
isServerReady
)
{
throw
new
Error
(
'Server has not finished restarting.'
)
...
...
@@ -202,6 +202,7 @@ export class NextDevInstance extends NextInstance {
runWithTempContent
?
async
(...
args
)
=>
{
await
waitServerToBeReadyAfterPatchFile
()
cliOutputLength
=
this
.
cliOutput
.
length
return
runWithTempContent
(...
args
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment