Files
Nathan Nguyen aec4421b2a fix(app-router): let concrete Pages routes win middleware rewrites (#2730)
* fix(app-router): let concrete Pages routes win middleware rewrites

A Pages data request that middleware rewrote returned a synthetic empty
JSON body whenever any App route matched the rewrite target, including a
dynamic or catch-all match. Every other App-vs-Pages ownership decision in
this handler treats a dynamic App match as non-owning, so a concrete Pages
route at the same pathname should render instead. Skipping that arbitration
meant getServerSideProps never ran for the rewrite target, and the client
router, which reuses the middleware probe response when the rewrite target
resolves to a Pages route, accepted the empty body as successful page data.
Redirect and notFound markers the Pages route would have returned were
therefore absent during client-side navigation.

Restrict the shortcut to App matches that own the target outright, so
dynamic matches fall through to the existing static and dynamic Pages
fallback arbitration.

That fallthrough reaches the tail Pages data response, which built its
headers from the not-found response alone and dropped headers the
middleware set on the way. Merge the middleware response headers there so
a rewrite landing on a genuinely App-owned dynamic route still carries its
cookies.

* fix(app-router): preserve middleware headers on Pages fallbacks

* fix(app-router): use Pages response merge semantics

* test(app-router): cover rewritten Pages data ownership

---------

Co-authored-by: James <james@eli.cx>
2026-08-03 11:02:14 +01:00
..