Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backport: fix prefetch bailout detection for nested loading segments #70618

Merged
merged 1 commit into from
Sep 30, 2024

Commits on Sep 30, 2024

  1. fix prefetch bailout detection for nested loading segments (#67358)

    When PPR is off, app router prefetches will render the component tree up
    until it encounters a `loading` segment, at which point it'll just
    return some metadata about the segment and won't do any further
    rendering. This is an optimization to ensure prefetches are lightweight
    and don't potentially invoke expensive dynamic subtrees. However,
    there's a bug in this logic that is causing it to bail unexpectedly if a
    segment deeper in the tree contained a `loading.js` file.
    
    This would mean the loading state wouldn't be triggered until the second
    request for the full RSC data is initiated, resulting in an unintended
    delta between when a link is clicked and the loading state is shown.
    
    The `shouldSkipComponentTree` flag was incorrectly being set to `true`
    even if the `loading.js` segment appeared deeper in the tree. Prefetch
    requests from the client will always contain `FlightRouterState`, so the
    logic to check for loading deeper in the tree will always be missed.
    
    This removes the `flightRouterState` check as it doesn't make sense:
    prefetches will currently _always_ include the `flightRouterState`,
    causing this to always short-circuit. I believe that this check is
    vestigial from when we were generating static `prefetch.rsc` outputs
    which is no longer the case.
    
    This mirrors a [similar
    check](https://github.com/vercel/next.js/blob/b87d8fc49983a3be568517d7ae14087749bb8ce3/packages/next/src/server/app-render/create-component-tree.tsx#L393)
    when determining if parallel route(s) should be rendered.
    ztanner committed Sep 30, 2024
    Configuration menu
    Copy the full SHA
    929cb69 View commit details
    Browse the repository at this point in the history