forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bugfix: only replace with full prefetch if existing data was partial (v…
…ercel#70650) By default we are storing the seeded prefetch entry (from the SSR render) as an "auto" prefetch. The prefetch cache is used because every navigation checks against the prefetch cache to determine if it has the necessary data to render the requested segment(s). We have a router heuristic that will re-fetch a page that's already in the prefetch cache if the one that is stored is an "auto" prefetch, and the newly requested prefetch is a "full" prefetch. This is because the assumption is the "auto" prefetch would contain partial data (potentially only `loading.js` data) while the "full" prefetch has everything, so we'd want to replace the cache entry with the most up to date information. Currently when we seed the prefetch cache with the initially SSRed page, we set a cache status of "auto". This is because a "full" prefetch has staleTime implications: a full prefetch will be client cached for 5 minutes by default (the `static` staleTime), and since we have no prefetch intent during SSR, we should fallback to the automatic caching heuristics to avoid caching a page longer than what was intended. However, this will trigger the above mentioned logic to switch to a "full" prefetch if the page you're currently on has a link to itself, with `prefetch={true}`, resulting in a wasted request. This refactors the logic responsible for switching a prefetch entry to a "full" prefetch only once we confirm the response payload from the existing cache entry wasn't a response that started rendering from the root. If we started rendering from the root, we know that we have the full data already, so it'd be wasteful to fetch again. Fixes vercel#70535
- Loading branch information
Showing
4 changed files
with
114 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import Link from 'next/link' | ||
|
||
export const dynamic = 'force-dynamic' | ||
|
||
export default async function Page() { | ||
return ( | ||
<> | ||
<p id="dynamic-page">Dynamic Page</p> | ||
<p> | ||
<Link href="/" id="to-home"> | ||
To home | ||
</Link> | ||
</p> | ||
<p> | ||
<Link href="/dynamic-page" prefetch> | ||
To Same Page | ||
</Link> | ||
</p> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters