perf(bundler-plugins): Use fast component annotation for Webpack and Turbopack - #24448
Conversation
size-limit report 📦
|
1e153da to
56fb5d9
Compare
56fb5d9 to
053b721
Compare
053b721 to
d9ab8d6
Compare
|
👋 @chargome — Please review this PR when you get a chance! |
d9ab8d6 to
c7d168f
Compare
c7d168f to
072d7c6
Compare
| export function createComponentNameAnnotateHooks( | ||
| ignoredComponents: string[], | ||
| injectIntoHtml: boolean, | ||
| getParseAstAsync?: () => Promise<ParseAstAsync | null>, |
There was a problem hiding this comment.
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.
…#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
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-parsercannot load or cannot parse a file. The next PR in the stack removes that fallback.createComponentNameAnnotateHooksnow 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