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

Use optional chaining internally #12115

Closed
VIKTORVAV99 opened this issue May 18, 2024 · 2 comments
Closed

Use optional chaining internally #12115

VIKTORVAV99 opened this issue May 18, 2024 · 2 comments

Comments

@VIKTORVAV99
Copy link

VIKTORVAV99 commented May 18, 2024

Problem Statement

Now that the JS SDK supports ES2018 and forward would it be possible to use optional chaining internally to reduce bundle sizes? It is currently being blocked by Avoid using optional chaining eslint(@sentry-internal/sdk/no-optional-chaining) for non node SDKs.

Node should support it natively and the other targets should already be including the polyfills if I understand things correctly.

I don't expect any large size reductions but I don't really see any drawbacks to using it since it should be supported in all targets.

Solution Brainstorm

There are multiple places where this can be used I the JS SDKs but the biggest benefits would be to reduce statements like this:

  const isInsideChromeExtension =
    windowWithMaybeChrome &&
    windowWithMaybeChrome.chrome &&
    windowWithMaybeChrome.chrome.runtime &&
    windowWithMaybeChrome.chrome.runtime.id;

to just:

  const isInsideChromeExtension =
    windowWithMaybeChrome?.chrome?.runtime?.id;

I would be happy to open some PRs myself if the mentioned ESLint rule is revised.

@AbhiPrasad
Copy link
Member

Hi @VIKTORVAV99, thanks for writing in!

I agree optional chaining would be a big improvement, but unfortunately it is ES2020, and we have a default minimum of ES2018 in our 8.x major version.

In our next major version we will evaluate using ES2020, which means we can adopt optional chaining! Closing this for now though.

@AbhiPrasad AbhiPrasad closed this as not planned Won't fix, can't repro, duplicate, stale May 21, 2024
@VIKTORVAV99
Copy link
Author

Understood 👍🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

No branches or pull requests

2 participants