next.js
9cd05eae - Implement runtime prefetching via segment opt-in (#83072)

Commit
151 days ago
Implement runtime prefetching via segment opt-in (#83072) Follow-up to #82905. When prefetching a link, we should perform a runtime prefetch for any segment that - has runtime prefetching enabled - is not a shared layout or - is a child of a segment that meets the above criteria. Anything that doesn't meet those criteria will be prefetched statically, i.e. the behavior before this PR. In other words, we disregard the `prefetch` config of shared layouts when deciding whether to perform a runtime prefetch. This means if you opt into runtime prefetching in a layout, navigating to a page inside that layout for the first time will perform a runtime prefetch, but navigating across multiple pages inside that layout will be static (until/unless there's a child that has also opted into runtime prefetching). For example, given a route structure like `/store/[id]`, where `/store/layout.tsx` has runtime prefetching enabled, but `/store/[id]/page.tsx` does not: - A Link from `/home` to `/store/1` results in a **runtime prefetch** - A Link from `/store/1` to `/store/2` results in a **static prefetch** If we didn't make this distinction, then opting into prefetching in a layout would override the config of everything inside it. (However, the most common pattern will be to set this config at the page level, where the distinction doesn't matter, since there are no child segments.) --------- Co-authored-by: Janka Uryga <lolzatu2@gmail.com>
Author
Parents
Loading