Skip to content

ref(integrations): Make ReportTypes a const enum - #4209

Merged
AbhiPrasad merged 4 commits into
masterfrom
abhi-const-enum-reporttypes
Dec 2, 2021
Merged

ref(integrations): Make ReportTypes a const enum#4209
AbhiPrasad merged 4 commits into
masterfrom
abhi-const-enum-reporttypes

Conversation

@AbhiPrasad

@AbhiPrasadAbhiPrasad commented Dec 1, 2021

Copy link
Copy Markdown
Contributor

ReportTypes is an interally used enum, so we do not need the runtime support. The ReportTypes enum lives in packages/integrations/src/reportingobserver.ts and is used by the ReportingObserver integration to manage report types.

According to the TS docs: https://www.typescriptlang.org/docs/handbook/enums.html

Const enums can only use constant enum expressions and unlike regular enums they are completely removed during compilation. Const enum members are inlined at use sites. This is possible since const enums cannot have computed members.

This helps save on bundle size.

`ReportTypes` is an interally used enum, so we do not need the runtime
support. This helps save on bundle size.
@github-actions

github-actionsBot commented Dec 1, 2021

Copy link
Copy Markdown
Contributor

size-limit report

PathBase Size (846e732)Current SizeChange
@sentry/browser - CDN Bundle (gzipped)22.48 KB22.49 KB+0.01% 🔺
@sentry/browser - Webpack23.37 KB23.37 KB0%
@sentry/react - Webpack23.4 KB23.4 KB0%
@sentry/nextjs Client - Webpack49.73 KB49.73 KB0%
@sentry/browser + @sentry/tracing - CDN Bundle (gzipped)29.93 KB29.93 KB+0.01% 🔺

@lobsterkatie

lobsterkatie commented Dec 2, 2021

Copy link
Copy Markdown
Member

Same suggestion here as on #4210:

...so we do not need the runtime support. This helps save on bundle size.

Suggestion: ...so we don't need its underlying values to be meaningful at runtime. Making it a const enum allows TS to convert those values to inlined integers, thereby decreasing bundle size.

You also might consider mentioning, in the title and/or the description, that ReportTypes is part of ReportingObserver, just so people don't have to click through to the Files tab to figure that out.

@AbhiPrasad

Copy link
Copy Markdown
ContributorAuthor

Updated description

@AbhiPrasad
AbhiPrasad merged commit 7ec20cb into masterDec 2, 2021
@AbhiPrasad
AbhiPrasad deleted the abhi-const-enum-reporttypes branch December 2, 2021 16:51
AbhiPrasad added a commit that referenced this pull request Dec 2, 2021
`ReportTypes` is an interally used enum, so we do not need the runtime support. The `ReportTypes` enum lives in `packages/integrations/src/reportingobserver.ts` and is used by the `ReportingObserver` integration to manage report types.
According to the TS docs: https://www.typescriptlang.org/docs/handbook/enums.html > Const enums can only use constant enum expressions and unlike regular enums they are completely removed during compilation. Const enum members are inlined at use sites. This is possible since const enums cannot have computed members. This helps save on bundle size.
onurtemizkan pushed a commit that referenced this pull request Dec 19, 2021
`ReportTypes` is an interally used enum, so we do not need the runtime support. The `ReportTypes` enum lives in `packages/integrations/src/reportingobserver.ts` and is used by the `ReportingObserver` integration to manage report types.
According to the TS docs: https://www.typescriptlang.org/docs/handbook/enums.html > Const enums can only use constant enum expressions and unlike regular enums they are completely removed during compilation. Const enum members are inlined at use sites. This is possible since const enums cannot have computed members. This helps save on bundle size.
Sign up for freeto 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.

3 participants

@AbhiPrasad@lobsterkatie@sl0thentr0py