Files
cf83d7c0b1 fix(cache): DCE to avoid pulling server internals into browser bundles (4/8) (#89865)
## Summary

Fix dead-code elimination in `packages/next/cache.js` to prevent
server-only internals from being pulled into browser bundles.
Restructures the conditional exports so bundlers can properly tree-shake
server paths.

## Test plan

- [ ] `pnpm --filter=next build` succeeds
- [ ] No runtime behavior changes

---------

Co-authored-by: Tim Neutkens <[email protected]>
2026-02-19 13:36:27 +01:00

15 lines
462 B
TypeScript

'use client'
import { unstable_cache } from 'next/cache'
// Importing next/cache in a Client Component should not pull server internals
// into browser chunks. The bundler sets NEXT_RUNTIME='' for client builds,
// which allows cache.js to DCE the server require() branch.
const getCachedData = unstable_cache(async () => {
return { data: 'hello' }
})
export function CacheClient() {
return <button onClick={() => getCachedData()}>Fetch cached</button>
}