nextjs - 💡(How to fix) Fix Client-side navigation fails when server component uses redirect() with Middleware/Proxy in production build [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vercel/next.js#87241Fetched 2026-04-08 02:07:28
View on GitHub
Comments
1
Participants
2
Timeline
8
Reactions
0
Author
Timeline (top)
labeled ×4closed ×1commented ×1issue_type_added ×1

Client-side navigation (via <Link>) fails when:

  1. Middleware/Proxy performs a redirect to add query params
  2. Server Component also performs a redirect() to add different query params

Error Message

  1. Observe the page fails to render (blank page or error)

Browser Console Error:

Root Cause

Client-side navigation (via <Link>) fails when:

  1. Middleware/Proxy performs a redirect to add query params
  2. Server Component also performs a redirect() to add different query params

Fix Action

Fix / Workaround

Workaround:

Using prefetch={false} on the Link component works around the issue:

<Link href="/my-internal-redirect" prefetch={false}>## Files involved:

Code Example

export function proxy(request: NextRequest) {
  const url = new URL(request.url);
  if (!url.searchParams.has("proxy-params")) {
    url.searchParams.set("proxy-params", "my-proxy");
    return NextResponse.redirect(url.toString());
  }
  return NextResponse.next();
}

---

import Link from "next/link";

export default function MyStartPage() {
  return (
    <div>
        <Link href="/my-internal-redirect">
          Go to Internal Redirect Page        </Link>
    </div>
  );
}

---

export default async function MyInternalRedirectPage({ searchParams }: Props) {
  const params = await searchParams;
  if (!params["internal-params"]) {
    currentParams.set("internal-params", "my-params");
    redirect(`/my-internal-redirect?${currentParams.toString()}`);
  }
  return <div>...</div>;
}

---

Operating System:
  MacOs 26.1
Binaries:
  Node: 22.17.1
  npm: 10.9.2
Relevant Packages:
  next: 16.0.10
  react: 19.2.1
  react-dom: 19.2.1
Next.js Config:
  output: N/A & standalone
RAW_BUFFERClick to expand / collapse

To Reproduce

  1. Setting nextjs 16 app router project and add below source code
  2. Run npm run build then npm run start
  3. Navigate to http://localhost:3000/my-start
  4. Click the "Go to Internal Redirect Page" link
  5. Observe the page fails to render (blank page or error)

Note: The issue does NOT occur in development mode (npm run dev). Note: Direct URL access works correctly, only client-side navigation via Link fails.

src/proxy.ts (Middleware/Proxy):

export function proxy(request: NextRequest) {
  const url = new URL(request.url);
  if (!url.searchParams.has("proxy-params")) {
    url.searchParams.set("proxy-params", "my-proxy");
    return NextResponse.redirect(url.toString());
  }
  return NextResponse.next();
}

src/app/my-startpage.tsx (Server Component):

import Link from "next/link";

export default function MyStartPage() {
  return (
    <div>
        <Link href="/my-internal-redirect">
          Go to Internal Redirect Page →
        </Link>
    </div>
  );
}

src/app/my-internal-redirect/page.tsx (Server Component):

export default async function MyInternalRedirectPage({ searchParams }: Props) {
  const params = await searchParams;
  if (!params["internal-params"]) {
    currentParams.set("internal-params", "my-params");
    redirect(`/my-internal-redirect?${currentParams.toString()}`);
  }
  return <div>...</div>;
}

Current vs. Expected behavior

Current behavior: When clicking a Link to navigate from /my-start to /my-internal-redirect in production build, the page fails to render. The client-side navigation appears to break when handling multiple redirects (one from Middleware/Proxy and one from Server Component's redirect()).

Expected behavior: The page should render correctly after both redirects complete:

  1. Middleware/Proxy adds proxy-params=my-proxy
  2. Server Component adds internal-params=my-params
  3. Final URL: /my-internal-redirect?proxy-params=my-proxy&internal-params=my-params
  4. Page renders successfully showing the params

Provide environment information

Operating System:
  MacOs 26.1
Binaries:
  Node: 22.17.1
  npm: 10.9.2
Relevant Packages:
  next: 16.0.10
  react: 19.2.1
  react-dom: 19.2.1
Next.js Config:
  output: N/A & standalone

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

Redirects, Middleware, Linking and Navigating

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

next build (local), next start (local)

Additional context

Summary

Client-side navigation (via <Link>) fails when:

  1. Middleware/Proxy performs a redirect to add query params
  2. Server Component also performs a redirect() to add different query params

Browser Console Error:

Throttling navigation to prevent the browser from hanging. See <URL>. Command line switch --disable-ipc-flooding-protection can be used to bypass the protection

Key observations:

  • ✅ Works in npm run dev (development mode)
  • ✅ Works with direct URL access (full page load)
  • ✅ Works with client-side hard navigation via Link in production build
  • ❌ Fails only with client-side navigation via Link(include prefetch) in production build

Workaround:

Using prefetch={false} on the Link component works around the issue:

<Link href="/my-internal-redirect" prefetch={false}>## Files involved:

Real-world Use Case & Migration Context

Business Requirements:

  1. Middleware/Proxy: Needs to maintain common search params across all pages (e.g., tracking params, session identifiers, feature flags)
  2. Specific Pages: Some pages need to initialize their own search params on first visit (e.g., default filters, page-specific state)

This is a common pattern where:

  • Middleware/Proxy handles global/shared query params
  • Individual pages handle page-specific query params

Migration Context:

  • This issue was discovered during migration from Next.js 14 to Next.js 16
  • The same code pattern worked correctly in Next.js 14
  • After upgrading to Next.js 16, multiple redirects causes infinite loop

extent analysis

TL;DR

The most likely fix is to disable prefetching on the Link component by setting prefetch={false} to prevent infinite redirects.

Guidance

  • The issue is caused by the combination of Middleware/Proxy and Server Component redirects, which leads to an infinite loop when using client-side navigation with prefetching.
  • To verify the issue, try disabling prefetching on the Link component by setting prefetch={false} and check if the page renders correctly.
  • Consider updating the Middleware/Proxy to handle the redirects in a way that avoids infinite loops, such as by checking for the presence of certain query parameters before redirecting.
  • If the issue persists, try using the use client directive in your Server Component to disable server-side rendering for that specific page.

Example

// Disable prefetching on the Link component
<Link href="/my-internal-redirect" prefetch={false}>
  Go to Internal Redirect Page →
</Link>

Notes

  • This issue seems to be specific to Next.js 16 and may not occur in earlier versions.
  • The prefetch={false} workaround may have performance implications, as it disables prefetching for the linked page.

Recommendation

Apply the workaround by setting prefetch={false} on the Link component, as it is a simple and effective solution to prevent the infinite redirects. However, it's recommended to investigate and update the Middleware/Proxy to handle redirects in a way that avoids infinite loops for a more robust solution.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING