next.js
c30747fe - Skip empty prefetch request for dynamic routes (#78436)

Commit
258 days ago
Skip empty prefetch request for dynamic routes (#78436) In the Segment Cache implementation of prefetching, a prefetch happens in two phases: first we fetch the route tree, then we fetch the data itself. The route tree prefetch tells us important metadata about the structure of the target route, like whether it shares any layouts with the current page. We can use this information to omit parts of the tree from subsequent data request. In this PR, I've added a new piece of metadata to the route tree prefetch response: `hasLoadingBoundary`. For each segment in the tree, this represents whether there is a `loading.tsx` boundary somewhere within it. This is useful because we know that during a prefetch, the server will only render up to the nearest loading boundary (unless prefetch={true} is set); if there are no loading boundaries, then the server will return an empty response. In the latter case, we can use this information to skip the data prefetch entirely, freeing up bandwidth for other requests in the queue.
Author
Parents
Loading