Skip to content

feat(nextjs): added webpack treeshaking flags as config - #18359

Merged
logaretm merged 8 commits into
developfrom
awad/js-1222-add-treeshaking-options-for-webpack
Dec 16, 2025
Merged

feat(nextjs): added webpack treeshaking flags as config#18359
logaretm merged 8 commits into
developfrom
awad/js-1222-add-treeshaking-options-for-webpack

Conversation

@logaretm

@logaretmlogaretm commented Dec 1, 2025

Copy link
Copy Markdown
Member

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

linearBot commented Dec 1, 2025

Copy link
Copy Markdown

@github-actions

github-actionsBot commented Dec 1, 2025

Copy link
Copy Markdown
Contributor

size-limit report 📦

PathSize% ChangeChange
@sentry/browser24.81 kB--
@sentry/browser - with treeshaking flags23.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 flags69.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/react26.52 kB--
@sentry/react (incl. Tracing)43.76 kB--
@sentry/vue29.27 kB--
@sentry/vue (incl. Tracing)43.36 kB--
@sentry/svelte24.82 kB--
CDN Bundle27.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 - uncompressed80.02 kB--
CDN Bundle (incl. Tracing) - uncompressed125.37 kB--
CDN Bundle (incl. Tracing, Replay) - uncompressed241.41 kB--
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed254.17 kB--
@sentry/nextjs (client)45.98 kB--
@sentry/sveltekit (client)41.93 kB--
@sentry/node-core51.6 kB--
@sentry/node161.48 kB+0.01%+1 B 🔺
@sentry/node - without tracing93.03 kB--
@sentry/aws-serverless108.54 kB-0.01%-1 B 🔽

View base workflow run

Comment threadpackages/nextjs/src/config/webpack.ts Outdated
Comment threadpackages/nextjs/src/config/withSentryConfig.ts Outdated
@logaretm
logaretmforce-pushed the awad/js-1222-add-treeshaking-options-for-webpack branch 2 times, most recently from bf5a673 to 66aa19cCompareDecember 4, 2025 14:44
CopilotAI review requested due to automatic review settings December 4, 2025 14:44

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

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.

FileDescription
packages/nextjs/src/config/types.tsAdded type definitions and JSDoc documentation for four new tree-shaking options
packages/nextjs/src/config/webpack.tsExtracted tree-shaking setup into a dedicated function that handles all five tree-shaking flags via webpack DefinePlugin
packages/nextjs/test/config/fixtures.tsUpdated DefinePlugin mock to accept and store definitions for test verification
packages/nextjs/test/config/webpack/constructWebpackConfig.test.tsAdded 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.

Comment threadpackages/nextjs/src/config/types.ts Outdated
Comment threadpackages/nextjs/src/config/types.ts Outdated
Comment threadpackages/nextjs/src/config/types.ts Outdated
Comment threadpackages/nextjs/src/config/types.ts Outdated
Comment threadpackages/nextjs/src/config/types.ts Outdated
Comment threadpackages/nextjs/src/config/types.ts Outdated
Comment threadpackages/nextjs/src/config/types.ts Outdated
Comment threadpackages/nextjs/src/config/types.ts Outdated
Comment threadpackages/nextjs/src/config/types.ts
@logaretm
logaretmforce-pushed the awad/js-1222-add-treeshaking-options-for-webpack branch from 03e070a to e66a724CompareDecember 5, 2025 09:56
Comment threadpackages/nextjs/test/config/webpack/constructWebpackConfig.test.ts Outdated
Comment threadpackages/nextjs/test/config/webpack/constructWebpackConfig.test.ts Outdated
Base automatically changed from awad/js-1111-deprecate-top-level-webpack-options to developDecember 5, 2025 15:21
@logaretm
logaretmforce-pushed the awad/js-1222-add-treeshaking-options-for-webpack branch from e66a724 to c8832afCompareDecember 5, 2025 15:23
@logaretmlogaretm linked an issue Dec 5, 2025 that may be closed by this pull request
Comment threadpackages/nextjs/test/config/webpack/constructWebpackConfig.test.ts Outdated
@logaretm
logaretmforce-pushed the awad/js-1222-add-treeshaking-options-for-webpack branch from de51fb2 to daa72efCompareDecember 11, 2025 16:48
@logaretm
logaretmforce-pushed the awad/js-1222-add-treeshaking-options-for-webpack branch from daa72ef to 261ad56CompareDecember 15, 2025 14:42
Comment threadpackages/nextjs/src/config/webpack.ts

@chargomechargome left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
Member

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

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

Copy link
Copy Markdown

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 CursorFix in Web

@logaretm
logaretm merged commit 99183a7 into developDec 16, 2025
68 checks passed
@logaretm
logaretm deleted the awad/js-1222-add-treeshaking-options-for-webpack branch December 16, 2025 19:55
logaretm added a commit to getsentry/sentry-docs that referenced this pull request Dec 18, 2025
# What
A PR to go in tandem with
getsentry/sentry-javascript#18359 once it gets
merged and released.
It documents the new tree-shaking options now abstracted away into
`webpack.treeshake` namespace. It has a few differences to the existing
tree-shaking flags under the hood:
- All options are optimized to be set to `true` to take effect, unlike
the flags where some had to be set to `true` and some had to be set to
`false`.
- Now exposed as an SDK `webpack.treeshake` build options rather than
needing the user to be aware of the webpack define plugin API.
Marking it as a draft to avoid merging it before the PR goes live.
---------
Co-authored-by: Charly Gomez <charly.gomez@sentry.io>
Co-authored-by: Sarah Mischinger <sarah@codingwriter.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for freeto 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

@logaretm@chargome