Skip to content

fix(nextjs): Include basePath in request url of Pages Router errors - #24985

Open
chargome wants to merge 1 commit into
developfrom
pages-router-requesturl
Open

chargome wants to merge 1 commit into
developfrom
pages-router-requesturl

Conversation

@chargome

@chargome chargome commented Oct 2, 2026

Copy link
Copy Markdown
Member

Next.js removes the basePath from req.url before running Pages Router data fetchers and API routes. So errors captured there reported a request.url without it, for example http://localhost:3000/foo/bar instead of http://localhost:3000/base/foo/bar.

Next keeps the URL as it was originally requested in its internal request meta (initURL), set before the basePath is removed. We now take the path and query from there. The origin still comes from the request headers, because Next builds the absolute initURL from 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

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>
@chargome

chargome commented Oct 2, 2026

Copy link
Copy Markdown
Member Author

bugbot run

@chargome chargome self-assigned this Oct 2, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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
chargome marked this pull request as ready for review October 2, 2026 11:37
@chargome
chargome requested a review from a team as a code owner October 2, 2026 11:37
@chargome
chargome requested review from logaretm, nicohrubec and s1gr1d and removed request for a team October 2, 2026 11:37

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@sentry/nextjs: request.url of Pages Router data fetcher errors is missing basePath

1 participant