Skip to content
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

Merged
merged 7 commits into from
Jan 16, 2023

Conversation

mydea
Copy link
Member

@mydea mydea commented Jan 16, 2023

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.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 16, 2023

size-limit report 📦

Path Size
@sentry/browser - ES5 CDN Bundle (gzipped + minified) 19.82 KB (-0.11% 🔽)
@sentry/browser - ES5 CDN Bundle (minified) 61.44 KB (-0.04% 🔽)
@sentry/browser - ES6 CDN Bundle (gzipped + minified) 18.49 KB (-0.62% 🔽)
@sentry/browser - ES6 CDN Bundle (minified) 54.74 KB (-0.48% 🔽)
@sentry/browser - Webpack (gzipped + minified) 20.22 KB (-0.75% 🔽)
@sentry/browser - Webpack (minified) 66.17 KB (-0.57% 🔽)
@sentry/react - Webpack (gzipped + minified) 20.24 KB (-0.78% 🔽)
@sentry/nextjs Client - Webpack (gzipped + minified) 47.57 KB (-0.21% 🔽)
@sentry/browser + @sentry/tracing - ES5 CDN Bundle (gzipped + minified) 26.78 KB (-0.18% 🔽)
@sentry/browser + @sentry/tracing - ES6 CDN Bundle (gzipped + minified) 25.11 KB (-0.69% 🔽)
@sentry/replay ES6 CDN Bundle (gzipped + minified) 43.11 KB (-1.55% 🔽)
@sentry/replay - Webpack (gzipped + minified) 38.45 KB (-1.47% 🔽)

Copy link
Member

@Lms24 Lms24 left a 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 } {
Copy link
Member

Choose a reason for hiding this comment

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

Nice refactor!

@Lms24
Copy link
Member

Lms24 commented Jan 16, 2023

Just gonna link to #6459 as we're kinda tracking bundle size improvements there

@mydea mydea changed the title ref(replay): Avoid optional chaining ref: Avoid optional chaining & add eslint rule Jan 16, 2023
@mydea
Copy link
Member Author

mydea commented Jan 16, 2023

ref #6778 as that touches similar files (note for myself)

@mydea mydea force-pushed the fn/replay-avoid-optional-chaining branch from 7783de0 to f11d97b Compare January 16, 2023 10:16
@@ -90,7 +90,7 @@ export interface BrowserTracingOptions extends RequestInstrumentationOptions {
*
* Default: undefined
*/
_experiments?: Partial<{ enableLongTask: boolean; enableInteractions: boolean }>;
_experiments: Partial<{ enableLongTask: boolean; enableInteractions: boolean }>;
Copy link
Member Author

@mydea mydea Jan 16, 2023

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

Copy link
Member

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.

Copy link
Member Author

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 👍

@@ -40,7 +41,7 @@ function finishRootSpan(vm: VueSentry, timestamp: number, timeout: number): void
}

vm.$_sentryRootSpanTimer = setTimeout(() => {
if (vm.$root?.$_sentryRootSpan) {
if (vm.$root.$_sentryRootSpan) {
Copy link
Member Author

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?

Copy link
Member

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?

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?

Copy link
Member Author

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!

Copy link
Member Author

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.

packages/utils/src/requestdata.ts Outdated Show resolved Hide resolved
@@ -40,7 +41,7 @@ function finishRootSpan(vm: VueSentry, timestamp: number, timeout: number): void
}

vm.$_sentryRootSpanTimer = setTimeout(() => {
if (vm.$root?.$_sentryRootSpan) {
if (vm.$root.$_sentryRootSpan) {
Copy link
Member

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?

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?

@@ -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();
Copy link
Member

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>
@mydea mydea merged commit 36492ce into master Jan 16, 2023
@mydea mydea deleted the fn/replay-avoid-optional-chaining branch January 16, 2023 16:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants