next.js
6b5fe463 - Fix: Don't bail out of prefetch if head is missing (#82216)

Commit
215 days ago
Fix: Don't bail out of prefetch if head is missing (#82216) This fixes an edge case where a Link is prefetched with prefetch={true}, and the target page has a dynamic head, but the head is not fully prefetched. If all the segment data for the target page was already cached, the prefetch scheduler would bail out and skip the request. However, we typically rely on the data prefetch to fetch the metadata, so by skipping the data prefetch we were effectively also skipping the metadata. The fix in this PR is to check for this condition before bailing out of the request, and initiate a request anyway. However, this illustrates that we're not modeling the caching of metadata in a complete way. Currently it's stored on the same cache entry as the route tree, but they are not always fetched simultaneously (as in this regression case), so their lifetimes are not always aligned. We should consider either always fetching the metadata as part of the route tree prefetch, or caching metadata on a separate entry type. This would allow us to dedupe entries between URLs that rewrite to the same route, like we already do for segments. The circumstances that lead to this scenario are relatively rare, though, hence the temporary solution in this PR.
Author
Parents
Loading