mirror of
https://github.com/vercel/next.js.git
synced 2026-09-20 02:25:18 +08:00
57baeec90d
This adds support for caching `fetch` responses in server components across HMR refresh requests. The two main benefits are faster responses for those requests, and reduced costs for billed API calls during local development. **Implementation notes:** - The feature is guarded by the new experimental flag `serverComponentsHmrCache`. - The server components HMR cache is intentionally independent from the incremental cache. - Fetched responses are written to the cache after every original fetch call, regardless of the cache settings (specifically including `no-store`). - Cached responses are read from the cache only for HMR refresh requests, potentially also short-cutting the incremental cache. - The HMR refresh requests are marked by the client with the newly introduced `Next-HMR-Refresh` header. - I shied away from further extending `renderOpts`. The alternative of adding another parameter to `renderToHTMLOrFlight` might not necessarily be better though. - This includes a refactoring to steer away from the "fast refresh" wording, since this is a separate (but related) [React feature](https://github.com/facebook/react/issues/16604#issuecomment-528663101) (also build on top of HMR). x-ref: #48481
14 lines
218 B
TypeScript
14 lines
218 B
TypeScript
'use client'
|
|
|
|
import { useRouter } from 'next/navigation'
|
|
|
|
export function RefreshButton() {
|
|
const { refresh } = useRouter()
|
|
|
|
return (
|
|
<button type="button" onClick={refresh}>
|
|
refresh
|
|
</button>
|
|
)
|
|
}
|