Skip to content

Conversation

@logaretm
Copy link
Collaborator

@logaretm logaretm commented Dec 1, 2025

This PR updates the Sentry Next.js integration to improve tree-shaking configuration and add new options for finer control over what SDK code is included in the final bundle.

The most significant changes are:

  • Added several new tree-shaking flags for better user DX.

Closes #18417

@linear
Copy link

linear bot commented Dec 1, 2025

@logaretm logaretm requested a review from chargome December 1, 2025 16:01
@github-actions
Copy link
Contributor

github-actions bot commented Dec 1, 2025

size-limit report 📦

Path Size % Change Change
@sentry/browser 24.81 kB - -
@sentry/browser - with treeshaking flags 23.3 kB - -
@sentry/browser (incl. Tracing) 41.55 kB - -
@sentry/browser (incl. Tracing, Profiling) 46.16 kB - -
@sentry/browser (incl. Tracing, Replay) 79.97 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 69.7 kB +0.01% +1 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas) 84.65 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 96.89 kB - -
@sentry/browser (incl. Feedback) 41.52 kB - -
@sentry/browser (incl. sendFeedback) 29.49 kB +0.01% +1 B 🔺
@sentry/browser (incl. FeedbackAsync) 34.48 kB +0.01% +1 B 🔺
@sentry/react 26.52 kB - -
@sentry/react (incl. Tracing) 43.76 kB - -
@sentry/vue 29.27 kB - -
@sentry/vue (incl. Tracing) 43.36 kB - -
@sentry/svelte 24.82 kB - -
CDN Bundle 27.23 kB - -
CDN Bundle (incl. Tracing) 42.22 kB - -
CDN Bundle (incl. Tracing, Replay) 78.75 kB +0.01% +1 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 84.2 kB - -
CDN Bundle - uncompressed 80.02 kB - -
CDN Bundle (incl. Tracing) - uncompressed 125.37 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 241.41 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 254.17 kB - -
@sentry/nextjs (client) 45.98 kB - -
@sentry/sveltekit (client) 41.93 kB - -
@sentry/node-core 51.6 kB - -
@sentry/node 161.48 kB +0.01% +1 B 🔺
@sentry/node - without tracing 93.03 kB - -
@sentry/aws-serverless 108.54 kB -0.01% -1 B 🔽

View base workflow run

@logaretm logaretm force-pushed the awad/js-1222-add-treeshaking-options-for-webpack branch 2 times, most recently from bf5a673 to 66aa19c Compare December 4, 2025 14:44
Copilot AI review requested due to automatic review settings December 4, 2025 14:44
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR enhances the Sentry Next.js SDK's tree-shaking capabilities by renaming debugLogs to debugLogging and introducing four new configuration options for fine-grained control over SDK bundle inclusion.

Key Changes:

  • Renamed configuration option from debugLogs to debugLogging for consistency
  • Added tracing, excludeReplayIframe, excludeReplayShadowDOM, and excludeReplayCompressionWorker tree-shaking options
  • Refactored webpack configuration to use a dedicated setupTreeshakingFromConfig function for improved maintainability

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 9 comments.

File Description
packages/nextjs/src/config/types.ts Added type definitions and JSDoc documentation for four new tree-shaking options
packages/nextjs/src/config/webpack.ts Extracted tree-shaking setup into a dedicated function that handles all five tree-shaking flags via webpack DefinePlugin
packages/nextjs/test/config/fixtures.ts Updated DefinePlugin mock to accept and store definitions for test verification
packages/nextjs/test/config/webpack/constructWebpackConfig.test.ts Added comprehensive test suite covering all tree-shaking options across different build contexts (server, client, edge)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@logaretm logaretm force-pushed the awad/js-1222-add-treeshaking-options-for-webpack branch from 03e070a to e66a724 Compare December 5, 2025 09:56
Base automatically changed from awad/js-1111-deprecate-top-level-webpack-options to develop December 5, 2025 15:21
@logaretm logaretm force-pushed the awad/js-1222-add-treeshaking-options-for-webpack branch from e66a724 to c8832af Compare December 5, 2025 15:23
@logaretm logaretm linked an issue Dec 5, 2025 that may be closed by this pull request
@logaretm logaretm force-pushed the awad/js-1222-add-treeshaking-options-for-webpack branch from de51fb2 to daa72ef Compare December 11, 2025 16:48
@logaretm logaretm force-pushed the awad/js-1222-add-treeshaking-options-for-webpack branch from daa72ef to 261ad56 Compare December 15, 2025 14:42
Copy link
Member

@chargome chargome left a comment

Choose a reason for hiding this comment

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

LGTM! Nice DX improvement

@chargome
Copy link
Member

@logaretm make sure to add a section in the changelog for this 🙏

@logaretm logaretm force-pushed the awad/js-1222-add-treeshaking-options-for-webpack branch from 261ad56 to 825cf35 Compare December 16, 2025 19:27
expect(treeshakePlugin.definitions).not.toHaveProperty('__SENTRY_TRACING__');
expect(treeshakePlugin.definitions).not.toHaveProperty('__RRWEB_EXCLUDE_SHADOW_DOM__');
});
});
Copy link

Choose a reason for hiding this comment

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

Bug: Missing integration or E2E tests for feature (Bugbot Rules)

Per the review rules specified in this repository, feat PRs should include at least one integration or E2E test. This PR adds new webpack treeshaking configuration flags but only includes unit tests. Since these flags affect the actual webpack build behavior and bundle output, an integration or E2E test verifying that the treeshaking actually works as expected in a real Next.js build would provide stronger confidence in the feature. Flagged because review rules file requests this check.

Fix in Cursor Fix in Web

@logaretm logaretm merged commit 99183a7 into develop Dec 16, 2025
68 checks passed
@logaretm logaretm deleted the awad/js-1222-add-treeshaking-options-for-webpack branch December 16, 2025 19:55
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.

feat(nextjs): added webpack treeshaking flags as config Add treeshaking option for webpack

3 participants