Skip to content

perf(vite): add fast component annotation transform#22089

Open
timfish wants to merge 1 commit into
developfrom
timfish/perf/vite-add-fast-component-annotation-transform
Open

perf(vite): add fast component annotation transform#22089
timfish wants to merge 1 commit into
developfrom
timfish/perf/vite-add-fast-component-annotation-transform

Conversation

@timfish

@timfish timfish commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

Credit to @TheAlexLichter who opened this PR against the bundler plugins repo after we moved the functionality to this repo but before we managed to remove the orphaned package!

Resolves getsentry/sentry-javascript-bundler-plugins#943

This PR adds a port of the Babel transform forreactComponentAnnotation.enabled that works with Vite 8 + magic string, dramatically decreasing build time.

I've also added parity tests and consolidated values to avoid drift of both implementations.

Vite 7 and fallback cases will use the existing Babel transform.
Both Babel and the Vite annotation backend are lazy-loaded to avoid unnecessary startup cost.

"data-sentry-source-file": "app.jsx"
}, void 0, false, {
fileName: _jsxFileName,
lineNumber: 4,

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.

The updated line numbers are on purpose and actually "more correct" as they now point to the actual JSX component, not just the span around it.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Noticed this as it was porting over!

@@ -0,0 +1,314 @@
import { transformAsync, traverse, types as t } from '@babel/core';
import { parse } from '@babel/parser';

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.

Yes, this does use babel for testing as it is more convenient API-wise 😄

@timfish timfish requested review from Lms24, isaacs and mydea July 8, 2026 13:14
@timfish timfish marked this pull request as ready for review July 8, 2026 14:17

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit e04ab6a. Configure here.

});

if (!isAstNode(ast)) {
return null;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Invalid AST skips Babel fallback

High Severity

When parseAstAsync resolves to a value that fails isAstNode, the Vite annotation hook returns null. Rollup treats null as a completed fast-path outcome and disables the Babel annotation fallback, so eligible .jsx/.tsx modules can ship without data-sentry-* attributes even though the slower transform would still apply them.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit e04ab6a. Configure here.

@Lms24 Lms24 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.

Thanks for contributing @TheAlexLichter and for porting this over Tim!

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.

Vite 8 /Rolldown: Do not use Babel for annotating react components

3 participants