Skip to content

perf(bundler-plugins): Use fast component annotation for Webpack and Turbopack - #24448

Merged
timfish merged 1 commit into
developfrom
feat/fast-annotation-webpack-turbopack
Sep 23, 2026
Merged

timfish merged 1 commit into
developfrom
feat/fast-annotation-webpack-turbopack

Conversation

@timfish

@timfish timfish commented Sep 16, 2026

Copy link
Copy Markdown
Collaborator

Stacked on #24440. Webpack and the Next.js Turbopack loader still annotated React components with Babel. This PR moves them to the fast oxc-based path, so every bundler integration now uses it. Babel stays as the fallback when oxc-parser cannot load or cannot parse a file. The next PR in the stack removes that fallback.

createComponentNameAnnotateHooks now tries the fast path first and uses Babel only when the fast path does not handle the file. Webpack, the Rollup and Vite plugins, and the Turbopack loader already call this function, so the Rollup plugin no longer needs its own fast-path setup.

The fast path's source maps listed each annotated file by its base name only, which dropped the directory. That is the bug from #23561, which was fixed for the Babel path, and it would have come back for Webpack. The maps now keep the full path, so Rollup and Vite builds that use the fast path get full paths too.

Ref #24415

@timfish
timfish added this pull request to stack #24441 September 16, 2026 17:07
@timfish
timfish marked this pull request as ready for review September 16, 2026 17:14
@timfish
timfish requested a review from a team as a code owner September 16, 2026 17:14
@timfish
timfish requested review from mydea and s1gr1d and removed request for a team September 16, 2026 17:14
@github-actions

github-actions Bot commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

⚠️ Warning: Base artifact is not the latest one, because the latest workflow run is not done yet. This may lead to incorrect results. Try to re-run all tests to get up to date results.

Path Size % Change Change
@sentry/browser 29.23 kB - -
@sentry/browser - with treeshaking flags 27.5 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 27.4 kB - -
@sentry/browser (incl. Tracing) 51.16 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 51.17 kB - -
@sentry/browser (incl. Tracing, Profiling) 54.16 kB - -
@sentry/browser (incl. Tracing, Replay) 90.75 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 79.85 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 95.45 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 108.42 kB - -
@sentry/browser (incl. Feedback) 46.76 kB - -
@sentry/browser (incl. sendFeedback) 34.29 kB - -
@sentry/browser (incl. FeedbackAsync) 39.39 kB - -
@sentry/browser (incl. Metrics) 30.25 kB - -
@sentry/browser (incl. Logs) 30.5 kB - -
@sentry/browser (incl. Metrics & Logs) 31.17 kB - -
@sentry/react 30.98 kB - -
@sentry/react (incl. Tracing) 53.44 kB - -
@sentry/vue 36.72 kB - -
@sentry/vue (incl. Tracing) 53.69 kB - -
@sentry/svelte 29.25 kB - -
CDN Bundle 30.93 kB - -
CDN Bundle (incl. Tracing) 51.69 kB - -
CDN Bundle (incl. Logs, Metrics) 33.19 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 53.66 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 73.92 kB - -
CDN Bundle (incl. Tracing, Replay) 89.27 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 91.23 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 95.43 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 97.4 kB - -
CDN Bundle - uncompressed 91.4 kB - -
CDN Bundle (incl. Tracing) - uncompressed 153.76 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 97.97 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 159.72 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 227.54 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 273.5 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 279.43 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 287.2 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 293.13 kB - -
@sentry/nextjs (client) 55.78 kB - -
@sentry/sveltekit (client) 51.59 kB - -
@sentry/core/server 39.92 kB - -
@sentry/core/browser 13.63 kB - -
@sentry/node 133.88 kB +0.02% +17 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 82.4 kB - -
@sentry/node - without tracing 90.39 kB +0.01% +7 B 🔺
@sentry/node - without channel injection 112.42 kB +0.02% +21 B 🔺
@sentry/aws-serverless 98.71 kB +0.03% +22 B 🔺
@sentry/cloudflare (withSentry) - minified 206.38 kB - -
@sentry/cloudflare (withSentry) 513.49 kB - -

