Skip to content

Conversation

@rajnish93
Copy link

What?

This PR fixes a bug where the client-side error overlay would incorrectly display "Next.js navigation API is not allowed to be used in Pages Router" when a navigation API error (like notFound() or redirect()) occurred within a Proxy or Middleware.

Why?

As reported in issue #86609, when notFound() is called inside a Proxy (e.g., proxy.ts), the server correctly generates an error message stating "Next.js navigation API is not allowed to be used in Proxy.". However, the client-side error handling logic unconditionally overwrote this message with a generic "Pages Router" error if isNextRouterError was true. This misuse of the error overlay confused users by misidentifying the source of the error.

How?

I modified packages/next/src/client/index.tsx to add a check before overwriting the error message. The code now verifies if the existing error message already contains "Middleware" or "Proxy". If it does, the specific, correct error message from the server is preserved.

I also added a regression test in test/development/app-dir/server-navigation-error/server-navigation-error.test.ts and a corresponding fixture test/development/app-dir/server-navigation-error/proxy.ts to verify that errors from proxy.ts are displayed correctly in the overlay.

Fixes #86609

@ijjk
Copy link
Member

ijjk commented Nov 28, 2025

Allow CI Workflow Run

  • approve CI run for commit: 6b55f46

Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer

1 similar comment
@ijjk
Copy link
Member

ijjk commented Nov 28, 2025

Allow CI Workflow Run

  • approve CI run for commit: 6b55f46

Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error Mismatch when using notFound() inside proxy.

2 participants