Skip to main content
GoodFirstPicks
DashboardIssuesReposLeaderboard

GoodFirstPicks by Leaveitblank © 2026

CreatorRequest a RepoPrivacy PolicyTerms of Service
`router.push()` reuses cached redirect from prefetch without fresh middleware evaluation | GoodFirstPicks

`router.push()` reuses cached redirect from prefetch without fresh middleware evaluation

vercel/next.js 1 comments 1mo ago
View on GitHub
mediumopenScope: somewhat clearSkill match: maybeNext.jsTypeScriptReact

Why this is a good first issue

The issue involves middleware evaluation and caching behavior in Next.js routing.

AI Summary

The issue occurs when `router.push()` reuses a cached redirect from a prefetched route without re-evaluating middleware, causing incorrect navigation behavior. The fix likely involves modifying how redirects are cached and ensuring middleware is re-evaluated when necessary. The scope is somewhat clear but requires understanding of Next.js routing and middleware internals.

Issue Description

Link to the code that reproduces this issue

https://github.com/KumarNitin19/nextjs-prefetch-redirect-bug

To Reproduce

I'm running middleware that conditionally redirects based on a cookie value. The / route is protected and redirects to /process when the processingComplete cookie is not set.

Steps to Reproduce:

  1. Navigate to /process page (no cookie set)
  2. Page renders with a sidebar containing <Link href="/">Dashboard</Link>
  3. Next.js automatically prefetches the / route
  4. Middleware evaluates and returns 307 redirect to /process (because cookie is false)
  5. Click "Start Process" button which:
    • Performs async work (simulated 2 seconds)
    • Sets cookie: processingComplete=true
    • Calls router.push('/') to navigate to dashboard
  6. Observe: User stuck on /process page, no navigation occurs

Live Demo (Vercel): https://nextjs-prefetch-redirect-bug.vercel.app/

Current vs. Expected behavior

Expected: When router.push('/') is called after the cookie changes:

  • Fresh GET request should be made to /
  • Middleware should re-evaluate with new cookie value
  • Middleware should allow navigation (no redirect)
  • User navigates to Dashboard

Current:

  • No fresh request is made to /
  • Router reuses the cached redirect from initial prefetch
  • Middleware is never re-evaluated
  • User stuck on /process page

The router appears to cache the redirect response from the prefetch and reuses it on router.push() without checking if the state has changed.

Provide environment information

Relevant Packages:

  • next: 15.5.8 (also tested on 15.5.9, bug reproduces on both)
  • react: 19.1.0
  • react-dom: 19.1.0
  • typescript: ^5

Which area(s) are affected? (Select all that apply)

Linking and Navigating, Middleware

Which stage(s) are affected? (Select all that apply)

Vercel (Deployed), Other (Deployed), next build (local)

Additional context

Workarounds:

  1. Disable prefetch (works reliably): `<

GitHub Labels

MiddlewareLinking and Navigatinglinear: next

Want to work on this?

Claim this issue to let others know you're working on it. You'll earn 10 points when you complete it!

Risk Flags

  • middleware evaluation
  • caching behavior
Loading labels...

Details

Points10 pts
Difficultymedium
Scopesomewhat clear
Skill Matchmaybe
Test Focusedno