Skip to content

Commit c23f957

Browse files
authored
Disable "use cache" outside of dynamicIO (#70538)
1 parent a184047 commit c23f957

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

packages/next/src/build/webpack/plugins/define-env-plugin.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ export function getDefineEnv({
183183
config.devIndicators.appIsrStatus
184184
),
185185
'process.env.__NEXT_PPR': checkIsAppPPREnabled(config.experimental.ppr),
186+
'process.env.__NEXT_DYNAMIC_IO': !!config.experimental.dynamicIO,
186187
'process.env.__NEXT_AFTER': config.experimental.after ?? false,
187188
'process.env.NEXT_DEPLOYMENT_ID': config.deploymentId || false,
188189
'process.env.__NEXT_FETCH_CACHE_KEY_PREFIX': fetchCacheKeyPrefix ?? '',

packages/next/src/server/use-cache/use-cache-wrapper.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@ async function generateCacheEntry(
160160
}
161161

162162
export function cache(kind: string, id: string, fn: any) {
163+
if (!process.env.__NEXT_DYNAMIC_IO) {
164+
throw new Error(
165+
'"use cache" is only available with the experimental.dynamicIO config.'
166+
)
167+
}
163168
const cacheHandler = cacheHandlerMap.get(kind)
164169
if (cacheHandler === undefined) {
165170
throw new Error('Unknown cache handler: ' + kind)

0 commit comments

Comments
 (0)