Files
Andrew ClarkandGitHub 8980f3a76a Fix: Improved rewrite detection during optimistic routing (#93619)
When optimistic routing is enabled, the client uses responses it
receives from the server (during a navigation or a prefetch) to resolve
the routes of structurally similar URLs.

However, if the server rewrites a URL to a different path than the one
requested by the client, then we disable optimistic routing for that
pattern.

We detect a rewrite by comparing the route tree returned from the server
to the requested URL. If the route tree does not match, according to the
Next.js routing algorithm, then the route must have been rewritten; we
do not write this pattern into the client's route table.

The basic mechanism for this was already implemented, but there were
some cases we weren't handling correctly:

- A static or non-optional dynamic segment is reached with no URL part
to consume.
- A page leaf is reached with URL parts still pending.
- A dynamic segment whose URL part matches one of its known static
siblings (which would have taken precedence under normal routing).

These cases have been fixed. Regression tests live in
`optimistic-routing-rewrite-detection-regression/` and
`optimistic-routing-parallel-slot-catchall-regression/`.

---

Replaces #93578 (re-opened from an `origin` branch to satisfy CI
requirements).
2026-05-08 09:02:43 -04:00

35 lines
1.0 KiB
TypeScript

import { Suspense } from 'react'
import { connection } from 'next/server'
import { LinkAccordion } from '../../components/link-accordion'
async function HubContent() {
await connection()
return <div id="hub-content">Hub</div>
}
// Hub page used by rewrite-detection tests as a navigation target instead of
// `browser.back()`. Each visit lands on a fresh page where all accordions
// start closed, so previously-revealed Links can't be re-mounted by BFCache
// and trigger uncontrolled prefetches outside any `act` scope.
export default function HubPage() {
return (
<div>
<Suspense fallback="Loading hub...">
<HubContent />
</Suspense>
<ul>
<li>
<LinkAccordion href="/rewritten/second" prefetch={false}>
Rewritten Second
</LinkAccordion>
</li>
<li>
<LinkAccordion href="/search-rewrite?v=beta" prefetch={false}>
Search Rewrite Beta (v=beta → content=beta)
</LinkAccordion>
</li>
</ul>
</div>
)
}