Commit e7409af2 authored by Jimmy Lai's avatar Jimmy Lai

refactor: consolidate nextUrl clearing to single location

parent 3111aea6
...@@ -42,12 +42,6 @@ export function navigateReducer( ...@@ -42,12 +42,6 @@ export function navigateReducer(
const currentUrl = new URL(state.canonicalUrl, location.origin) const currentUrl = new URL(state.canonicalUrl, location.origin)
const currentRenderedSearch = state.renderedSearch const currentRenderedSearch = state.renderedSearch
// Clear nextUrl for same-page navigations to avoid re-triggering
// interception rewrites. When the user navigates to the same URL they're
// already on, we should not send the Next-Url header that would cause the
// server to apply interception rewrites again.
const nextUrl = url.href === currentUrl.href ? null : state.nextUrl
return navigateUsingSegmentCache( return navigateUsingSegmentCache(
state, state,
url, url,
...@@ -55,7 +49,7 @@ export function navigateReducer( ...@@ -55,7 +49,7 @@ export function navigateReducer(
currentRenderedSearch, currentRenderedSearch,
state.cache, state.cache,
state.tree, state.tree,
nextUrl, state.nextUrl,
FreshnessPolicy.Default, FreshnessPolicy.Default,
scrollBehavior, scrollBehavior,
navigateType navigateType
......
...@@ -60,12 +60,12 @@ export function navigate( ...@@ -60,12 +60,12 @@ export function navigate(
scrollBehavior: ScrollBehavior, scrollBehavior: ScrollBehavior,
navigateType: 'push' | 'replace' navigateType: 'push' | 'replace'
): AppRouterState | Promise<AppRouterState> { ): AppRouterState | Promise<AppRouterState> {
// Clear nextUrl for same-page navigations to avoid re-triggering // When navigating to the same URL, clear nextUrl so the Next-Url header is
// interception rewrites. This applies to both link clicks and programmatic // not sent. This prevents the server from re-applying interception rewrites,
// navigations (e.g. router.push, router.replace). // which would incorrectly re-trigger intercepting routes on same-page
if (url.href === currentUrl.href) { // navigations (e.g. router.push, router.replace, link clicks).
nextUrl = null // See: https://github.com/vercel/next.js/issues/82934
} const effectiveNextUrl = url.href === currentUrl.href ? null : nextUrl
// Instant Navigation Testing API: when the lock is active, ensure a // Instant Navigation Testing API: when the lock is active, ensure a
// prefetch task has been initiated before proceeding with the navigation. // prefetch task has been initiated before proceeding with the navigation.
...@@ -84,7 +84,7 @@ export function navigate( ...@@ -84,7 +84,7 @@ export function navigate(
currentRenderedSearch, currentRenderedSearch,
currentCacheNode, currentCacheNode,
currentFlightRouterState, currentFlightRouterState,
nextUrl, effectiveNextUrl,
freshnessPolicy, freshnessPolicy,
scrollBehavior, scrollBehavior,
navigateType navigateType
...@@ -99,7 +99,7 @@ export function navigate( ...@@ -99,7 +99,7 @@ export function navigate(
currentRenderedSearch, currentRenderedSearch,
currentCacheNode, currentCacheNode,
currentFlightRouterState, currentFlightRouterState,
nextUrl, effectiveNextUrl,
freshnessPolicy, freshnessPolicy,
scrollBehavior, scrollBehavior,
navigateType navigateType
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment