Repository navigation
fix(cloudflare): keep default exports intact when auto-instrumenting - #25372
Merged
isaacs merged 2 commits intoOct 15, 2026
Conversation
isaacs
added this pull request to stack #25346
October 14, 2026 17:05
isaacs
requested review from
JPeer264 and
mydea
and removed request for
a team
October 14, 2026 17:05
JPeer264
approved these changes
Oct 14, 2026
isaacs
force-pushed
the
isaacs/fix-default-export-transform
branch
from
October 14, 2026 18:18
34b2d7c to
f61848b
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit f61848b. Configure here.
isaacs
force-pushed
the
isaacs/fix-default-export-transform
branch
3 times, most recently
from
October 14, 2026 23:36
7843742 to
48ede38
Compare
JPeer264
force-pushed
the
isaacs/fix-default-export-transform
branch
from
October 15, 2026 08:45
48ede38 to
17aa842
Compare
isaacs
force-pushed
the
isaacs/fix-default-export-transform
branch
2 times, most recently
from
October 15, 2026 14:27
adc460d to
11dfd25
Compare
The Vite transform rewrote `export default <expr>` to `const __SENTRY_DEFAULT_EXPORT__ = <expr>` and set the wrapped default export at the end of the module. That broke the module in four ways: - A parenthesized default export, such as `export default (handler);`, became a syntax error. The rewrite replaced everything up to the expression, which dropped the `(` and kept the `)`. - An anonymous class, function or arrow took the name `__SENTRY_DEFAULT_EXPORT__` in place of `default`. Libraries can read `.name`, as #24700 found for named classes. - `export default class Handler {}` lost the `Handler` binding, so other code in the module that used `Handler` threw. - A circular import that read the default export after the original `export default` statement, but before the end of the module, threw. The transform now replaces only the `export default` keywords, keeps a named class or function declaration as it is, and gives an anonymous one the name `default` by way of an object property. The default export is set in two steps, as for `export { handler as default }`. Where the original statement set it, it is bound to the value as-is, so a circular import gets the handler. At the end of the module, it is rebound to the wrapper, so methods added to the handler after `export default` are instrumented too. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
isaacs
force-pushed
the
isaacs/fix-default-export-transform
branch
from
October 15, 2026 16:43
11dfd25 to
a37b84a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

The Vite transform rewrote
export default <expr>toconst __SENTRY_DEFAULT_EXPORT__ = <expr>and set the wrapped default export at the end of the module. That broke the module in four ways:export default (handler);, became a syntax error. The rewrite replaced everything up to the expression, which dropped the(and kept the).__SENTRY_DEFAULT_EXPORT__in place ofdefault. Libraries can read.name, as fix(cloudflare): Keep the user's class name when auto-wrapping an export #24700 found for named classes.export default class Handler {}lost theHandlerbinding, so other code in the module that usedHandlerthrew.export defaultstatement, but before the end of the module, threw.The transform now replaces only the
export defaultkeywords, keeps a named class or function declaration as it is, and gives an anonymous one the namedefaultby way of an object property.The default export is set in two steps, as for
export { handler as default }. Where the original statement set it, it is bound to the value as-is, so a circular import gets the handler. At the end of the module, it is rebound to the wrapper, so methods added to the handler afterexport defaultare instrumented too.