bugfix: only replace with full prefetch if existing data was partial (#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 #70535