Fix error message mismatch for navigation API in Proxy #86627
+59
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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()orredirect()) 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 ifisNextRouterErrorwas true. This misuse of the error overlay confused users by misidentifying the source of the error.How?
I modified
packages/next/src/client/index.tsxto 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.tsand a corresponding fixturetest/development/app-dir/server-navigation-error/proxy.tsto verify that errors fromproxy.tsare displayed correctly in the overlay.Fixes #86609