mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
The server actions transform, which handles the `'use cache'` directive, was not being applied to `node_modules` when imported from route handlers. This caused `'use cache'` functions from dependencies to fail with errors like `"cacheLife() can only be called inside a 'use cache' function"``. The issue was that the `AppRoute` context used `internal_custom_rules` for its foreign code module options, which did not include the server actions transform. This is inconsistent with `AppRSC` (App Router pages), which correctly uses `foreign_next_server_rules` that includes the transform. The fix extends `foreign_next_server_rules` with `internal_custom_rules` and uses it for the foreign code context in `AppRoute`, matching the pattern used by `AppRSC`.
24 lines
485 B
JavaScript
24 lines
485 B
JavaScript
import { cacheLife, cacheTag } from 'next/cache'
|
|
|
|
export async function getCachedRandom() {
|
|
'use cache'
|
|
return Math.random()
|
|
}
|
|
|
|
export async function getCachedRandomWithTag(tag) {
|
|
'use cache'
|
|
cacheTag(tag)
|
|
return Math.random()
|
|
}
|
|
|
|
export async function getCachedRandomWithCacheLife(n = 1) {
|
|
'use cache'
|
|
cacheLife('weeks')
|
|
return String(Math.ceil(Math.random() * n))
|
|
}
|
|
|
|
export async function getCachedRandomWithHandler() {
|
|
'use cache: default'
|
|
return Math.random()
|
|
}
|