fix(nextjs): Include basePath in request url of Pages Router errors - #24985
Merged
Merged
Conversation
Next.js strips the basePath from req.url before running Pages Router data fetchers and API routes, so captured errors reported a request url without it. Use the originally requested path and query from Next.js' initURL request meta instead, keeping the origin from the request headers. Fixes #24975 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
Author
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit ca14e8d. Configure here.
chargome
marked this pull request as ready for review
October 2, 2026 11:37
chargome
requested review from
logaretm,
nicohrubec and
s1gr1d
and removed request for
a team
October 2, 2026 11:37
nicohrubec
reviewed
Oct 5, 2026
Simplify reading the original path and query from initURL with core's parseUrl, and assert that streamed segment spans also carry the basePath in url.full. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
chargome
added a commit
that referenced
this pull request
Oct 6, 2026
…rs (#25064) Backport of: #24985 ## Differences to the original PR - `packages/nextjs/src/common/pages-router-instrumentation/wrapApiHandlerWithSentry.ts`: v10 still has the older API route wrapper that starts its own `http.server` span, so the swap to `pagesRouterRequestToRequestData` lands on the `normalizedRequest` used there instead of the inline `setSDKProcessingMetadata` call. Because that span builds `url.full` and `url.path` from the same request data, on v10 those span attributes also include the `basePath` now. - `dev-packages/e2e-tests/test-applications/nextjs-15-basepath/tests/pages-router-request-url.test.ts`: v10 does not stream spans by default, so the tests wait for the `http.server` transaction and check its `request.url` instead of the streamed segment span's `url.full`. The transaction's `request.url` has no query string (it is in `query_string`), so the assertion leaves it out. --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Next.js removes the
basePathfromreq.urlbefore running Pages Router data fetchers and API routes. So errors captured there reported arequest.urlwithout it, for examplehttp://localhost:3000/foo/barinstead ofhttp://localhost:3000/base/foo/bar.Next keeps the URL as it was originally requested in its internal request meta (
initURL), set before thebasePathis removed. We now take the path and query from there. The origin still comes from the request headers, because Next builds the absoluteinitURLfrom its own hostname and port, which can differ from the public host behind a proxy. API routes were affected the same way, so they're covered too.Fixes #24975