-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ref: Avoid optional chaining & add eslint rule #6777
Conversation
size-limit report 📦
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM and nice bundle size improvement!
@@ -89,3 +87,11 @@ function addInternalBreadcrumb(arg: Parameters<typeof addBreadcrumb>[0]): void { | |||
...rest, | |||
}); | |||
} | |||
|
|||
function getEventExceptionValues(event: Event): { type: string; value: string } { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice refactor!
Just gonna link to #6459 as we're kinda tracking bundle size improvements there |
ref #6778 as that touches similar files (note for myself) |
7783de0
to
f11d97b
Compare
As this is transpiled to a rather verbose form.
@@ -90,7 +90,7 @@ export interface BrowserTracingOptions extends RequestInstrumentationOptions { | |||
* | |||
* Default: undefined | |||
*/ | |||
_experiments?: Partial<{ enableLongTask: boolean; enableInteractions: boolean }>; | |||
_experiments: Partial<{ enableLongTask: boolean; enableInteractions: boolean }>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to double check here, is this change OK? It is actually always set right now because it is (as {}
) part of the DEFAULT_BROWSER_TRACING_OPTIONS
. By actually marking this non-optional we can save on checks throughout tracing a bit. cc @AbhiPrasad @Lms24
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is fine because it's still optional in the integration constructor, and that is all that matters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Jup, this was my thought as well 👍
packages/vue/src/tracing.ts
Outdated
@@ -40,7 +41,7 @@ function finishRootSpan(vm: VueSentry, timestamp: number, timeout: number): void | |||
} | |||
|
|||
vm.$_sentryRootSpanTimer = setTimeout(() => { | |||
if (vm.$root?.$_sentryRootSpan) { | |||
if (vm.$root.$_sentryRootSpan) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also here just to double check cc @Lms24 , type-wise $root
cannot be undefined, not sure if the optional chaining guard was there for a different reason?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm not sure to be honest. With the type, you mean this here, correct?
sentry-javascript/packages/vue/src/types.ts
Lines 14 to 27 in 2aa4e94
export type ViewModel = { | |
_isVue?: boolean; | |
__isVue?: boolean; | |
$root: ViewModel; | |
$parent?: ViewModel; | |
$props: { [key: string]: any }; | |
$options?: { | |
name?: string; | |
propsData?: { [key: string]: any }; | |
_componentTag?: string; | |
__file?: string; | |
}; | |
}; | |
Since it seems like we vendored this type from Vue, I wouldn't be too sure that $root
always existed (older Vue versions...). According to this PR, we introduced it with Vue 3 support: #3804. I'd just check for vm.$root
here anyway to make sure. Shouldn't hurt us too much in terms of bundle size. WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jup, I will revert this then, to be safe!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked, and as far as I can tell $root should be available in both vue2 and vue3. But, hard to be sure... so I reverted the check, to be on the safe side.
f11d97b
to
0fb8ab6
Compare
packages/vue/src/tracing.ts
Outdated
@@ -40,7 +41,7 @@ function finishRootSpan(vm: VueSentry, timestamp: number, timeout: number): void | |||
} | |||
|
|||
vm.$_sentryRootSpanTimer = setTimeout(() => { | |||
if (vm.$root?.$_sentryRootSpan) { | |||
if (vm.$root.$_sentryRootSpan) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm not sure to be honest. With the type, you mean this here, correct?
sentry-javascript/packages/vue/src/types.ts
Lines 14 to 27 in 2aa4e94
export type ViewModel = { | |
_isVue?: boolean; | |
__isVue?: boolean; | |
$root: ViewModel; | |
$parent?: ViewModel; | |
$props: { [key: string]: any }; | |
$options?: { | |
name?: string; | |
propsData?: { [key: string]: any }; | |
_componentTag?: string; | |
__file?: string; | |
}; | |
}; | |
Since it seems like we vendored this type from Vue, I wouldn't be too sure that $root
always existed (older Vue versions...). According to this PR, we introduced it with Vue 3 support: #3804. I'd just check for vm.$root
here anyway to make sure. Shouldn't hurt us too much in terms of bundle size. WDYT?
packages/vue/src/tracing.ts
Outdated
@@ -96,7 +97,7 @@ export const createTracingMixins = (options: TracingOptions): Mixins => { | |||
// Start a new span if current hook is a 'before' hook. | |||
// Otherwise, retrieve the current span and finish it. | |||
if (internalHook == internalHooks[0]) { | |||
const activeTransaction = this.$root?.$_sentryRootSpan || getActiveTransaction(); | |||
const activeTransaction = this.$root.$_sentryRootSpan || getActiveTransaction(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Likewise here, I guess
Co-authored-by: Lukas Stracke <lukas.stracke@sentry.io>
As this is transpiled to a rather verbose form.
This PR now also adds an eslint rule based on facebook/lexical#3233 to enforce avoiding optional chaining. I left it for all node-based stuff, because there we don't care, I guess.