Repository: vercel/next.js
Pull request: [segment cache]: fix interception route handling

With `clientSegmentCache` enabled, if you are already on a route that was intercepted/could have been intercepted, and then you navigated to it again, the router would get stuck in a state where it was infinitely suspended on data it would never receive.

When no prefetch is available, we assume that the FlightRouterState sent by the server contains everything that is needed to describe the rendering shape of the page. However this isn't quite true: in `walk-tree-with-flight-router-state` (the function that populates prefetch responses), we skip sending down the `__DEFAULT__` segment. As a result, the client would get into a state where it thinks it needs to request data from the server, but the server will never send it. 

This updates the code to not special-case `__DEFAULT__` segments. We should separately see how we can restore this optimization to keep those payloads as small as possible, but it causes problems with back/forward nav that need to be investigated.

Changed files:
filename: packages/next/src/server/app-render/walk-tree-with-flight-router-state.tsx
patch: @@ -16,10 +16,7 @@ import {
 } from './create-flight-router-state-from-loader-tree'
 import type { AppRenderContext } from './app-render'
 import { hasLoadingComponentInTree } from './has-loading-component-in-tree'
-import {
-  DEFAULT_SEGMENT_KEY,
-  addSearchParamsIfPageSegment,
-} from '../../shared/lib/segment'
+import { addSearchParamsIfPageSegment } from '../../shared/lib/segment'
 import { createComponentTree } from './create-component-tree'
 import { getSegmentParam } from './get-segment-param'
 
@@ -218,6 +215,7 @@ export async function walkTreeWithFlightRouterState({
       getDynamicParamFromSegment,
       query
     )
+
     // Create component tree using the slice of the loaderTree
     const seedData = await createComponentTree(
       // This ensures flightRouterPath is valid and filters down the tree
@@ -298,17 +296,6 @@ export async function walkTreeWithFlightRouterState({
     })
 
     for (const subPath of subPaths) {
-      // we don't need to send over default routes in the flight data
-      // because they are always ignored by the client, unless it's a refetch
-      if (
-        subPath[0] === DEFAULT_SEGMENT_KEY &&
-        flightRouterState &&
-        !!flightRouterState[1][parallelRouteKey][0] &&
-        flightRouterState[1][parallelRouteKey][3] !== 'refetch'
-      ) {
-        continue
-      }
-
       paths.push([actualSegment, parallelRouteKey, ...subPath])
     }
   }

filename: test/client-segment-cache-tests-manifest.json
patch: @@ -43,11 +43,6 @@
         "app dir - navigation middleware redirect should change browser location when router.refresh() gets a redirect response"
       ]
     },
-    "test/e2e/app-dir/parallel-routes-and-interception/parallel-routes-and-interception.test.ts": {
-      "failed": [
-        "parallel-routes-and-interception route intercepting should support intercepting local dynamic sibling routes"
-      ]
-    },
     "test/e2e/app-dir/parallel-routes-revalidation/parallel-routes-revalidation.test.ts": {
       "failed": [
         "parallel-routes-revalidation router.refresh (dynamic) - searchParams: false should correctly refresh data for previously intercepted modal and active page slot",