mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
The initial prefetching implementation was based on the response returning below the common layout, however when static generation was added the RSC payload for these changed to only include the router tree patch and the fully rendered page. Currently the flow for prefetch is this: - `router.prefetch` - Fetch RSC payload - Dispatch `ACTION_PREFETCH` with RSC payload. Note: the fetch is intentionally not in the reducer as the fetch happens during an event or effect, e.g. hover or `useEffect` - Reducer handles `ACTION_PREFETCH`, creates the router tree, applies the `subTreeData` to the cache append-only. Saves the new router tree in the `prefetchCache` part of the reducer state. - Then, on navigation, the `subTreeData` should be already available so there's no additional apply. The router state is applied based on the `prefetchCache`. This approach is fine when the RSC payload returned never overrides the `subTreeData` of an already existing node, however that does happen in case of static pages because the subTreeData is for the root cache node instead of a deeper node. The new flow for prefetching: - `router.prefetch` - Fetch RSC payload - Dispatch `ACTION_PREFETCH` with RSC payload - Reducer handles `ACTION_PREFETCH`, creates the router tree, Saves the new router tree and `subTreeData` in the `prefetchCache` part of the reducer state. - Then, on navigation, the `subTreeData` and router state are applied based on the `prefetchCache`. <!-- Thanks for opening a PR! Your contribution is much appreciated. To make sure your PR is handled as smoothly as possible we request that you follow the checklist sections below. Choose the right checklist for the change that you're making: --> ## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md) ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] [e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md) ## Documentation / Examples - [ ] Make sure the linting passes by running `pnpm build && pnpm lint` - [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md) Co-authored-by: JJ Kasper <[email protected]>
14 lines
272 B
JavaScript
14 lines
272 B
JavaScript
import Link from 'next/link'
|
|
export default function HomePage() {
|
|
return (
|
|
<>
|
|
<Link href="/dashboard" id="to-dashboard">
|
|
To Dashboard
|
|
</Link>
|
|
<Link href="/static-page" id="to-static-page">
|
|
To Static Page
|
|
</Link>
|
|
</>
|
|
)
|
|
}
|