mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
## 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]>
15 lines
462 B
TypeScript
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>
|
|
}
|