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).
33 lines
1.2 KiB
JavaScript
33 lines
1.2 KiB
JavaScript
/**
|
|
* @type {import('next').NextConfig}
|
|
*/
|
|
const nextConfig = {
|
|
cacheComponents: true,
|
|
experimental: {
|
|
optimisticRouting: true,
|
|
varyParams: true,
|
|
},
|
|
// Each rewrite below crafts one of the rewrite-affected response shapes
|
|
// we want to verify. They live in `beforeFiles` so they take precedence
|
|
// over the filesystem dynamic route — otherwise a 1-part URL like
|
|
// /featured would route directly to the filesystem (matched by the
|
|
// dynamic /[teamSlug]) without going through the rewrite, and we'd
|
|
// never observe the rewrite-affected response shape under test.
|
|
async rewrites() {
|
|
return {
|
|
beforeFiles: [
|
|
// Case "static-sibling": URL matches a known static sibling, but
|
|
// the rewrite sends it through the dynamic /[teamSlug] route.
|
|
{ source: '/featured', destination: '/some-team' },
|
|
// Case "static-visible-null": URL is shorter than the response,
|
|
// and the deeper segment is a visible static segment.
|
|
{ source: '/team-shorter', destination: '/team-shorter/overview' },
|
|
// Case "tree-shorter-than-url": URL is longer than the response.
|
|
{ source: '/:teamSlug/garbage', destination: '/:teamSlug' },
|
|
],
|
|
}
|
|
},
|
|
}
|
|
|
|
module.exports = nextConfig
|