Server Action external redirect is dropped when invoked outside a React scope
Tier 2 hard typescript · cross-file · real merged PR from vercel/next.js #86367
Ground-truth defects
The re-implemented Server Action reducer now rejects the action's promise with a redirect error for every redirect, external ones included, where it previously resolved them, and builds that error's URL with createHrefFromUrl, which keeps only the path and query, so an external URL loses its origin. Called from a form action or useTransition, React catches the handled error and the external navigation that handleExternalUrl staged (mpaNavigation) goes through. Called outside a React scope, such as a plain onClick, the rejection reaches the app router's unhandledrejection handler, which pushes the same-origin path; that navigation supersedes the external one, so the redirect to the external URL never happens.
The change under review
diff (truncated — full diff)
@@ -51,7 +51,7 @@ export type NavigationTask = { } export type NavigationRequestAccumulation = { - scrollableSegments: Array<FlightSegmentPath> + scrollableSegments: Array<FlightSegmentPath> | null separateRefreshUrls: Set<string> | null } @@ -91,6 +91,8 @@ export function startPPRNavigation( oldRouterState: FlightRouterState, newRouterState: FlightRouterState, shouldRefreshDynamicData: boolean, + seedData: CacheNodeSeedData | null, + seedHead: HeadData | null, prefetchData: CacheNodeSeedData | null, prefetchHead: HeadData | null, isPrefetchHeadPartial: boolean, @@ -108,6 +110,8 @@ export function startPPRNavigation( newRouterState, shouldRefreshDynamicData, didFindRootLayout, + seedData, + seedHead, prefetchData, prefetchHead, isPrefetchHeadPartial, @@ -128,6 +132,8 @@ function updateCacheNodeOnNavigation( newRouterState: FlightRouterState, shouldRefreshDynamicData: boolean, didFindRootLayout: boolean, + seedData: CacheNodeSeedData | null, + seedHead: HeadData | null, prefetchData: CacheNodeSeedData | null, prefetchHead: HeadData | null, isPrefetchHeadPartial: boolean, @@ -193,6 +199,8 @@ function updateCacheNodeOnNavigation( newRouterState, oldCacheNode, shouldRefreshDynamicData, + seedData, + seedHead, prefetchData, prefetchHead, isPrefetchHeadPartial, @@ -216,6 +224,7 @@ function updateCacheNodeOnNavigation( const newRouterStateChildren = newRouterState[1] const oldRouterStateChildren = oldRouterState[1] + const seedDataChildren = seedData !== null ? seedData[1] : null const prefetchDataChildren = prefetchData !== null ? prefetchData[1] : null // We're currently traversing the part of the tree that was also part of @@ -264,6 +273,28 @@ function updateCacheNodeOnNavigation( // Reuse the existing CacheNode newCacheNode = reuseDynamicCacheNode(oldCacheNode, newParallelRoutes) needsDynamicRequest = false + } else if (seedData !== null) { + // If this navigation was the result of an action, then check if the + // server sent back data in the action response. We should favor using + // that, rather than performing a separate request. This is both better + // for performance and it's more likely to be consistent with any + // writes that were just performed by the action, compared to a + // separate request. + const seedRsc = seedData[0] + const seedLoading = seedData[2] + const isSeedRscPartial = false + const isSeedHeadPartial = seedHead === null + newCacheNode = readCacheNodeFromSeedData( + seedRsc, + seedLoading, + isSeedRscPartial, + seedHead, + isSeedHeadPartial, + isLeafSegment, + newParallelRoutes, + navigatedAt + ) + needsDynamicRequest = isLeafSegment && isSeedHeadPartial } else if (prefetchData !== null) { // Consult the prefetch cache. const prefetchRsc = prefetchData[0] @@ -357,12 +388,16 @@ function updateCacheNodeOnNavigation( oldParallelRoutes !== undefined ? oldParallelRoutes.get(parallelRouteKey) : undefined + + let seedDataChild: CacheNodeSeedData | void | null = + seedDataChildren !== null ? seedDataChildren[parallelRouteKey] : null let prefetchDataChild: CacheNodeSeedData | void | null = prefetchDataChildren !== null ? prefetchDataChildren[parallelRouteKey] : null let newSegmentChild = newRouterStateChild[0] + let seedHeadChild = seedHead let prefetchHeadChild = prefetchHead let isPrefetchHeadPartialChild = isPrefetchHeadPartial if (newSegmentChild === DEFAULT_SEGMENT_KEY) { @@ -377,6 +412,8 @@ function updateCacheNodeOnNavigation( // Since we're switching to a different route tree, these are no // longer valid, because they correspond to the outer tree. + seedDataChild = null + seedHeadChild = null prefetchDataChild = null prefetchHeadChild = null isPrefetchHeadPartialChild = false @@ -396,6 +433,8 @@ function updateCacheNodeOnNavigation( newRouterStateChild, shouldRefreshDynamicData, childDidFindRootLayout, + seedDataChild ?? null, + seedHeadChild, prefetchDataChild ?? null, prefetchHeadChild, isPrefetchHeadPartialChild, @@ -421,7 +460,9 @@ function updateCacheNodeOnNavigation( taskChildren.set(parallelRouteKey, taskChild) const newCacheNodeChild = taskChild.node if (newCacheNodeChild !== null) { - const newSegmentMapChild: ChildSegmentMap = new Map(oldSegmentMapChild) + const newSegmentMapChild: ChildSegmentMap = new Map( + shouldRefreshDynamicData ? undefined : oldSegmentMapChild + ) newSegmentMapChild.set(newSegmentKeyChild, newCacheNodeChild) newParallelRoutes.set(parallelRouteKey, newSegmentMapChild) } @@ -471,6 +512,8 @@ function createCacheNodeOnNavigation( newRouterState: FlightRouterState, oldCacheNode: CacheNode | void, shouldRefreshDynamicData: boolean, + seedData: CacheNodeSeedData | null, + seedHead: HeadData | null, prefetchData: CacheNodeSeedData | null, prefetchHead: HeadData | null, isPrefetchHeadPartial: boolean, @@ -497,6 +540,7 @@ function createCacheNodeOnNavigation( const newRouterStateChildren = newRouterState[1] const prefetchDataChildren = prefetchData !== null ? prefetchData[1] : null + const seedDataChildren = seedData !== null ? seedData[1] : null const oldParallelRoutes = oldCacheNode !== undefined ? oldCacheNode.parallelRoutes : undefined const newParallelRoutes = new Map( @@ -514,6 +558,9 @@ function createCacheNodeOnNavigation( // TODO: We should use a string to represent the segment path instead of // an array. We already use a string representation for the path when // accessing the Segment Cache, so we can use the same one. + if (accumulation.scrollableSegments === null) { + accumulation.scrollableSegments = [] + } accumulation.scrollableSegments.push(segmentPath) } @@ -534,6 +581,28 @@ function createCacheNodeOnNavigation( // Reuse the existing CacheNode newCacheNode = reuseDynamicCacheNode(oldCacheNode, newParallelRoutes) needsDynamicRequest = false + } else if (seedData !== null) { + // If this navigation was the result of an action, then check if the + // server sent back data in the action response. We should favor using + // that, rather than performing a separate request. This is both better + // for performance and it's more likely to be consistent with any + // writes that were just performed by the action, compared to a + // separate request. + const seedRsc = seedData[0] + const seedLoading = seedData[2] + const isSeedRscPartial = false + const isSeedHeadPartial = seedHead === null + newCacheNode = readCacheNodeFromSeedData( + seedRsc, + seedLoading, + isSeedRscPartial, + seedHead, + isSeedHeadPartial, + isLeafSegment, + newParallelRoutes, + navigatedAt + ) + needsDynamicRequest = isLeafSegment && isSeedHeadPartial } else if (prefetchData !== null) { // Consult the prefetch cache. const prefetchRsc = prefetchData[0] @@ -578,6 +647,8 @@ function createCacheNodeOnNavigation( oldParallelRoutes !== undefined ? oldParallelRoutes.get(parallelRouteKey) : undefined + const seedDataChild: CacheNodeSeedData | void | null = + seedDataChildren !== null ? seedDataChildren[parallelRouteKey] : null const prefetchDataChild: CacheNodeSeedData | void | null = prefetchDataChildren !== null ? prefetchDataChildren[parallelRouteKey] @@ -596,6 +667,8 @@ function createCacheNodeOnNavigation( newRouterStateChild, oldCacheNodeChild, shouldRefreshDynamicData, + seedDataChild ?? null, + seedHead, prefetchDataChild ?? null, prefetchHead, isPrefetchHeadPartial, @@ -611,7 +684,9 @@ function createCacheNodeOnNavigation( taskChildren.set(parallelRouteKey, taskChild) const newCacheNodeChild = taskChild.node if (newCacheNodeChild !== null) { - const newSegmentMapChild: ChildSegmentMap = new Map(oldSegmentMapChild) + const newSegmentMapChild: ChildSegmentMap = new Map( + shouldRefreshDynamicData ? undefined : oldSegmentMapChild + ) newSegmentMapChild.set(newSegmentKeyChild, newCacheNodeChild) newParallelRoutes.set(parallelRouteKey, newSegmentMapChild) } @@ -161,12 +161,14 @@ export function navigateReducer( // implementation. Eventually we'll rewrite the router reducer to a // state machine. const currentUrl = new URL(state.canonicalUrl, location.origin) + const shouldRefreshDynamicData = false const result = navigateUsingSegmentCache( url, currentUrl, state.cache, state.tree, state.nextUrl, + shouldRefreshDynamicData, shouldScroll, mutable ) @@ -5,8 +5,9 @@ import type { RefreshAction, } from '../router-reducer-types' import { handleNavigationResult } from './navigate-reducer' -import { refresh as refreshUsingSegmentCache } from '../../segment-cache/navigation' +import { navigateToSeededRoute } from '../../segment-cache/navigation' import { revalidateEntireCache } from '../../segment-cache/cache' +import { hasInterceptionRouteInCurrentTree } from './has-interception-route-in-current-tree' export function refreshReducer( state: ReadonlyReducerState, @@ -19,14 +20,38 @@ export function refreshReducer( const currentRouterState = state.tree revalidateEntireCache(currentNextUrl, currentRouterState) + // We always send the last next-url, not the current when performing a dynamic + // request. This is because we update the next-url after a navigation, but we + // want the same interception route to be matched that used the last next-url. + const nextUrlForRefresh = hasInterceptionRouteInCurrentTree(state.tree) + ? state.previousNextUrl || currentNextUrl + : null + + // A refresh is modeled as a navigation to the current URL, but where any + // existing dynamic data (including in shared layouts) is re-fetched. const currentUrl = new URL(state.canonicalUrl, action.origin) - const result = refreshUsingSegmentCache( + const url = currentUrl + const currentFlightRouterState = state.tree + const shouldScroll = true + const shouldRefreshDynamicData = true + + const seedFlightRouterState = state.tree + const seedRenderedSearch = state.renderedSearch + const seedData = null + const seedHead = null + + const result = navigateToSeededRoute( + url, currentUrl, state.cache, - state.tree, - state.nextUrl, - state.renderedSearch, - state.canonicalUrl + currentFlightRouterState, + seedFlightRouterState, + seedRenderedSearch, + seedData, + seedHead, + shouldRefreshDynamicData, + nextUrlForRefresh, + shouldScroll ) const mutable: Mutable = {} @@ -32,16 +32,8 @@ import type { } from '../router-reducer-types' import { assignLocation } from '../../../assign-location' import { createHrefFromUrl } from '../create-href-from-url' -import { handleExternalUrl } from './navigate-reducer' -import { applyRouterStatePatchToTree } from '../apply-router-state-patch-to-tree' -import { isNavigatingToNewRootLayout } from '../is-navigating-to-new-root-layout' -import type { CacheNode } from '../../../../shared/lib/app-router-types' -import { handleMutable } from '../handle-mutable' -import { fillLazyItemsTillLeafWithHead } from '../fill-lazy-items-till-leaf-with-head' -import { createEmptyCacheNode } from '../../app-router' +import { handleExternalUrl, handleNavigationResult } from './navigate-reducer' import { hasInterceptionRouteInCurrentTree } from './has-interception-route-in-current-tree' -import { handleSegmentMismatch } from '../handle-segment-mismatch' -import { refreshInactiveParallelSegments } from '../refetch-inactive-parallel-segments' import { normalizeFlightData, prepareFlightRouterStateForRequest, @@ -57,6 +49,11 @@ import { } from '../../../../shared/lib/server-reference-info' import { revalidateEntireCache } from '../../segment-cache/cache' import { getDeploymentId } from '../../../../shared/lib/deployment-id' +import { + navigateToSeededRoute, + navigate as navigateUsingSegmentCache, +} from '../../segment-cache/navigation' +import type { NormalizedSearch } from '../../segment-cache/cache-key' const createFromFetch = createFromFetchBrowser as (typeof import('react-server-dom-webpack/client.browser'))['createFromFetch'] @@ -74,11 +71,16 @@ if ( ).createDebugChannel } +// TODO: Refactor to be a discriminated union. Or just get rid of it; +// fetchServerAction only has one caller, no reason this intermediate type has +// to exist. type FetchServerActionResult = { redirectLocation: URL | undefined redirectType: RedirectType | undefined actionResult: ActionResult | undefined actionFlightData: NormalizedFlightData[] | string | undefined + actionFlightDataRenderedSearch: NormalizedSearch | undefined + actionFlightDataCouldBeIntercepted: boolean | undefined isPrerender: boolean revalidatedParts: { tag: boolean @@ -166,7 +168,7 @@ async function fetchServerAction( revalidatedParts = { paths: revalidatedHeader[0] || [], tag: !!revalidatedHeader[1], - cookie: revalidatedHeader[2], + cookie: !!revalidatedHeader[2], } } catch (e) { revalidatedParts = NO_REVALIDATED_PARTS @@ -200,6 +202,8 @@ async function fetchServerAction( let actionResult: FetchServerActionResult['actionResult'] let actionFlightData: FetchServerActionResult['actionFlightData'] + let actionFlightDataRenderedSearch: FetchServerActionResult['actionFlightDataRenderedSearch'] + let actionFlightDataCouldBeIntercepted: FetchServerActionResult['actionFlightDataCouldBeIntercepted'] if (isRscResponse) { const response: ActionFlightResponse = await createFromFetch( @@ -214,16 +218,25 @@ async function fetchServerAction( // An internal redirect can send an RSC response, but does not have a useful `actionResult`. actionResult = redirectLocation ? undefined : response.a - actionFlightData = normalizeFlightData(response.f) + const maybeFlightData = normalizeFlightData(response.f) + if (maybeFlightData !== '') { + actionFlightData = maybeFlightData + actionFlightDataRenderedSearch = response.q as NormalizedSearch + actionFlightDataCouldBeIntercepted = response.i + } } else { // An external redirect doesn't contain RSC data. actionResult = undefined actionFlightData = undefined + actionFlightDataRenderedSearch = undefined + actionFlightDataCouldBeIntercepted = undefined } return { actionResult, actionFlightData, + actionFlightDataRenderedSearch, + actionFlightDataCouldBeIntercepted, redirectLocation, redirectType, revalidatedParts, @@ -248,8 +261,6 @@ export function serverActionReducer( const { resolve, reject } = action const mutable: ServerActionMutable = {} - let currentTree = state.tree - mutable.preserveCustomHistoryState = false // only pass along the `nextUrl` param (used for interception routes) if the current route was intercepted. @@ -267,161 +278,47 @@ export function serverActionReducer( ? state.previousNextUrl || state.nextUrl : null - const navigatedAt = Date.now() - return fetchServerAction(state, nextUrl, action).then( async ({ actionResult, actionFlightData: flightData, + actionFlightDataRenderedSearch: flightDataRenderedSearch, + actionFlightDataCouldBeIntercepted: flightDataCouldBeIntercepted, redirectLocation, redirectType, revalidatedParts, }) => { - let redirectHref: string | undefined - - // honor the redirect type instead of defaulting to push in case of server actions. - if (redirectLocation) { - if (redirectType === RedirectType.replace) { - state.pushRef.pendingPush = false - mutable.pendingPush = false - } else { - state.pushRef.pendingPush = true - mutable.pendingPush = true - } - - redirectHref = createHrefFromUrl(redirectLocation, false) - mutable.canonicalUrl = redirectHref - } - - if (!flightData) { - resolve(actionResult) - - // If there is a redirect but no flight data we need to do a mpaNavigation. - if (redirectLocation) { - return handleExternalUrl( - state, - mutable, - redirectLocation.href, - state.pushRef.pendingPush - ) - } - return state - } - - if (typeof flightData === 'string') { - // Handle case when navigating to page in `pages` from `app` - resolve(actionResult) - - return handleExternalUrl( - state, - mutable, - flightData, - state.pushRef.pendingPush - ) - } - - const actionRevalidated = + const actionDidRevalidateCache = revalidatedParts.paths.length > 0 || revalidatedParts.tag || revalidatedParts.cookie - // Store whether this action triggered any revalidation - // The action queue will use this information to potentially - // trigger a refresh action if the action was discarded - // (ie, due to a navigation, before the action completed) - if (actionRevalidated) { + if (actionDidRevalidateCache) { + // Store whether this action triggered any revalidation + // The action queue will use this information to potentially + // trigger a refresh action if the action was discarded + // (ie, due to a navigation, before the action completed) action.didRevalidate = true - } - - for (const normalizedFlightData of flightData) { - const { - tree: treePatch, - seedData: cacheNodeSeedData, - head, - isRootRender, - } = normalizedFlightData - - if (!isRootRender) { - // TODO-APP: handle this case better - console.log('SERVER ACTION APPLY FAILED') - resolve(actionResult) - - return state - } - - // Given the path can only have two items the items are only the router state and rsc for the root. - const newTree = applyRouterStatePatchToTree( - // TODO-APP: remove '' - [''], - currentTree, - treePatch,
Leaderboard for this case
hard · 0 of 9 bots fully caught it (0% solve rate) · 0% avg coverage.
| # | Bot | Result | Caught | Coverage | Findings | False alarms |
|---|---|---|---|---|---|---|
| 1 | Claude Code (Opus 5.5) | miss | 0/1 | 0.0% | 2 | 0 |
| 2 | Cubic | miss | 0/1 | 0.0% | 1 | 0 |
| 3 | cursor | miss | 0/1 | 0.0% | 2 | 0 |
| 4 | Drape (Deep Review) | miss | 0/1 | 0.0% | 3 | 0 |
| 5 | greptile | miss | 0/1 | 0.0% | 0 | 0 |
| 6 | Mjolnir (Opus 5.5) | miss | 0/1 | 0.0% | 4 | 0 |
| 7 | Mjolnir (Sonnet 5.5) | miss | 0/1 | 0.0% | 1 | 0 |
| 8 | Drape (Review) | miss | 0/1 | 0.0% | 3 | 1 |
| 9 | qodo | miss | 0/1 | 0.0% | 2 | 1 |
Bot results
Claude Code (Opus 5.5) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | high | ✗ | — |
handleMutable only sets focusAndScrollRef.apply to true when mutable.scrollableSegments is defined. Before this change, a navigation that created no new segments (for example a same-URL Link or push, where the page is refetched through the update path) passed [] and so triggered scroll and focus. Now it passes null, which becomes undefined, so apply keeps its previous value and the page no longer scrolls or moves focus. [grounded: diff] [consensus 3/3: valid=3]
When there is no redirect, redirectType is undefined, so pendingPush is true, and it is written into the live state.pushRef before the bailout. The old code only changed pendingPush on a redirect. In the MPA fallback path, app-router.tsx now calls location.assign instead of location.replace. History pushState is guarded against same-URL pushes, so the real impact is limited. [grounded: diff] [consensus 3/3: valid=3]
raw comments (2)
`scrollableSegments` now starts as `null` instead of `[]` in `navigateUsingPrefetchedRouteTree`, `navigateDynamicallyWithNoPrefetch` and `navigateToSeededRoute`, and it only becomes an array when `createCacheNodeOnNavigation` adds a new segment. When a navigation creates no new segments (for example a <Link> or router.push() to the current URL), `navigationTaskToResult` now returns `null`. `handleNavigationResult` turns that into `mutable.scrollableSegments = undefined`. In `handleMutable`, `focusAndScrollRef.apply` then keeps its previous value (usually false after the last scroll) instead of becoming true with an empty `segmentPaths`. As a result, ordinary navigations that used to scroll to the top and move focus no longer do. Previously, only refresh deliberately passed `null`.
`pendingPush = redirectType !== RedirectType.replace` evaluates to true when there is no redirect (`redirectType` is undefined). It is also written directly to `state.pushRef.pendingPush` before the early `return state` bailout. So every server action without a redirect, including ones that change nothing, mutates the live pushRef to push mode. A revalidation-only action that falls back to an MPA navigation now uses `location.assign` instead of `location.replace` for the current URL. The old code only changed `pendingPush` when a redirect happened.
Cubic · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | high | ✗ | — |
Before the change, the reducer mutated state.pushRef.pendingPush only when there was a redirect. Now, with no redirect, redirectType is undefined, so pendingPush becomes true, and that value is written into the current state before the `return state` bail-out. The stale flag stays on the shared pushRef. Later reducers that pass it through (server-patch-reducer calls handleExternalUrl with state.pushRef.pendingPush) and app-router's MPA branch (`if (pushRef.pendingPush) location.assign`) would then push a history entry instead of replacing it. [grounded: diff] [consensus 3/3: valid=3]
raw comments (2)
<!-- cubic:v=487e289b-9e33-4fc0-b0ba-50744ea5482b -->
<!-- cubic:review-run=21b09d75-7ce1-58e3-bf4e-605bf4cb8b6e -->
<!-- metadata:{"confidence":8} -->
P2: For an ordinary server action with no redirect, this line mutates `state.pushRef.pendingPush` to `true` even though the reducer later bails out without navigation. That stale flag can make a later MPA fallback push a history entry instead of replacing it; do not mutate the current state here and let navigation paths apply `mutable.pendingPush`.
<details>
<summary>Prompt for AI agents</summary>
```text
Check if this issue is valid — if so, understand the root cause and fix it. At packages/next/src/client/components/router-reducer/reducers/server-action-reducer.ts, line 336:
<comment>For an ordinary server action with no redirect, this line mutates `state.pushRef.pendingPush` to `true` even though the reducer later bails out without navigation. That stale flag can make a later MPA fallback push a history entry instead of replacing it; do not mutate the current state here and let navigation paths apply `mutable.pendingPush`.</comment>
<file context>
@@ -431,10 +328,125 @@ export function serverActionReducer(
- return handleMutable(state, mutable)
+ const pendingPush = redirectType !== RedirectType.replace
+ state.pushRef.pendingPush = pendingPush
+ mutable.pendingPush = pendingPush
+
</file context>
```
</details>
<!-- cubic:review-summary:start -->
**1 issue found** across 7 files
<!-- cubic:review-summary:end -->
<details>
<summary>Prompt for AI agents (unresolved issues)</summary>
```text
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="packages/next/src/client/components/router-reducer/reducers/server-action-reducer.ts">
<violation number="1" location="packages/next/src/client/components/router-reducer/reducers/server-action-reducer.ts:336">
P2: For an ordinary server action with no redirect, this line mutates `state.pushRef.pendingPush` to `true` even though the reducer later bails out without navigation. That stale flag can make a later MPA fallback push a history entry instead of replacing it; do not mutate the current state here and let navigation paths apply `mutable.pendingPush`.</violation>
</file>
```
</details>
<sub>Reply with feedback, questions, or to request a fix.<br /><br />[Re-trigger cubic](https://www.cubic.dev/action/re-review/pr/drape-io/crbench-cubic-2026-09/64/ai_pr_review_github_delivery_453aa96e0b23e704468598dc85d3fae886fd9fa985d344ff8526e33914e19fcc?returnTo=https%3A%2F%2Fgithub.com%2Fdrape-io%2Fcrbench-cubic-2026-09%2Fpull%2F64)</sub>
<!-- cubic:review-post:ai_pr_review_github_delivery_453aa96e0b23e704468598dc85d3fae886fd9fa985d344ff8526e33914e19fcc:a805cff51b7c3788ed030ad33c9696257f55f342:21b09d75-7ce1-58e3-bf4e-605bf4cb8b6e -->
cursor · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | high | ✗ | — |
The old code called revalidateEntireCache(state.nextUrl, newTree). The new code passes the interception-gated `nextUrl`, which is null whenever the tree has no interception route. pingVisibleLinks then reschedules visible-link prefetches under cache keys built with that null nextUrl, unlike refreshReducer, which passes state.nextUrl. The app-router effect re-pings links when the tree changes, which softens the impact, but the regression is real. [grounded: diff] [consensus 3/3: valid=3]
The old code changed pushRef.pendingPush only when there was a redirect, and the external-URL path used the existing state.pushRef.pendingPush. Now a non-redirect action (redirectType undefined) sets pendingPush to true on state.pushRef before the bailout. So the string-flightData MPA path and the failed-SPA MPA path now push a new history entry instead of honoring the prior value. [grounded: diff] [consensus 3/3: valid=3]
raw comments (3)
### Revalidate pings links with wrong nextUrl
**Medium Severity**
<!-- DESCRIPTION START -->
`revalidateEntireCache` now receives the interception-gated `nextUrl`, which is `null` when the current tree has no interception route, instead of `state.nextUrl`. Visible-link prefetches are keyed with `state.nextUrl`, so a revalidating action fills the wrong cache entries. Combined with the revalidation cooldown and passing the pre-navigation `state.tree`, links on the resulting page can stay stale until a later miss.
<!-- DESCRIPTION END -->
<!-- BUGBOT_BUG_ID: c24fc989-7a57-4348-b30f-847d77ec6854 -->
<!-- LOCATIONS START
packages/next/src/client/components/router-reducer/reducers/server-action-reducer.ts#L304-L305
LOCATIONS END -->
<div><a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9DVVJTT1IiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjA1ZGY3NWE3LWU5YTAtNDAzYS05ZTI1LWRkNWE4N2IwYTQwYyIsImVuY3J5cHRpb25LZXkiOiI0RTNTZERnMWNpc0IzVFFTWlJXTjRQY3d1WnA1eVhnYjRhTGZFX0pOQjRnIiwiYnJhbmNoIjoidDItbmV4dGpzLTg2MzY3IiwicmVwb093bmVyIjoiZHJhcGUtaW8iLCJyZXBvTmFtZSI6ImNyYmVuY2gtY3Vyc29yLTIwMjYtMDkiLCJwcm92aWRlciI6ImdpdGh1YiJ9fQ" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a> <a href="https://cursor.com/agents?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9XRUIiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjA1ZGY3NWE3LWU5YTAtNDAzYS05ZTI1LWRkNWE4N2IwYTQwYyIsImVuY3J5cHRpb25LZXkiOiI0RTNTZERnMWNpc0IzVFFTWlJXTjRQY3d1WnA1eVhnYjRhTGZFX0pOQjRnIiwiYnJhbmNoIjoidDItbmV4dGpzLTg2MzY3IiwicmVwb093bmVyIjoiZHJhcGUtaW8iLCJyZXBvTmFtZSI6ImNyYmVuY2gtY3Vyc29yLTIwMjYtMDkiLCJwck51bWJlciI6NjYsImNvbW1pdFNoYSI6IjA0YTY1Nzg0NDM0MTNkZGZlOTgwZDdmYjMzMGIwOTlmZGFmNzczMDIiLCJwcm92aWRlciI6ImdpdGh1YiJ9fQ" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-web-light.png"><img alt="Fix in Web" width="99" height="28" src="https://cursor.com/assets/images/fix-in-web-dark.png"></picture></a></div>
<sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 04a6578443413ddfe980d7fb330b099fdaf77302. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup>
### Non-redirect actions force pending push
**Medium Severity**
<!-- DESCRIPTION START -->
`pendingPush` is computed as `redirectType !== RedirectType.replace` for every action, including those with no redirect (`redirectType` is `undefined`, so this is `true`). That value is written onto `state.pushRef` and `mutable` before any bailout. A follow-up MPA (string flight data, failed SPA, or external URL) then uses `assign` instead of `replace`, and a no-op action leaves `pendingPush` stuck true on the current state object.
<!-- DESCRIPTION END -->
<!-- BUGBOT_BUG_ID: 7485d4cf-5633-402f-ac18-12ff1852d792 -->
<!-- LOCATIONS START
packages/next/src/client/components/router-reducer/reducers/server-action-reducer.ts#L334-L337
LOCATIONS END -->
<div><a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9DVVJTT1IiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OmIzNmJiZjFiLWU4ZDAtNGMzMi1hYjViLTc2MTYwMGFmNDkxZCIsImVuY3J5cHRpb25LZXkiOiJUbTU1dFJ4WHZ3ZkR3RGtqa2N2TEFpQm9JdVBkMzFZd2ctLWRkMG9OYU00IiwiYnJhbmNoIjoidDItbmV4dGpzLTg2MzY3IiwicmVwb093bmVyIjoiZHJhcGUtaW8iLCJyZXBvTmFtZSI6ImNyYmVuY2gtY3Vyc29yLTIwMjYtMDkiLCJwcm92aWRlciI6ImdpdGh1YiJ9fQ" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a> <a href="https://cursor.com/agents?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9XRUIiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OmIzNmJiZjFiLWU4ZDAtNGMzMi1hYjViLTc2MTYwMGFmNDkxZCIsImVuY3J5cHRpb25LZXkiOiJUbTU1dFJ4WHZ3ZkR3RGtqa2N2TEFpQm9JdVBkMzFZd2ctLWRkMG9OYU00IiwiYnJhbmNoIjoidDItbmV4dGpzLTg2MzY3IiwicmVwb093bmVyIjoiZHJhcGUtaW8iLCJyZXBvTmFtZSI6ImNyYmVuY2gtY3Vyc29yLTIwMjYtMDkiLCJwck51bWJlciI6NjYsImNvbW1pdFNoYSI6IjA0YTY1Nzg0NDM0MTNkZGZlOTgwZDdmYjMzMGIwOTlmZGFmNzczMDIiLCJwcm92aWRlciI6ImdpdGh1YiJ9fQ" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-web-light.png"><img alt="Fix in Web" width="99" height="28" src="https://cursor.com/assets/images/fix-in-web-dark.png"></picture></a></div>
<sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 04a6578443413ddfe980d7fb330b099fdaf77302. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- BUGBOT_REVIEW -->
Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.
<!-- BUGBOT_FIX_ALL -->
<a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9BTExfSU5fQ1VSU09SIiwiZGF0YSI6eyJyZWRpc0tleSI6ImJ1Z2JvdC1tdWx0aTo4NTMyZTM1MS1lY2RkLTRlOTQtYThkYy0xN2ZjZmNkOWM3MzgiLCJlbmNyeXB0aW9uS2V5IjoiZVI4dG1iYU1vMWR4YmZsb29RSnV5dzJiWGQ2X1ltRENoeGlOaURHb3V5OCIsImJyYW5jaCI6InQyLW5leHRqcy04NjM2NyIsInJlcG9Pd25lciI6ImRyYXBlLWlvIiwicmVwb05hbWUiOiJjcmJlbmNoLWN1cnNvci0yMDI2LTA5IiwicHJvdmlkZXIiOiJnaXRodWIifX0" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix All in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a>
<!-- /BUGBOT_FIX_ALL -->
<!-- BUGBOT_AUTOFIX_REVIEW_FOOTNOTE_BEGIN -->
<sup>❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the [Cursor dashboard](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- BUGBOT_AUTOFIX_REVIEW_FOOTNOTE_END -->
<sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 04a6578443413ddfe980d7fb330b099fdaf77302. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup>
Drape (Deep Review) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | high | ✗ | — |
Before the change, navigate's accumulation started as [], so handleNavigationResult always set mutable.scrollableSegments to an array and handleMutable set apply=true. On a same-page click the leaf goes through the update path, so nothing gets pushed. The value stays null, becomes undefined, and the scroll/focus apply is no longer set. [grounded: diff] [consensus 3/3: valid=3]
The old code called revalidateEntireCache(state.nextUrl, newTree). The new code passes the interception-gated nextUrl, which is null unless the route is intercepted, so pingVisibleLinks builds cache keys with the wrong Next-URL. The HistoryUpdater re-ping later corrects this, so the effect is wasted prefetches. [grounded: diff] [consensus 3/3: valid=3]
When there is no redirect, redirectType is undefined, so pendingPush is true. That value is written into state.pushRef before the no-op early return. The old code only set pendingPush on a redirect, so this change leaks pendingPush=true into later reducers such as refresh. HistoryUpdater's same-URL guard limits the visible effect. [grounded: diff] [consensus 3/3: valid=3]
raw comments (3)
**Same-page link clicks no longer scroll**
`scrollableSegments` now starts as `null`, not `[]`. When no new page segment is created (e.g. clicking a link to the current page), `handleMutable` never sets `focusAndScrollRef.apply`, so scroll/focus is skipped. Initialize `scrollableSegments` to `[]` in navigate's paths; use `null` only for refresh/actions.
```
packages/next/src/client/components/segment-cache/navigation.ts:297 const accumulation: NavigationRequestAccumulation = {
packages/next/src/client/components/segment-cache/navigation.ts:298 scrollableSegments: null,
packages/next/src/client/components/segment-cache/navigation.ts:299 separateRefreshUrls: null,
packages/next/src/client/components/segment-cache/navigation.ts:300 }
packages/next/src/client/components/router-reducer/handle-mutable.ts:55 apply: shouldScroll
packages/next/src/client/components/router-reducer/handle-mutable.ts:56 ? isNotUndefined(mutable?.scrollableSegments)
packages/next/src/client/components/router-reducer/handle-mutable.ts:57 ? true
packages/next/src/client/components/router-reducer/handle-mutable.ts:58 : state.focusAndScrollRef.apply
packages/next/src/client/components/segment-cache/navigation.ts:314 (base) const accumulation: NavigationRequestAccumulation = {
packages/next/src/client/components/segment-cache/navigation.ts:315 (base) scrollableSegments: [],
```
**Revalidation re-prefetches links under the wrong Next-URL**
After a revalidating action, visible links are re-prefetched with nextUrl=null instead of state.nextUrl. If the state commits after the 300ms cooldown, as with an async unseeded navigation, the non-intercepted variant is fetched and wasted. Pass state.nextUrl, as refreshReducer does.
```
packages/next/src/client/components/router-reducer/reducers/server-action-reducer.ts:296 if (actionDidRevalidateCache) {
packages/next/src/client/components/router-reducer/reducers/server-action-reducer.ts:297 // Store whether this action triggered any revalidation
packages/next/src/client/components/router-reducer/reducers/server-action-reducer.ts:298 // The action queue will use this information to potentially
packages/next/src/client/components/router-reducer/reducers/server-action-reducer.ts:299 // trigger a refresh action if the action was discarded
packages/next/src/client/components/links.ts:353 const cacheKey = createCacheKey(instance.prefetchHref, nextUrl)
packages/next/src/client/components/router-reducer/reducers/refresh-reducer.ts:19 const currentNextUrl = state.nextUrl
packages/next/src/client/components/router-reducer/reducers/refresh-reducer.ts:20 const currentRouterState = state.tree
packages/next/src/client/components/router-reducer/reducers/refresh-reducer.ts:21 revalidateEntireCache(currentNextUrl, currentRouterState)
packages/next/src/client/components/router-reducer/reducers/server-action-reducer.ts:403 (base) includeNextUrl: Boolean(nextUrl),
```
**Non-redirecting actions now force a history push**
`pendingPush` is `true` whenever `redirectType` isn't replace, including when there's no redirect. It is also written onto `state.pushRef` before the no-op early return, so later reducers inherit it. Set pendingPush only when redirectLocation is defined, and after the bail-out.
```
packages/next/src/client/components/router-reducer/reducers/server-action-reducer.ts:335 const pendingPush = redirectType !== RedirectType.replace
packages/next/src/client/components/router-reducer/reducers/server-action-reducer.ts:336 state.pushRef.pendingPush = pendingPush
packages/next/src/client/components/router-reducer/reducers/server-action-reducer.ts:337 mutable.pendingPush = pendingPush
packages/next/src/client/components/router-reducer/reducers/server-action-reducer.ts:339 // Check if we can bail out without updating any state.
packages/next/src/client/components/router-reducer/handle-mutable.ts:41 pendingPush: isNotUndefined(mutable.pendingPush)
packages/next/src/client/components/router-reducer/handle-mutable.ts:42 ? mutable.pendingPush
packages/next/src/client/components/router-reducer/handle-mutable.ts:43 : state.pushRef.pendingPush,
packages/next/src/client/components/app-router.tsx:83 if (
packages/next/src/client/components/app-router.tsx:84 pushRef.pendingPush &&
packages/next/src/client/components/app-router.tsx:85 // Skip pushing an additional history entry if the canonicalUrl is the same as the current url.
```
Drape (Review) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | high | ✗ | — |
For a no-redirect action the target URL is state.canonicalUrl, and HistoryUpdater only calls pushState when pendingPush is set and the canonical URL differs from the current location; otherwise it calls replaceState. So the claimed extra history push does not happen. The stale true flag left on state.pushRef has no shown effect either. [invalid: contradiction] [consensus 3/3: invalid=3]
`nextUrl` is null unless the tree contains an interception route. pingVisibleLinks uses that value in createCacheKey, but navigations look up the cache with state.nextUrl. Before this change, revalidateEntireCache was called with state.nextUrl, so the change introduces a key mismatch for routes that can be intercepted. [grounded: diff] [consensus 3/3: valid=3]
Before the change, accumulation started as [], so a navigation that created no new segments (such as a same-page click) still passed [] to handleMutable, which set focusAndScrollRef.apply = true. Now it passes null, which becomes undefined, so apply keeps its previous state value and no scroll happens. [grounded: diff] [consensus 3/3: valid=3]
raw comments (3)
**Actions without redirect now default to history push**
`pendingPush` is true whenever there's no redirect, and it is written to `state.pushRef` before the early bail-out. So no-redirect actions push history, and the unchanged state keeps a stale `true`. Set pendingPush only when redirectLocation is defined, and don't mutate state before the bail-out.
```
packages/next/src/client/components/router-reducer/reducers/server-action-reducer.ts:335 const pendingPush = redirectType !== RedirectType.replace
packages/next/src/client/components/router-reducer/reducers/server-action-reducer.ts:336 state.pushRef.pendingPush = pendingPush
packages/next/src/client/components/router-reducer/reducers/server-action-reducer.ts:337 mutable.pendingPush = pendingPush
```
**Revalidation re-prefetches links under a null Next-Url**
When the current tree has no interception route, `nextUrl` here is null. revalidateEntireCache then re-prefetches visible links with a null Next-Url, where the base used state.nextUrl. The re-prefetches get the wrong key and header, so later navigations miss them for interceptable routes. Pass state.nextUrl to revalidateEntireCache, as refreshReducer does.
```
packages/next/src/client/components/router-reducer/reducers/server-action-reducer.ts:296 if (actionDidRevalidateCache) {
packages/next/src/client/components/router-reducer/reducers/server-action-reducer.ts:297 // Store whether this action triggered any revalidation
packages/next/src/client/components/router-reducer/reducers/server-action-reducer.ts:298 // The action queue will use this information to potentially
packages/next/src/client/components/router-reducer/reducers/server-action-reducer.ts:299 // trigger a refresh action if the action was discarded
packages/next/src/client/components/router-reducer/reducers/refresh-reducer.ts:19 const currentNextUrl = state.nextUrl
packages/next/src/client/components/router-reducer/reducers/refresh-reducer.ts:20 const currentRouterState = state.tree
packages/next/src/client/components/router-reducer/reducers/refresh-reducer.ts:21 revalidateEntireCache(currentNextUrl, currentRouterState)
```
**Same-page link click no longer scrolls**
`scrollableSegments` now starts as `null` and is only set to `[]` when a new segment is created. A navigation that creates none (same-page click, which only updates leaf segments) reaches `handleMutable` with undefined, so `focusAndScrollRef.apply` is not set. Initialize scrollableSegments to [] for regular navigations; keep null only for refresh.
```
packages/next/src/client/components/segment-cache/navigation.ts:298 scrollableSegments: null,
packages/next/src/client/components/router-reducer/ppr-navigations.ts:561 if (accumulation.scrollableSegments === null) {
packages/next/src/client/components/router-reducer/ppr-navigations.ts:562 accumulation.scrollableSegments = []
packages/next/src/client/components/router-reducer/ppr-navigations.ts:563 }
```
greptile · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | high | ✗ | — |
Mjolnir (Opus 5.5) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | high | ✗ | — |
The navigate paths used to start with []. Now they start with null, and only createCacheNodeOnNavigation fills the array. A same-URL navigation matches every segment, so the result stays null, which becomes undefined. handle-mutable.ts then keeps the previous focusAndScrollRef.apply value instead of setting it to true. [grounded: diff] [consensus 3/3: valid=3]
The old code passed state.nextUrl. The new code passes the action's request nextUrl, which is null unless the tree has an interception route. So pingVisibleLinks re-prefetches visible links with no Next-Url. [grounded: diff] [consensus 3/3: valid=3]
Same issue as finding 0. With null scrollableSegments, handleMutable keeps the stale apply flag, so same-page navigations lose the scroll-all behaviour they had before. [grounded: diff] [consensus 3/3: valid=3]
The old code only changed state.pushRef.pendingPush when there was a redirect. The new code sets it to true (redirectType is undefined) before the no-op bail-out that returns the same state, so the flag stays changed after a plain action. [grounded: diff] [consensus 3/3: valid=3]
raw comments (4)
[P2] Same-URL navigations no longer trigger scroll/focus handling
packages/next/src/client/components/segment-cache/navigation.ts:297-300 `navigateUsingPrefetchedRouteTree` and `navigateDynamicallyWithNoPrefetch` now start with `scrollableSegments: null` instead of `[]`, and the array is only created when `createCacheNodeOnNavigation` runs. If a navigation creates no new segments, the result is still `null`. The main case is clicking a `‹Link›` to the current URL, or calling `router.push` with it, where `isSamePageNavigation` refetches the page segment through the update path. `handleNavigationResult` then turns `null` into `mutable.scrollableSegments = undefined`. As a result, `handleMutable` keeps the previous `focusAndScrollRef.apply`, which layout-router has already reset to `false`, instead of setting it to `true` with an empty `segmentPaths`. Before this change, these navigations ran the "scroll all segments" behaviour. Now they do nothing, so the `[]` (navigation) vs `null` (refresh) distinction described in the `handleNavigationResult` comment is lost for ordinary navigations, not only for refresh and actions.
[P3] Revalidating server actions re-prefetch visible links with the wrong Next-Url
packages/next/src/client/components/router-reducer/reducers/server-action-reducer.ts:304 `revalidateEntireCache(nextUrl, state.tree)` now gets the action's request `nextUrl`. That value is `null` unless the current tree contains an interception route. The old code and `refreshReducer` both pass `state.nextUrl`. `revalidateEntireCache` calls `pingVisibleLinks`/`pingInvalidationListeners`, so after any revalidating action every visible link is re-prefetched with the cache key `(href, null)` and no Next-Url header. For routes that can be intercepted, this caches the non-intercepted variant under the wrong key. These prefetches are wasted, because the app-router effect later re-pings with the real `state.nextUrl` once the new tree commits. Passing `state.nextUrl` would match the previous behaviour.
[P2] Same-URL navigations no longer trigger scroll/focus handling
packages/next/src/client/components/segment-cache/navigation.ts:297-300 `navigateUsingPrefetchedRouteTree` and `navigateDynamicallyWithNoPrefetch` now start with `scrollableSegments: null` where they used to start with `[]`, and the array is now only created in `createCacheNodeOnNavigation`. That matters for normal (non-refresh) navigations that never reach the create path. The clearest case is clicking a `‹Link›` to the current URL, or calling `router.push(currentUrl)`. There, every segment matches in `updateCacheNodeOnNavigation`, so `scrollableSegments` stays `null`. `handleNavigationResult` turns that into `mutable.scrollableSegments = undefined`, and `handleMutable` then leaves `focusAndScrollRef.apply` at its previous value, which is normally `false`. Before this change, the empty array set `apply: true` with empty `segmentPaths`. `ScrollAndFocusHandler` treats that as "scroll for all segments", so the page scrolled into view. The `null` default was only needed for refresh, which goes through `navigateToSeededRoute`. Changing it in the regular navigation paths silently drops scroll/focus management for same-page navigations.
[P3] Server action reducer sets `pendingPush = true` on the shared state even when it bails out without navigating
packages/next/src/client/components/router-reducer/reducers/server-action-reducer.ts:587-603 `pendingPush` is computed as `redirectType !== RedirectType.replace` and written to `state.pushRef.pendingPush` before the "no redirect, no revalidation, no flight data" bail-out. That bail-out returns the same `state` object, so every plain action leaves `pushRef.pendingPush` mutated to `true`. Before this change, the reducer only touched it when there was a redirect. Because nothing re-renders, `HistoryUpdater` never resets the flag. Later reducers that inherit `state.pushRef.pendingPush` will then push instead of replace when the URL changes. This applies to `handleMutable` callers that don't set `mutable.pendingPush`, and to the `handleExternalUrl` calls in `server-patch-reducer`/`hmr-refresh-reducer`. The result is an extra history entry, or `location.assign` instead of `location.replace`. Moving the assignment after the bail-out check restores the old behavior.
Mjolnir (Sonnet 5.5) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | high | ✗ | — |
The removed code called `revalidateEntireCache(state.nextUrl, newTree)`. The new code passes the request-only `nextUrl`, which is null unless the current tree has an interception route and otherwise prefers `previousNextUrl`. The post-action `navigateUsingSegmentCache` call also gets this `nextUrl`, while `navigateReducer` and `refreshReducer` use `state.nextUrl`. So re-prefetches and the route-cache lookup are keyed differently from later Link navigations, which can cause cache misses or the wrong interception match. [grounded: diff] [consensus 3/3: valid=3]
raw comments (1)
[P2] Action reducer uses the request-only `nextUrl` for cache invalidation and the navigation lookup
`nextUrl` here is the value built for the action fetch. It is `null` unless the current tree contains an interception route, and it prefers `previousNextUrl`. The revalidation ping and the post-action `navigate(...)` call both receive it. `revalidateEntireCache(nextUrl, ...)` re-prefetches visible links, and `createCacheKey(href, nextUrl)` builds the route-cache key from it. The old code used `state.nextUrl` for the revalidation, and the normal `navigateReducer` passes `state.nextUrl` to `navigate`. When `state.nextUrl` is set but the tree has no interception route (for example after the first navigation), the re-prefetched entries and the lookup for a redirect target use a different key than later `‹Link›` navigations. That can cause cache misses or wrong interception matching for routes that vary on Next-Url. The fix is to keep using `nextUrl` for the action request and pass `state.nextUrl` to `revalidateEntireCache` and to `navigateUsingSegmentCache`.
qodo · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | high | ✗ | — |
The new code sets pendingPush = (redirectType !== replace), which is true when there is no redirect. It writes this into state.pushRef before the no-op bailout returns the same state. The old code only touched pendingPush when redirectLocation was set, so this is a new behavior change. Its practical impact is limited. [grounded: diff] [consensus 3/3: valid=3]
Reusing shared cached layouts when there is no revalidation is the intended navigation semantics, as the in-code comment says. Same-page leaf segments still bypass the reuse branch through isSamePageNavigation, and revalidating actions set shouldRefreshDynamicData, so the seed data is used. Nothing stale is shown. [invalid: contradiction] [consensus 3/3: invalid=3]
raw comments (4)
<img src="https://img.shields.io/badge/Medium-634FD1?style=flat-square" height="20px" alt="Remediation recommended">
2\. No-op actions can alter browser history <code>🐞 Bug</code> <code>≡ Correctness</code>
<pre>
<b><i>serverActionReducer</i></b> sets <b><i>state.pushRef.pendingPush</i></b> to true whenever <b><i>redirectType</i></b> is undefined,
even before its no-navigation bailout returns the same state object. After an action without a
redirect, revalidation, or Flight data, a later server patch that preserves this flag can make
<b><i>HistoryUpdater</i></b> push an extra history entry when the canonical and browser URLs differ.
</pre>
<details>
<summary><strong>Agent Prompt</strong></summary>
```
## Issue description
A server action without a redirect sets the shared `pendingPush` flag before returning through the no-navigation bailout. The stale flag can be preserved by a later router update and cause an unintended browser history entry.
## Fix Focus Areas
- packages/next/src/client/components/router-reducer/reducers/server-action-reducer.ts[335-350]
## Recommended Fix
Compute `pendingPush` as true only when `redirectLocation` exists and the redirect type is not `replace`. Avoid directly mutating `state.pushRef` before the bailout; pass the correctly scoped value through `mutable` and the navigation handlers only when an actual navigation occurs.
```
<code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
</details>
<img src="https://img.shields.io/badge/High-634FD1?style=flat-square" height="20px" alt="Action required">
1\. Server action updates show stale content <code>🐞 Bug</code> <code>≡ Correctness</code>
<pre>
The newly added <b><i>seedData</i></b> handling in <b><i>updateCacheNodeOnNavigation</i></b> runs only after the
existing-cache reuse branch, so a non-revalidating server action reuses matching cache nodes instead
of applying its returned seed data. This occurs when an action returns Flight data without
revalidating and the target shares a cached layout or segment, leaving that response data out of the
rendered cache.
</pre>
<details>
<summary><strong>Agent Prompt</strong></summary>
```
Issue description
Seeded Server Action data is checked only after reusable cache nodes. As a result, action responses that do not trigger cache revalidation can be discarded for matching cached segments.
Fix Focus Areas
- packages/next/src/client/components/router-reducer/ppr-navigations.ts[267-298]
- packages/next/src/client/components/router-reducer/ppr-navigations.ts[569-606]
Recommended Fix
Check for non-null `seedData` before either existing-cache reuse branch in both navigation traversal functions, then retain the existing reuse behavior only when no action seed data was supplied.
```
<code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
</details>
<h3>PR Summary by Qodo</h3>
Unify refresh and server actions with Segment Cache navigation
<code>✨ Enhancement</code> <code>🐞 Bug fix</code> <code>🕐 40+ Minutes</code>
<img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider">
<details>
<summary>AI Description</summary>
<dl>
<dd>
<br/>
><pre>
>• Routes refreshes and server-action redirects through shared Segment Cache navigation.
>• Seeds router state from action Flight responses before fetching missing dynamic data.
>• Preserves interception context while evicting stale cache entries after revalidation.
></pre>
</dd>
</dl>
</details>
<details>
<summary>Diagram</summary>
<dl>
<dd>
<br/>
```mermaid
graph TD
A["Refresh or action"] --> B{"Flight seed?"} -->|Yes| C["Seeded navigation"] --> E["PPR traversal"] --> F["Router cache"]
B -->|No| D["Cache navigation"] --> E
E -->|"Missing data"| G["RSC server"] -->|"Dynamic Flight"| E
```
</dd>
</dl>
</details>
<details>
<summary>High-Level Assessment</summary>
<dl>
<dd>
<br/>
>The shared Segment Cache navigation pipeline is preferable to retaining separate refresh and server-action cache mutation implementations. It centralizes route diffing, seeded response handling, dynamic fetching, MPA fallback, scrolling, and invalidation semantics, reducing divergence between navigation entry points.
</dd>
</dl>
</details>
<details>
<summary> Files changed (7) <code> +347 / -213 </code> </summary>
<dl>
<dd>
<br/>
<details>
<summary>Enhancement (6) <code> +345 / -213 </code></summary>
<dl>
<dd>
<details>
<summary>ppr-navigations.ts<code>Consume action seeds during recursive PPR navigation</code> <code>+78/-3</code></summary>
<br/>
>Consume action seeds during recursive PPR navigation
>
><pre>
>• Adds action-provided RSC and head seeds as a preferred cache-node source ahead of prefetched data, propagating them through parallel routes. Dynamic refreshes now discard stale sibling segment maps, and scrollable segments remain null when no new page is introduced.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/61/files#diff-18ce84be969580c9ff353b4608bb4e63ee4b66c537f88b8e702e4ae6cfe76a98'>packages/next/src/client/components/router-reducer/ppr-navigations.ts</a>
</details>
<details>
<summary>refresh-reducer.ts<code>Model router refresh as a seeded navigation</code> <code>+31/-6</code></summary>
<br/>
>Model router refresh as a seeded navigation
>
><pre>
>• Replaces the dedicated Segment Cache refresh call with navigation to the current route while forcing dynamic-data refresh. Preserves the prior next URL when required to match an existing interception route.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/61/files#diff-a611683cae3b53234b58b66764ff44a653ae6a795195a87d67f2b8bda25e4471'>packages/next/src/client/components/router-reducer/reducers/refresh-reducer.ts</a>
</details>
<details>
<summary>server-action-reducer.ts<code>Route server-action effects through shared navigation</code> <code>+155/-143</code></summary>
<br/>
>Route server-action effects through shared navigation
>
><pre>
>• Replaces manual Flight tree patching and cache construction with seeded or regular Segment Cache navigation. It carries rendered-search and interception metadata, evicts prefetches after revalidation, handles internal and external redirects, and skips navigation for actions without side effects.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/61/files#diff-f0d65554a4d7e89691b3471005a0c82b19459186b0f5f3ab2d1dc2f7a927ca77'>packages/next/src/client/components/router-reducer/reducers/server-action-reducer.ts</a>
</details>
<details>
<summary>navigation.ts<code>Generalize Segment Cache navigation for seeds and refreshes</code> <code>+65/-61</code></summary>
<br/>
>Generalize Segment Cache navigation for seeds and refreshes
>
><pre>
>• Introduces navigateToSeededRoute and propagates dynamic-refresh intent through prefetched and unprefetched navigation paths. Full refreshes request the entire dynamic route, while nullable scroll targets preserve existing refresh behavior.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/61/files#diff-9b885c642cd06ad4ddc90475efd7d5aee9759f2e429a9c8b1d6bcde27fa6e4f8'>packages/next/src/client/components/segment-cache/navigation.ts</a>
</details>
<details>
<summary>app-render.tsx<code>Attach route context to RSC payloads</code> <code>+8/-0</code></summary>
<br/>
>Attach route context to RSC payloads
>
><pre>
>• Adds rendered-search and interception eligibility metadata to server-action and regular dynamic RSC responses so client navigation can reconstruct the correct route context.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/61/files#diff-a3e2e024db1faa1b501e0dd6040eaaf0d931cb9878ae0fb0f4c3658daa982768'>packages/next/src/server/app-render/app-render.tsx</a>
</details>
<details>
<summary>app-router-types.ts<code>Type new RSC navigation metadata</code> <code>+8/-0</code></summary>
<br/>
>Type new RSC navigation metadata
>
><pre>
>• Extends navigation and action Flight response contracts with rendered-search and interception eligibility fields.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/61/files#diff-799ad06e41c9251f83ce3bffb8d6d4370fc41ba67f9700e817a231a03126c996'>packages/next/src/shared/lib/app-router-types.ts</a>
</details>
</dd>
</dl>
</details>
<details>
<summary>Refactor (1) <code> +2 / -0 </code></summary>
<dl>
<dd>
<details>
<summary>navigate-reducer.ts<code>Declare normal navigations as non-refreshing</code> <code>+2/-0</code></summary>
<br/>
>Declare normal navigations as non-refreshing
>
><pre>
>• Passes an explicit false dynamic-refresh flag into Segment Cache navigation, distinguishing ordinary navigations from refresh and revalidation flows.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/61/files#diff-af4a773de0b4d751f4d5ee8dc9857c8726e0e52966a8f27bff3089d25b68ca3c'>packages/next/src/client/components/router-reducer/reducers/navigate-reducer.ts</a>
</details>
</dd>
</dl>
</details>
</dd>
</dl>
</details>
<h3>Code Review by Qodo</h3>
<code>🐞 Bugs (2)</code> <code>📘 Rule violations (0)</code> <code>📜 Skill insights (0)</code>
<img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider">
<br/>
<img src="https://img.shields.io/badge/High-634FD1?style=flat-square" height="20px" alt="Action required">
<details>
<summary> 1. Server action updates show stale content <code>🐞 Bug</code> <code>≡ Correctness</code></summary>
<br/>
> <details open>
><summary>Description</summary>
><br/>
>
><pre>
>The newly added <b><i>seedData</i></b> handling in <b><i>updateCacheNodeOnNavigation</i></b> runs only after the
>existing-cache reuse branch, so a non-revalidating server action reuses matching cache nodes instead
>of applying its returned seed data. This occurs when an action returns Flight data without
>revalidating and the target shares a cached layout or segment, leaving that response data out of the
>rendered cache.
></pre>
></details>
> <details>
><summary>Code</summary>
><br/>
>
><code>[packages/next/src/client/components/router-reducer/ppr-navigations.ts[276]](https://github.com/drape-io/crbench-qodo-2026-09/pull/61/files#diff-18ce84be969580c9ff353b4608bb4e63ee4b66c537f88b8e702e4ae6cfe76a98R276-R276)</code>
>
>```diff
>+ } else if (seedData !== null) {
>```
></details>
> <details>
><summary>Evidence</summary>
><br/>
>
><pre>
>The server-action reducer sets <b><i>shouldRefreshDynamicData</i></b> only when the action reports revalidation,
>then supplies its returned seed data to the seeded navigation path. That path passes the flag and
>seed data into the PPR traversal, whose unchanged-cache branch precedes the added seed-data branch;
>therefore a non-revalidating action can reuse the old cache rather than consume its response.
></pre>
>
> <code>[packages/next/src/client/components/router-reducer/reducers/server-action-reducer.ts[383-419]](https://github.com/drape-io/crbench-qodo-2026-09/blob/df5c3fe16c6d2eba3e2b93442dec8bd0487f0b57/packages/next/src/client/components/router-reducer/reducers/server-action-reducer.ts/#L383-L419)</code>
> <code>[packages/next/src/client/components/segment-cache/navigation.ts[231-245]](https://github.com/drape-io/crbench-qodo-2026-09/blob/df5c3fe16c6d2eba3e2b93442dec8bd0487f0b57/packages/next/src/client/components/segment-cache/navigation.ts/#L231-L245)</code>
> <code>[packages/next/src/client/components/router-reducer/ppr-navigations.ts[267-298]](https://github.com/drape-io/crbench-qodo-2026-09/blob/df5c3fe16c6d2eba3e2b93442dec8bd0487f0b57/packages/next/src/client/components/router-reducer/ppr-navigations.ts/#L267-L298)</code>
> <code>[packages/next/src/client/components/router-reducer/ppr-navigations.ts[569-606]](https://github.com/drape-io/crbench-qodo-2026-09/blob/df5c3fe16c6d2eba3e2b93442dec8bd0487f0b57/packages/next/src/client/components/router-reducer/ppr-navigations.ts/#L569-L606)</code>
></details>
> <details>
><summary>Agent prompt</summary>
><br/>
>
>```
>The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
>
>Issue description
>Seeded Server Action data is checked only after reusable cache nodes. As a result, action responses that do not trigger cache revalidation can be discarded for matching cached segments.
>
>Fix Focus Areas
>- packages/next/src/client/components/router-reducer/ppr-navigations.ts[267-298]
>- packages/next/src/client/components/router-reducer/ppr-navigations.ts[569-606]
>
>Recommended Fix
>Check for non-null `seedData` before either existing-cache reuse branch in both navigation traversal functions, then retain the existing reuse behavior only when no action seed data was supplied.
>```
> <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
></details>
<hr/>
</details>
<br/>
<img src="https://img.shields.io/badge/Medium-634FD1?style=flat-square" height="20px" alt="Remediation recommended">
<details>
<summary> 2. No-op actions can alter browser history <code>🐞 Bug</code> <code>≡ Correctness</code></summary>
<br/>
> <details open>
><summary>Description</summary>
><br/>
>
><pre>
><b><i>serverActionReducer</i></b> sets <b><i>state.pushRef.pendingPush</i></b> to true whenever <b><i>redirectType</i></b> is undefined,
>even before its no-navigation bailout returns the same state object. After an action without a
>redirect, revalidation, or Flight data, a later server patch that preserves this flag can make
><b><i>HistoryUpdater</i></b> push an extra history entry when the canonical and browser URLs differ.
></pre>
></details>
> <details>
><summary>Code</summary>
><br/>
>
><code>[packages/next/src/client/components/router-reducer/reducers/server-action-reducer.ts[R335-337]](https://github.com/drape-io/crbench-qodo-2026-09/pull/61/files#diff-f0d65554a4d7e89691b3471005a0c82b19459186b0f5f3ab2d1dc2f7a927ca77R335-R337)</code>
>
>```diff
>+ const pendingPush = redirectType !== RedirectType.replace
>+ state.pushRef.pendingPush = pendingPush
>+ mutable.pendingPush = pendingPush
>```
></details>
> <details>
><summary>Evidence</summary>
><br/>
>
><pre>
>The changed reducer assigns <b><i>pendingPush</i></b> before checking whether navigation is needed and directly
>mutates the existing state. <b><i>handleMutable</i></b> preserves the existing flag when a later update does not
>specify one, server patches take that path, and <b><i>HistoryUpdater</i></b> calls <b><i>pushState</i></b> when the
>preserved flag is true and the canonical URL differs from the browser URL.
></pre>
>
> <code>[packages/next/src/client/components/router-reducer/reducers/server-action-reducer.ts[335-350]](https://github.com/drape-io/crbench-qodo-2026-09/blob/df5c3fe16c6d2eba3e2b93442dec8bd0487f0b57/packages/next/src/client/components/router-reducer/reducers/server-action-reducer.ts/#L335-L350)</code>
> <code>[packages/next/src/client/components/router-reducer/handle-mutable.ts[36-52]](https://github.com/drape-io/crbench-qodo-2026-09/blob/df5c3fe16c6d2eba3e2b93442dec8bd0487f0b57/packages/next/src/client/components/router-reducer/handle-mutable.ts/#L36-L52)</code>
> <code>[packages/next/src/client/components/router-reducer/reducers/server-patch-reducer.ts[71-84]](https://github.com/drape-io/crbench-qodo-2026-09/blob/df5c3fe16c6d2eba3e2b93442dec8bd0487f0b57/packages/next/src/client/components/router-reducer/reducers/server-patch-reducer.ts/#L71-L84)</code>
> <code>[packages/next/src/client/components/app-router.tsx[83-94]](https://github.com/drape-io/crbench-qodo-2026-09/blob/df5c3fe16c6d2eba3e2b93442dec8bd0487f0b57/packages/next/src/client/components/app-router.tsx/#L83-L94)</code>
></details>
> <details>
><summary>Agent prompt</summary>
><br/>
>
>```
>The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
>
>## Issue description
>A server action without a redirect sets the shared `pendingPush` flag before returning through the no-navigation bailout. The stale flag can be preserved by a later router update and cause an unintended browser history entry.
>
>## Fix Focus Areas
>- packages/next/src/client/components/router-reducer/reducers/server-action-reducer.ts[335-350]
>
>## Recommended Fix
>Compute `pendingPush` as true only when `redirectLocation` exists and the redirect type is not `replace`. Avoid directly mutating `state.pushRef` before the bailout; pass the correctly scoped value through `mutable` and the navigation handlers only when an actual navigation occurs.
>```
> <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
></details>
<hr/>
</details>
<img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider">
<!-- qodo-context:start -->
<details><summary><strong>Context sources</strong></summary>
<div>Review mode: <code>🧠 Deep</code>: This is a high-density, cross-cutting router and server-action change spanning multiple independent navigation, refresh, cache, interception, and response-contract paths, making redundant review materially valuable.</div>
<!-- qodo-context:end -->
</details>
<img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider">
<!-- qodo-daily-tip:start -->
<details>
<summary><strong>Tip of the day</strong></summary>
<br/>
<pre>💡 Did you know, you can reply 'qodo' on any finding to push back, ask questions, or dig deeper</pre>
<a href="https://docs.qodo.ai/tips-and-tricks">More tips ↗</a> | <a href="https://app.qodo.ai/configurations?tab=display-preferences">Customize Qodo ↗</a> | <a href="https://docs.qodo.ai">Qodo docs ↗</a>
</details>
<img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider">
<!-- qodo-daily-tip:end -->
<!-- https://github.com/drape-io/crbench-qodo-2026-09/commit/df5c3fe16c6d2eba3e2b93442dec8bd0487f0b57 -->
<a href="https://www.qodo.ai"><img src="https://www.qodo.ai/wp-content/uploads/2025/03/qodo-logo.svg" width="80" alt="Qodo Logo"></a>