vercel / next.js

The React Framework
https://nextjs.org
MIT License
122.91k stars 26.28k forks source link

fix dynamic param extraction for interception routes #67400

Closed ztanner closed 2 days ago

ztanner commented 3 days ago

What

When using generateStaticParams with interception routes, the interception would never occur, and instead an MPA navigation would take place to the targeted link.

Why

For interception rewrites, we use a __NEXT_EMPTY_PARAM__ marker (in place of the actual param slot, eg :locale) for any params that are discovered prior to the interception marker. This is because during route resolution, the params for the interception route might not contain the same params for the page that triggered the interception. The dynamic params are then extracted from FlightRouterState at render time. However, when generateStaticParams is present, the FlightRouterState header is stripped from the request, so it isn't able to extract the dynamic params and so the router thinks the new tree is a new root layout, hence the MPA navigation.

How

This removes the __NEXT_EMPTY_PARAM__ hack and several spots where we were forcing interception routes to be dynamic as a workaround to the above bug. Now when resolving the route, if the request was to an interception route, we extract the dynamic params from the request before constructing the final rewritten URL. This will ensure that the params from the "current" route are available in addition to the params from the interception route without needing to defer until render.

Fixes #65192 Fixes #52880

ztanner commented 3 days ago

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @ztanner and the rest of your teammates on Graphite Graphite

ijjk commented 3 days ago

Tests Passed