Repository navigation
fix(nextjs): Apply top-level bundleSizeOptimizations to webpack and Turbopack builds - #24818
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
size-limit report 📦
|
nicohrubec
left a comment
There was a problem hiding this comment.
do I understand correctly that with this PR users would set webpack: { treeshake: { removeTracing: true }}} and this setting would then be applied even if they are on turbopack? feels a bit weird to me, why not either allow to set this in the turbopack options directly or even move it to top level if this is now supported for both bundlers?
|
@nicohrubec yes, good point. I'll move it up. |
bundleSizeOptimizations to webpack and Turbopack builds
I reworked this by moving it up as a toplevel flag and deprecated the old treeshake flag. |
| /** | ||
| * Tree-shaking options to help reduce the size of the Sentry SDK bundle. | ||
| * | ||
| * @deprecated Use the top-level `bundleSizeOptimizations` option instead, which works for both webpack and Turbopack builds. |
There was a problem hiding this comment.
We moved this from top level to webpack specific not too long ago, I would like to avoid deprecating this right away again to not upset users. We can keep both top level and this one in parallel and just document top level for now and ship deprecation closer to v12.
Also I think the deprecation notice needs to be applied to nested options here too afaik so this gets picked up in IDEs.
There was a problem hiding this comment.
Right, makes sense. I removed the deprecation and left a TODO in 64cdaf2
| consoleSandbox(() => { | ||
| // eslint-disable-next-line no-console | ||
| console.warn( | ||
| '[@sentry/nextjs] You have enabled `debug: true`, but Sentry debug logging was removed from your bundle (likely via `webpack.treeshake.removeDebugLogging: true`). Set that option to `false` to see Sentry debug output.', |
There was a problem hiding this comment.
The old option in still usable, right? Maybe we should mention both options in the log? Also with a todo so we don't forget to remove it.
There was a problem hiding this comment.
Yes, it still works. I added both options to the log, with a TODO to remove the old one in v12, in c85dff4
… and Turbopack builds (#25261) Backport of: #24818 ## Differences to the original PR - `packages/nextjs/src/{client,edge,server}/index.ts`: the `debug: true` warning still mentions `withSentryConfig({ disableLogger: true })`. v10 still has the deprecated `disableLogger` option, which develop removed. The message now lists `bundleSizeOptimizations.excludeDebugStatements: true`, `withSentryConfig({ disableLogger: true })`, and `webpack.treeshake.removeDebugLogging: true`. - `packages/nextjs/src/config/types.ts`: left out the TODO comment change on the closing brace of `_experimental.turbopackReactComponentAnnotation`. On v10 that line has no `TODO(v12)` comment to replace. This only affects a comment. - `packages/nextjs/src/config/withSentryConfig/getFinalConfigObjectBundlerUtils.ts`: the `../util` import leaves out `supportsTurbopackRuleCondition`, which v10 doesn't have. The new `getTreeshakeDefines` import is unchanged. - `packages/nextjs/test/config/webpack/constructWebpackConfig.test.ts`: the new test spies on `core.loadModule` instead of `coreServer.loadModule`. On v10 this test file imports `@sentry/core` as `core` and has no `coreServer` import. - `packages/nextjs/test/config/withSentryConfig.test.ts`: the existing v10 test `adds a turbopack note when the deprecated option only applies to webpack` now passes `{ ...exportedNextConfig }` instead of the shared fixture. On v10, `disableLogger` maps to `webpack.treeshake.removeDebugLogging`. With Turbopack enabled, the new `maybeSetTurbopackTreeshakeDefines` writes `compiler.define` onto the passed config. That change leaked into the shared fixture and broke the new Turbopack treeshake tests. This only changes tests. Reviewer note: because `disableLogger` maps to `webpack.treeshake.removeDebugLogging` on v10, `disableLogger: true` now also removes debug logging in Turbopack builds. The existing deprecation warning for `disableLogger` still adds "(Not supported with Turbopack.)". This backport leaves that warning unchanged. <!-- junior-request-attribution:start --> via Junior system actor `junior`. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:agent-dispatch%3Adispatch_cc76606421a00682d726df899f995e6a --> -- [View Junior Session](https://junior-prod.sentry.dev/conversations/agent-dispatch%3Adispatch_cc76606421a00682d726df899f995e6a) [[Sentry]](https://sentry.sentry.io/explore/conversations/agent-dispatch%3Adispatch_cc76606421a00682d726df899f995e6a/?project=4510944073809921) <!-- junior-session-footer:end --> Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
What
The top-level
bundleSizeOptimizationsoption now removes unused SDK code in both webpack and Turbopack builds.webpack.treeshakeis deprecated. It still works, butbundleSizeOptimizationswins when you set both.Why
On Turbopack, the tree-shaking options did nothing and gave no warning. The old option also lived under
webpack, which is wrong for an option that works with both bundlers.Closes: #24795