Skip to content

feat(loader): Detect ES6 support & ship appropriate package #53841

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

Closed
wants to merge 2 commits into from

Conversation

mydea
Copy link
Member

@mydea mydea commented Jul 31, 2023

This adds a check for ES6 support into the loader script, and ensures we load the corresponding bundle based on this.

  • By default we always load the ES6 bundle
  • If no ES6 support is detected, we load the ES5 bundle
  • If replay is enabled and no ES6 support is detected, we disable replay and load the replay-less ES5 bundle instead

I tested this in IE11 via BrowserStack, where it worked as far as I can tell (a bit hard to try with the free version, but I managed to get it running at least).

Closes #53840

@mydea mydea requested review from lforst, Lms24 and AbhiPrasad July 31, 2023 09:37
@mydea mydea self-assigned this Jul 31, 2023
@mydea mydea requested a review from a team as a code owner July 31, 2023 09:37
@github-actions github-actions bot added Scope: Frontend Automatically applied to PRs that change frontend components Scope: Backend Automatically applied to PRs that change backend components labels Jul 31, 2023
@github-actions
Copy link
Contributor

🚨 Warning: This pull request contains Frontend and Backend changes!

It's discouraged to make changes to Sentry's Frontend and Backend in a single pull request. The Frontend and Backend are not atomically deployed. If the changes are interdependent of each other, they must be separated into two pull requests and be made forward or backwards compatible, such that the Backend or Frontend can be safely deployed independently.

Have questions? Please ask in the #discuss-dev-infra channel.

@@ -60,6 +62,22 @@ declare const __LOADER__IS_LAZY__: any;
});
}

// We detect ES6 support by checking if module scripts are supported
let _hasEs6Support: boolean | undefined;
function hasEs6Support(): boolean {
Copy link
Member

@AbhiPrasad AbhiPrasad Jul 31, 2023

Choose a reason for hiding this comment

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

m: could we check if Symbol is defined globally as an es5 check?

also maybe https://gist.github.com/bendc/d7f3dbc83d0f65ca0433caf90378cd95 works better.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, not sure if new Function("(a = 0) => a"); works well with all CSP security settings etc...? isn't this basically eval, which it may complain about?

but I guess we can do 'Symbol' in window check, that should be fine I guess?

FWIW I think module support should be a pretty good proxy. Symbol is a bit "better" supported.

Copy link
Member

Choose a reason for hiding this comment

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

injecting an inline script seems more likely to trigger CSP fwiw

Copy link
Member Author

Choose a reason for hiding this comment

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

good point, we should def. not do that then 😬 so let's go the symbol check route then, wdyt? should this work:

try {
  Symbol("loader");
} catch(error) {
  // this is ES5
}

Copy link
Member

Choose a reason for hiding this comment

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

This might fail with polyfills but maybe that is ok because it represents that someone is already polyfilling the necessary es6 features.

I'm comfortable with shipping this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I think if Symbol is polyfilled we can ~assume that ES6 stuff is polyfilled generally. Overall by now ES6 is so widely supported that I figure only very few will be affected by this overall!

@@ -60,6 +62,22 @@ declare const __LOADER__IS_LAZY__: any;
});
}

// We detect ES6 support by checking if module scripts are supported
let _hasEs6Support: boolean | undefined;
function hasEs6Support(): boolean {
Copy link
Member

Choose a reason for hiding this comment

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

This might fail with polyfills but maybe that is ok because it represents that someone is already polyfilling the necessary es6 features.

I'm comfortable with shipping this.

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.

Looks good from my PoV!

@codecov
Copy link

codecov bot commented Aug 28, 2023

Codecov Report

Merging #53841 (79e4f51) into master (2be150d) will increase coverage by 1.11%.
The diff coverage is 90.90%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #53841      +/-   ##
==========================================
+ Coverage   78.31%   79.42%   +1.11%     
==========================================
  Files        5040     5040              
  Lines      214865   214874       +9     
  Branches    36495    36495              
==========================================
+ Hits       168263   170673    +2410     
+ Misses      41266    38806    -2460     
- Partials     5336     5395      +59     
Files Changed Coverage Δ
src/sentry/web/frontend/js_sdk_loader.py 97.36% <90.90%> (-0.73%) ⬇️

... and 308 files with indirect coverage changes

@getsantry
Copy link
Contributor

getsantry bot commented Oct 19, 2023

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you remove the label Waiting for: Community, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

@getsantry getsantry bot added the Stale label Oct 19, 2023
@mydea mydea removed the Stale label Oct 19, 2023
@getsantry
Copy link
Contributor

getsantry bot commented Nov 9, 2023

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you remove the label Waiting for: Community, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

@getsantry getsantry bot added the Stale label Nov 9, 2023
@mydea mydea removed the Stale label Nov 9, 2023
@getsantry
Copy link
Contributor

getsantry bot commented Dec 1, 2023

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you remove the label Waiting for: Community, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

@getsantry getsantry bot added the Stale label Dec 1, 2023
@getsantry getsantry bot closed this Dec 9, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Dec 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Scope: Backend Automatically applied to PRs that change backend components Scope: Frontend Automatically applied to PRs that change frontend components Stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Detect ES6 support in loader & fetch corresponding CDN bundle
4 participants