mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
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).
40 lines
1.3 KiB
TypeScript
40 lines
1.3 KiB
TypeScript
import { LinkAccordion } from '../components/link-accordion'
|
|
|
|
export default function Home() {
|
|
return (
|
|
<main>
|
|
<h1>HOME</h1>
|
|
<ul>
|
|
{/* The four prefetch URLs below each arrive via a rewrite that
|
|
produces a route shape the URL would not naturally route to.
|
|
Each test reveals one of them (default prefetch=true) to
|
|
populate the router's prediction state, then clicks one of
|
|
the click-targets below to check that no incorrect prediction
|
|
was learned. */}
|
|
<li>
|
|
<LinkAccordion href="/myteam/garbage">Tree-shorter</LinkAccordion>
|
|
</li>
|
|
<li>
|
|
<LinkAccordion href="/featured">Static-sibling</LinkAccordion>
|
|
</li>
|
|
<li>
|
|
<LinkAccordion href="/team-shorter">
|
|
Static-visible-null
|
|
</LinkAccordion>
|
|
</li>
|
|
|
|
{/* Click target — prefetch={false} so revealing it fires no
|
|
request. Inside an act scope, the test clicks this and
|
|
asserts that no /[teamSlug] loading boundary appears
|
|
instantly (which would only happen if the router had a
|
|
cached prediction for it). */}
|
|
<li>
|
|
<LinkAccordion href="/yourteam" prefetch={false}>
|
|
Your team
|
|
</LinkAccordion>
|
|
</li>
|
|
</ul>
|
|
</main>
|
|
)
|
|
}
|