mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
When functions exported from a module with a top-level `'use cache'` directive are imported into client modules, the compiler should allow `cacheLife` and `cacheTag` usage within those functions. This PR updates the `react_server_components` transform to properly track module directives (`'use client'`, `'use server'`, `'use cache'`) and skip client graph validation for modules with `'use cache'`, identical to how modules with `'use server'` are already handled. Those modules are transformed anyway for the client graph by the `server_actions` transform, which is applied after the `react_server_components` transform, in which their implementation is replaced by server function references. closes NAR-498
26 lines
383 B
TypeScript
26 lines
383 B
TypeScript
'use cache'
|
|
|
|
import { cacheLife, cacheTag } from 'next/cache'
|
|
|
|
function getRandomValue() {
|
|
const v = Math.random()
|
|
console.log(v)
|
|
return v
|
|
}
|
|
|
|
export async function foo() {
|
|
cacheLife('days')
|
|
return getRandomValue()
|
|
}
|
|
|
|
export const bar = async function () {
|
|
cacheTag('bar')
|
|
return getRandomValue()
|
|
}
|
|
|
|
const baz = async () => {
|
|
return getRandomValue()
|
|
}
|
|
|
|
export { baz }
|