View base workflow run

Comment thread packages/nextjs/src/config/loaders/componentAnnotationLoader.ts
@timfish
timfish force-pushed the feat/fast-annotation-webpack-turbopack branch from 1e153da to 56fb5d9 Compare September 17, 2026 09:26
@timfish
timfish requested a review from chargome September 17, 2026 11:38
@timfish
timfish force-pushed the feat/fast-annotation-webpack-turbopack branch from 56fb5d9 to 053b721 Compare September 20, 2026 12:51
@github-actions

Copy link
Copy Markdown
Contributor

👋 @mydea, @s1gr1d — Please review this PR when you get a chance!

@timfish
timfish force-pushed the feat/fast-annotation-webpack-turbopack branch from 053b721 to d9ab8d6 Compare September 21, 2026 22:02
@github-actions

Copy link
Copy Markdown
Contributor

👋 @chargome — Please review this PR when you get a chance!

@timfish
timfish force-pushed the feat/fast-annotation-webpack-turbopack branch from d9ab8d6 to c7d168f Compare September 22, 2026 10:50
@timfish
timfish requested a review from logaretm September 22, 2026 12:33
Base automatically changed from feat/fast-annotation-html-injection to develop September 23, 2026 10:23
@timfish
timfish force-pushed the feat/fast-annotation-webpack-turbopack branch from c7d168f to 072d7c6 Compare September 23, 2026 10:23
export function createComponentNameAnnotateHooks(
ignoredComponents: string[],
injectIntoHtml: boolean,
getParseAstAsync?: () => Promise<ParseAstAsync | null>,

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.

Bug: The Rollup and Vite plugins lack error handling for the dynamic import('./component-annotation-oxc'). An import failure will cause an unhandled rejection, bypassing the intended Babel fallback.
Severity: MEDIUM

Suggested Fix

Wrap the await (await fastHooksPromise).transform(...) call within a try/catch block. In the catch block, implement the fallback to the Babel transformation. Alternatively, add a .catch() handler to the fastHooksPromise promise chain to gracefully handle potential import failures, similar to the existing implementation in the Turbopack loader.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: packages/bundler-plugins/src/core/index.ts#L90

Potential issue: In the Rollup and Vite plugins, the `transform` function awaits
`fastHooksPromise`, which is derived from a dynamic
`import('./component-annotation-oxc')`. If this import fails due to build-time issues
like file corruption or resolution problems, the promise will reject. This rejection is
not handled by a `try/catch` block or a `.catch()` handler. As a result, the unhandled
rejection will propagate up, crashing the bundler's transform hook and bypassing the
intended fallback mechanism that uses Babel for transformation.

@timfish
timfish merged commit 21086bb into develop Sep 23, 2026
228 of 230 checks passed
@timfish
timfish deleted the feat/fast-annotation-webpack-turbopack branch September 23, 2026 11:02
timfish added a commit that referenced this pull request Sep 23, 2026
…#24449)

Stacked on #24448. Every bundler integration now annotates React
components with the fast oxc-based path. This PR removes the Babel
fallback from that path, so `@babel/core` is no longer a runtime
dependency of `@sentry/bundler-plugins`.

The `@sentry/bundler-plugins/babel-plugin` export stays, because the
React Native SDK uses it with Metro. The plugin only imports Babel types
and runs inside the user's own Babel. So `@babel/core` moves to
`devDependencies` and becomes an optional peer dependency, and the
export keeps working.

Without the fallback, `oxc-parser` leaves a file it cannot parse
unchanged, and the bundler reports the syntax error. If no parser can
load, for example on a platform without an `oxc-parser` native binary,
the plugin logs one warning and skips annotations.

Fixes #24415
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.

2 participants