fix loading bailout condition & server patch mismatch tolerance (#72227)
Pre-PPR on client navigations, we are currently determining whether or not to render the underlying React components based on the presence (or lack thereof) of `loading.js`. We'll render components up to the first segment containing `loading.js`, and then stop at that level. Similarly, if there's no `loading.js` in the tree at all, we'll return a mostly empty prefetch. The underlying reason for this is that we cannot assume a particular tree/subtree doesn't contain expensive invocations: `loading.js` is a signal we use to detect where some sort of dynamic call will happen. This heuristic is largely improved with PPR + DIO but we still need to support this case. Currently there's a bug that will lead to overfetching. When determining if we should skip the component tree, we check the presence of loading at that level, as well as the entire tree. This means that during partial navigations when the server starts rendering deeper within the tree rather than starting from the root, the presence of `loading.js` in an earlier segment would incorrectly tell the router it should render the page. This updates the handling to check for a loading segment only within the partial tree that's being diffed. That way when we recursively call this, it won't look at earlier segments when deciding if there's a loading segment deeper in the tree. This PR also adjusts the server-patch reducer to be more resilient to mismatching trees. Previously we triggered a hard navigation but this actually can become a fairly common case if the RSC response doesn't return initial bytes quickly enough, such as in `dynamicIO` when we're warming the dev caches prior to a navigation. Instead we'll return the state in-place and effectively discard the patch because the assumption is the tree was patched elsewhere.
Showing
Please
register
or
sign in
to comment