fix(nextjs): Keep the Pages Router runtime out of App Router client bundles - #24188
Merged
Merged
Conversation
…undles The client SDK statically imports `next/router` for Pages Router navigation spans, and the app/pages decision is only made at runtime. That put Next.js' entire Pages Router client runtime (~80 KB raw) into the client bundle of every App Router app. Move the navigation instrumentation, the only code needing `next/router`, into its own module and call it behind a build-time constant. `withSentryConfig` sets `_sentryHasPagesRouter` to `'false'` when the project has an `app` directory and no page files outside `pages/api`, so the dead branch lets webpack and Turbopack drop the module and the import. Pageload instrumentation stays, since App Router builds still render `404.html` and `500.html` through the Pages Router. Fixes #24032 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
chargome
force-pushed
the
chargome/fix/nextjs-static-pages-router-split
branch
from
September 8, 2026 08:37
bdb77bd to
b52c073
Compare
Contributor
size-limit report 📦
|
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 b52c073. Configure here.
3 tasks
chargome
marked this pull request as ready for review
September 8, 2026 09:31
chargome
requested review from
logaretm,
nicohrubec and
s1gr1d
and removed request for
a team
September 8, 2026 09:31
logaretm
approved these changes
Sep 8, 2026
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.
The client SDK statically imports
next/routerfor Pages Router navigation spans, which pulls Next.js' whole Pages Router client runtime (~80 KB raw) into every App Router client bundle.The navigation instrumentation now lives in its own module and is called behind a build-time constant.
withSentryConfigsets_sentryHasPagesRouterto'false'when the project has anappdirectory and no page files outsidepages/api, so webpack and Turbopack drop the module and itsnext/routerimport. Pageload instrumentation stays, since App Router builds still serve404.html/500.htmlthrough the Pages Router. Mixed app/pages projects are unaffected.Chosen over the dynamic
import()in #24033 to keep the SDK statically analyzable, keep navigation listener registration synchronous, and leave Pages Router apps untouched.Fixes #24032
Refs #24033