frontend icon indicating copy to clipboard operation
frontend copied to clipboard

Redefine browser requirements for modern (latest) builds

Open steverep opened this issue 2 years ago • 21 comments

Breaking change

Browser requirements for serving modern (latest) builds of the frontend have been updated to include only those released in the last year or those still having high global utilization above 0.5%. As before, legacy builds will be served whenever modern requirements are not met.

Proposed change

This change implements a new and more practical way to decipher between "modern" and "legacy" browsers by:

  1. Redefining the browserslist query to be more practical and evolve to always grab the most recent/utilized browser versions. This does for the modern builds what #16384 did for legacy.
  2. Generates a regex to match those browsers and uses it to decide which build to serve. The import() syntax test is kept for simplicity of these changes and as a backup for now, but I think it can be safely eliminated in order to consolidate and simplify the loading code in a future PR.

This does turn off most of Babel's transforms, but only reduces the bundle by about 1%. Of course that doesn't account for the fact that the current dynamic import test technically includes some pretty old browsers that should have a bunch of polyfills, so not really a fair comparison. Also, a not-so-modest reduction might be obtained by not having to transpile class fields, but Lit's decorators are still on the stage 2 spec.

Lastly, I did try to consolidate more code in the templates. The exception was the app index because of its special treatment, but I can fix that in a follow up.

New requirements as of today would be at least (updated to reflect changes from discussion below):

Browser Legacy Current Modern New Modern
Android 60 63 115
Chrome 60 63 109
Edge 16 79 115
Firefox 52 67 115
iOS 10.3 13 15.6
Safari 11 13 16.6
Opera 47 50 101
Opera Mobile* - 80 80
Samsung 4 8.2 22

* = only latest version due to limitations of CanIUse database

Modern Build Babel Plugins

@babel/preset-env: DEBUG option

Using targets: { "android": "115", "chrome": "109", "edge": "115", "firefox": "115", "ios": "15.6", "opera": "101", "opera_mobile": "80", "safari": "16.6", "samsung": "22" }

Using modules transform: auto

Using plugins: transform-unicode-sets-regex { chrome < 112, firefox < 116, ios < 17, safari < 17, samsung } bugfix/transform-firefox-class-in-computed-class-key { firefox } proposal-class-static-block { ios < 16.4 } syntax-private-property-in-object syntax-class-properties syntax-numeric-separator syntax-nullish-coalescing-operator syntax-optional-chaining syntax-json-strings syntax-optional-catch-binding syntax-async-generators syntax-object-rest-spread syntax-export-namespace-from bugfix/transform-safari-id-destructuring-collision-in-function-expression { ios < 16.3 } syntax-dynamic-import syntax-top-level-await syntax-import-meta syntax-import-attributes

Modern Build Core-JS Polyfills

The following 56 polyfills may be injected by Babel:

es.array.push { android < 122, chrome < 122, edge < 122, ios < 16.0, opera < 108, opera_mobile < 81, samsung < 26.0 } es.array.to-reversed { chrome < 110, ios < 16.0 } es.array.to-sorted { chrome < 110, ios < 16.0 } es.array.to-spliced { chrome < 110, ios < 16.0 } es.array.unshift { ios < 16.0 } es.array.with { chrome < 110, ios < 16.0 } es.array-buffer.detached { chrome < 114, firefox < 122, ios < 17.4, safari < 17.4, samsung < 23.0 } es.array-buffer.transfer { chrome < 114, firefox < 122, ios < 17.4, safari < 17.4, samsung < 23.0 } es.array-buffer.transfer-to-fixed-length { chrome < 114, firefox < 122, ios < 17.4, safari < 17.4, samsung < 23.0 } es.map.group-by { android < 117, chrome < 117, edge < 117, firefox < 119, ios, opera < 103, safari, samsung < 24.0 } es.object.group-by { android < 117, chrome < 117, edge < 117, firefox < 119, ios, opera < 103, safari, samsung < 24.0 } es.promise.with-resolvers { android < 119, chrome < 119, edge < 119, firefox < 121, ios < 17.4, opera < 105, safari < 17.4, samsung < 25.0 } es.regexp.flags { chrome < 111 } es.set.difference.v2 { android < 123, chrome < 123, edge < 123, firefox < 127, ios, opera < 109, opera_mobile < 82, safari, samsung } es.set.intersection.v2 { android < 123, chrome < 123, edge < 123, firefox < 127, ios, opera < 109, opera_mobile < 82, safari, samsung } es.set.is-disjoint-from.v2 { android < 123, chrome < 123, edge < 123, firefox < 127, ios, opera < 109, opera_mobile < 82, safari, samsung } es.set.is-subset-of.v2 { android < 123, chrome < 123, edge < 123, firefox < 127, ios, opera < 109, opera_mobile < 82, safari, samsung } es.set.is-superset-of.v2 { android < 123, chrome < 123, edge < 123, firefox < 127, ios, opera < 109, opera_mobile < 82, safari, samsung } es.set.symmetric-difference.v2 { android < 123, chrome < 123, edge < 123, firefox < 127, ios, opera < 109, opera_mobile < 82, safari, samsung } es.set.union.v2 { android < 123, chrome < 123, edge < 123, firefox < 127, ios, opera < 109, opera_mobile < 82, safari, samsung } es.string.is-well-formed { chrome < 111, firefox < 119, ios < 16.4 } es.string.to-well-formed { chrome < 111, firefox < 119, ios < 16.4 } es.typed-array.to-reversed { chrome < 110, ios < 16.0 } es.typed-array.to-sorted { chrome < 110, ios < 16.0 } es.typed-array.with { chrome < 110, ios < 16.4 } esnext.suppressed-error.constructor { android, chrome, edge, firefox, ios, opera, opera_mobile, safari, samsung } esnext.array.from-async { android < 121, chrome < 121, edge < 121, ios, opera < 107, opera_mobile < 81, safari, samsung < 25.0 } esnext.array.group { android, chrome, edge, firefox, ios, opera, opera_mobile, safari, samsung } esnext.array.group-to-map { android, chrome, edge, firefox, ios, opera, opera_mobile, safari, samsung } esnext.iterator.constructor { android < 122, chrome < 122, edge < 122, firefox, ios, opera < 108, opera_mobile < 81, safari, samsung < 26.0 } esnext.iterator.drop { android < 122, chrome < 122, edge < 122, firefox, ios, opera < 108, opera_mobile < 81, safari, samsung < 26.0 } esnext.iterator.every { android < 122, chrome < 122, edge < 122, firefox, ios, opera < 108, opera_mobile < 81, safari, samsung < 26.0 } esnext.iterator.filter { android < 122, chrome < 122, edge < 122, firefox, ios, opera < 108, opera_mobile < 81, safari, samsung < 26.0 } esnext.iterator.find { android < 122, chrome < 122, edge < 122, firefox, ios, opera < 108, opera_mobile < 81, safari, samsung < 26.0 } esnext.iterator.flat-map { android < 122, chrome < 122, edge < 122, firefox, ios, opera < 108, opera_mobile < 81, safari, samsung < 26.0 } esnext.iterator.for-each { android < 122, chrome < 122, edge < 122, firefox, ios, opera < 108, opera_mobile < 81, safari, samsung < 26.0 } esnext.iterator.from { android < 122, chrome < 122, edge < 122, firefox, ios, opera < 108, opera_mobile < 81, safari, samsung < 26.0 } esnext.iterator.map { android < 122, chrome < 122, edge < 122, firefox, ios, opera < 108, opera_mobile < 81, safari, samsung < 26.0 } esnext.iterator.reduce { android < 122, chrome < 122, edge < 122, firefox, ios, opera < 108, opera_mobile < 81, safari, samsung < 26.0 } esnext.iterator.some { android < 122, chrome < 122, edge < 122, firefox, ios, opera < 108, opera_mobile < 81, safari, samsung < 26.0 } esnext.iterator.take { android < 122, chrome < 122, edge < 122, firefox, ios, opera < 108, opera_mobile < 81, safari, samsung < 26.0 } esnext.iterator.to-array { android < 122, chrome < 122, edge < 122, firefox, ios, opera < 108, opera_mobile < 81, safari, samsung < 26.0 } esnext.json.is-raw-json { chrome < 114, firefox, ios, safari, samsung < 23.0 } esnext.json.parse { chrome < 114, firefox, ios, safari, samsung < 23.0 } esnext.json.raw-json { chrome < 114, firefox, ios, safari, samsung < 23.0 } esnext.symbol.async-dispose { android, chrome, edge, firefox, ios, opera, opera_mobile, safari, samsung } esnext.symbol.dispose { android < 125, chrome < 125, edge < 125, firefox, ios, opera < 111, opera_mobile, safari, samsung } esnext.symbol.metadata { android, chrome, edge, firefox, ios, opera, opera_mobile, safari, samsung } web.dom-exception.stack { android, chrome, edge, ios, opera, opera_mobile, safari, samsung } web.immediate { android, chrome, edge, firefox, ios, opera, opera_mobile, safari, samsung } web.structured-clone { android, chrome, edge, firefox, ios, opera, opera_mobile, safari, samsung } web.url.can-parse { android < 120, chrome < 120, edge < 120, ios < 17.0, opera < 106, safari < 17.0, samsung < 25.0 } web.url.parse { android < 126, chrome < 126, edge < 126, firefox < 126, ios, opera < 112, opera_mobile, safari, samsung } web.url-search-params.delete { android < 118, chrome < 118, edge < 118, ios < 17.0, opera < 104, safari < 17.0, samsung < 25.0 } web.url-search-params.has { android < 118, chrome < 118, edge < 118, ios < 17.0, opera < 104, safari < 17.0, samsung < 25.0 } web.url-search-params.size { chrome < 113, ios < 17.0, safari < 17.0, samsung < 23.0 }

Legacy Build Babel Plugins

@babel/preset-env: DEBUG option

Using targets: { "android": "60", "chrome": "60", "edge": "16", "firefox": "52", "ie": "11", "ios": "10.3", "opera": "47", "opera_mobile": "80", "safari": "11", "samsung": "4" }

Using modules transform: auto

Using plugins: transform-unicode-sets-regex { android, chrome < 112, edge < 112, firefox < 116, ie, ios < 17, opera < 98, safari < 17, samsung } proposal-class-static-block { android, chrome < 94, edge < 94, firefox < 93, ie, ios < 16.4, opera < 80, safari < 16.4, samsung < 17 } proposal-private-property-in-object { android, chrome < 91, edge < 91, firefox < 90, ie, ios < 15, opera < 77, safari < 15, samsung < 16 } proposal-class-properties { android, chrome < 74, edge < 79, firefox < 90, ie, ios < 14.5, opera < 62, safari < 14.1, samsung < 11 } proposal-private-methods { android, chrome < 84, edge < 84, firefox < 90, ie, ios < 15, opera < 70, safari < 15, samsung < 14 } proposal-numeric-separator { android, chrome < 75, edge < 79, firefox < 70, ie, ios < 13, opera < 62, safari < 13, samsung < 11 } proposal-logical-assignment-operators { android, chrome < 85, edge < 85, firefox < 79, ie, ios < 14, opera < 71, safari < 14, samsung < 14 } proposal-nullish-coalescing-operator { android, chrome < 80, edge < 80, firefox < 72, ie, ios < 13.4, opera < 67, safari < 13.1, samsung < 13 } proposal-optional-chaining { android, chrome < 80, edge < 80, firefox < 74, ie, ios < 13.4, opera < 67, safari < 13.1, samsung < 13 } proposal-json-strings { android, chrome < 66, edge < 79, firefox < 62, ie, ios < 12, opera < 53, safari < 12, samsung < 9 } proposal-optional-catch-binding { android, chrome < 66, edge < 79, firefox < 58, ie, ios < 11.3, opera < 53, safari < 11.1, samsung < 9 } transform-parameters { firefox < 53, ie, samsung < 5 } proposal-async-generator-functions { android, chrome < 63, edge < 79, firefox < 57, ie, ios < 12, opera < 50, safari < 12, samsung < 8 } proposal-object-rest-spread { edge < 79, firefox < 55, ie, ios < 11.3, safari < 11.1, samsung < 8 } transform-dotall-regex { android, chrome < 62, edge < 79, firefox < 78, ie, ios < 11.3, opera < 49, safari < 11.1, samsung < 8 } proposal-unicode-property-regex { android, chrome < 64, edge < 79, firefox < 78, ie, ios < 11.3, opera < 51, safari < 11.1, samsung < 9 } transform-named-capturing-groups-regex { android, chrome < 64, edge < 79, firefox < 78, ie, ios < 11.3, opera < 51, safari < 11.1, samsung < 9 } transform-async-to-generator { ie, samsung < 6 } transform-exponentiation-operator { ie, samsung < 6 } transform-template-literals { ie } transform-literals { firefox < 53, ie } transform-function-name { firefox < 53, ie, samsung < 5 } transform-arrow-functions { ie, samsung < 5 } transform-classes { ie, samsung < 5 } transform-object-super { ie, samsung < 5 } transform-shorthand-properties { ie } transform-duplicate-keys { ie } transform-computed-properties { ie } transform-for-of { firefox < 53, ie, samsung < 5 } transform-sticky-regex { ie, samsung < 5 } transform-unicode-escapes { firefox < 53, ie } transform-unicode-regex { ie, ios < 12, safari < 12, samsung < 5 } transform-spread { ie, samsung < 5 } transform-destructuring { firefox < 53, ie, samsung < 5 } transform-block-scoping { firefox < 53, ie, samsung < 5 } transform-typeof-symbol { ie } transform-new-target { ie, samsung < 5 } transform-regenerator { firefox < 53, ie, samsung < 5 } proposal-export-namespace-from { android < 72, chrome < 72, edge < 79, firefox < 80, ie, ios < 14.5, opera < 60, safari < 14.1, samsung < 11.0 } syntax-dynamic-import syntax-top-level-await syntax-import-meta syntax-import-attributes

Legacy Build Core-JS Polyfills

The following 273 polyfills may be injected by Babel:

es.symbol { ie, samsung < 5.0 } es.symbol.description { android < 70, chrome < 70, edge < 79, firefox < 63, ie, ios < 12.2, opera < 57, safari < 12.1, samsung < 10.0 } es.symbol.async-iterator { android < 63, chrome < 63, edge < 79, firefox < 55, ie, ios < 12.0, opera < 50, safari < 12.0, samsung < 8.0 } es.symbol.has-instance { ie, samsung < 5.0 } es.symbol.is-concat-spreadable { ie, samsung < 5.0 } es.symbol.iterator { ie } es.symbol.match { edge < 79, ie, samsung < 5.0 } es.symbol.match-all { android < 73, chrome < 73, edge < 79, firefox < 67, ie, ios < 13.0, opera < 60, safari < 13, samsung < 11.0 } es.symbol.replace { edge < 79, ie, samsung < 5.0 } es.symbol.search { edge < 79, ie, samsung < 5.0 } es.symbol.species { ie, samsung < 5.0 } es.symbol.split { edge < 79, ie, samsung < 5.0 } es.symbol.to-primitive { ie, samsung < 5.0 } es.symbol.to-string-tag { ie, samsung < 5.0 } es.symbol.unscopables { ie } es.error.cause { android < 94, chrome < 94, edge < 94, firefox < 91, ie, ios < 15.0, opera < 80, safari < 15.0, samsung < 17.0 } es.aggregate-error { android < 85, chrome < 85, edge < 85, firefox < 79, ie, ios < 14.0, opera < 71, safari < 14.0, samsung < 14.0 } es.aggregate-error.cause { android < 94, chrome < 94, edge < 94, firefox < 91, ie, ios < 15.0, opera < 80, safari < 15.0, samsung < 17.0 } es.array.at { android < 92, chrome < 92, edge < 92, firefox < 90, ie, ios < 15.4, opera < 78, safari < 15.4, samsung < 16.0 } es.array.concat { ie, samsung < 5.0 } es.array.copy-within { ie, samsung < 5.0 } es.array.fill { ie, samsung < 5.0 } es.array.filter { ie, samsung < 5.0 } es.array.find { ie, samsung < 5.0 } es.array.find-index { ie, samsung < 5.0 } es.array.find-last { android < 97, chrome < 97, edge < 97, firefox < 104, ie, ios < 15.4, opera < 83, safari < 15.4, samsung < 18.0 } es.array.find-last-index { android < 97, chrome < 97, edge < 97, firefox < 104, ie, ios < 15.4, opera < 83, safari < 15.4, samsung < 18.0 } es.array.flat { android < 69, chrome < 69, edge < 79, firefox < 62, ie, ios < 12.0, opera < 56, safari < 12.0, samsung < 10.0 } es.array.flat-map { android < 69, chrome < 69, edge < 79, firefox < 62, ie, ios < 12.0, opera < 56, safari < 12.0, samsung < 10.0 } es.array.from { firefox < 53, ie, samsung < 5.0 } es.array.includes { firefox < 102, ie, samsung < 6.0 } es.array.index-of { samsung < 5.0 } es.array.iterator { android < 66, chrome < 66, firefox < 60, ie, opera < 53, samsung < 9.0 } es.array.join { ie } es.array.last-index-of { samsung < 5.0 } es.array.map { ie, samsung < 5.0 } es.array.of { ie, samsung < 5.0 } es.array.push { android < 122, chrome < 122, edge < 122, firefox < 55, ie, ios < 16.0, opera < 108, opera_mobile < 81, safari < 16.0, samsung < 26.0 } es.array.reduce { android < 83, chrome < 83, opera < 69, samsung < 13.0 } es.array.reduce-right { android < 83, chrome < 83, opera < 69, samsung < 13.0 } es.array.reverse { ios < 12.2, safari < 12.0.2 } es.array.slice { ie, samsung < 5.0 } es.array.sort { android < 70, chrome < 70, edge < 79, ie, ios < 12.0, opera < 57, safari < 12.0, samsung < 10.0 } es.array.species { ie, samsung < 5.0 } es.array.splice { ie, samsung < 5.0 } es.array.to-reversed { android < 110, chrome < 110, edge < 110, firefox < 115, ie, ios < 16.0, opera < 96, safari < 16.0, samsung < 21.0 } es.array.to-sorted { android < 110, chrome < 110, edge < 110, firefox < 115, ie, ios < 16.0, opera < 96, safari < 16.0, samsung < 21.0 } es.array.to-spliced { android < 110, chrome < 110, edge < 110, firefox < 115, ie, ios < 16.0, opera < 96, safari < 16.0, samsung < 21.0 } es.array.unscopables.flat { android < 73, chrome < 73, edge < 79, firefox < 67, ie, ios < 13.0, opera < 60, safari < 13, samsung < 11.0 } es.array.unscopables.flat-map { android < 73, chrome < 73, edge < 79, firefox < 67, ie, ios < 13.0, opera < 60, safari < 13, samsung < 11.0 } es.array.unshift { android < 71, chrome < 71, ios < 16.0, opera < 58, safari < 16.0, samsung < 10.0 } es.array.with { android < 110, chrome < 110, edge < 110, firefox < 115, ie, ios < 16.0, opera < 96, safari < 16.0, samsung < 21.0 } es.array-buffer.constructor { ie, ios < 12.0, safari < 12.0 } es.array-buffer.slice { ios < 12.2, safari < 12.1 } es.array-buffer.detached { android < 114, chrome < 114, edge < 114, firefox < 122, ie, ios < 17.4, opera < 100, safari < 17.4, samsung < 23.0 } es.array-buffer.transfer { android < 114, chrome < 114, edge < 114, firefox < 122, ie, ios < 17.4, opera < 100, safari < 17.4, samsung < 23.0 } es.array-buffer.transfer-to-fixed-length { android < 114, chrome < 114, edge < 114, firefox < 122, ie, ios < 17.4, opera < 100, safari < 17.4, samsung < 23.0 } es.date.to-primitive { ie, samsung < 5.0 } es.function.has-instance { ie, samsung < 5.0 } es.function.name { ie } es.global-this { android < 71, chrome < 71, edge < 79, firefox < 65, ie, ios < 12.2, opera < 58, safari < 12.1, samsung < 10.0 } es.json.stringify { android < 72, chrome < 72, edge < 79, firefox < 64, ie, ios < 12.2, opera < 59, safari < 12.1, samsung < 11.0 } es.json.to-string-tag { ie, samsung < 5.0 } es.map { firefox < 53, ie, samsung < 5.0 } es.map.group-by { android < 117, chrome < 117, edge < 117, firefox < 119, ie, ios, opera < 103, safari, samsung < 24.0 } es.math.acosh { ie, samsung < 6.0 } es.math.asinh { ie } es.math.atanh { ie } es.math.cbrt { ie } es.math.clz32 { ie } es.math.cosh { ie } es.math.expm1 { ie } es.math.fround { ie } es.math.hypot { android < 78, chrome < 78, ie, opera < 65, samsung < 12.0 } es.math.imul { ie } es.math.log10 { ie } es.math.log1p { ie } es.math.log2 { ie } es.math.sign { ie } es.math.sinh { ie } es.math.tanh { ie } es.math.to-string-tag { ie, samsung < 5.0 } es.math.trunc { ie } es.number.constructor { ie } es.number.epsilon { ie } es.number.is-finite { ie } es.number.is-integer { ie } es.number.is-nan { ie } es.number.is-safe-integer { ie } es.number.max-safe-integer { ie } es.number.min-safe-integer { ie } es.number.parse-float { edge < 79, ie, ios < 11.0 } es.number.parse-int { edge < 79, ie } es.number.to-exponential { edge < 18, firefox < 87, ie, ios < 11.0, samsung < 5.0 } es.number.to-fixed { edge < 79, ie } es.object.assign { edge < 79, ie, samsung < 5.0 } es.object.define-getter { android < 62, chrome < 62, ie, opera < 49, samsung < 8.0 } es.object.define-setter { android < 62, chrome < 62, ie, opera < 49, samsung < 8.0 } es.object.entries { ie, samsung < 6.0 } es.object.freeze { ie } es.object.from-entries { android < 73, chrome < 73, edge < 79, firefox < 63, ie, ios < 12.2, opera < 60, safari < 12.1, samsung < 11.0 } es.object.get-own-property-descriptor { ie } es.object.get-own-property-descriptors { ie, samsung < 6.0 } es.object.get-own-property-names { ie } es.object.get-prototype-of { ie } es.object.group-by { android < 117, chrome < 117, edge < 117, firefox < 119, ie, ios, opera < 103, safari, samsung < 24.0 } es.object.has-own { android < 93, chrome < 93, edge < 93, firefox < 92, ie, ios < 15.4, opera < 79, safari < 15.4, samsung < 17.0 } es.object.is { ie } es.object.is-extensible { ie } es.object.is-frozen { ie } es.object.is-sealed { ie } es.object.keys { ie } es.object.lookup-getter { android < 62, chrome < 62, ie, opera < 49, samsung < 8.0 } es.object.lookup-setter { android < 62, chrome < 62, ie, opera < 49, samsung < 8.0 } es.object.prevent-extensions { ie } es.object.seal { ie } es.object.to-string { ie, samsung < 5.0 } es.object.values { ie, samsung < 6.0 } es.parse-float { edge < 74 } es.parse-int { edge < 74 } es.promise { android < 67, chrome < 67, edge < 79, firefox < 69, ie, ios < 11.0, opera < 54, samsung < 9.0 } es.promise.all-settled { android < 76, chrome < 76, edge < 79, firefox < 71, ie, ios < 13.0, opera < 63, safari < 13, samsung < 12.0 } es.promise.any { android < 85, chrome < 85, edge < 85, firefox < 79, ie, ios < 14.0, opera < 71, safari < 14.0, samsung < 14.0 } es.promise.finally { android < 67, chrome < 67, edge < 79, firefox < 69, ie, ios < 13.2.3, opera < 54, safari < 13.0.3, samsung < 9.0 } es.promise.with-resolvers { android < 119, chrome < 119, edge < 119, firefox < 121, ie, ios < 17.4, opera < 105, safari < 17.4, samsung < 25.0 } es.reflect.apply { ie, samsung < 5.0 } es.reflect.construct { ie, samsung < 5.0 } es.reflect.define-property { ie, samsung < 5.0 } es.reflect.delete-property { ie, samsung < 5.0 } es.reflect.get { ie, samsung < 5.0 } es.reflect.get-own-property-descriptor { ie, samsung < 5.0 } es.reflect.get-prototype-of { ie, samsung < 5.0 } es.reflect.has { ie, samsung < 5.0 } es.reflect.is-extensible { ie, samsung < 5.0 } es.reflect.own-keys { ie, samsung < 5.0 } es.reflect.prevent-extensions { ie, samsung < 5.0 } es.reflect.set { edge < 79, ie, samsung < 5.0 } es.reflect.set-prototype-of { ie, samsung < 5.0 } es.reflect.to-string-tag { android < 86, chrome < 86, edge < 86, firefox < 82, ie, ios < 14.0, opera < 72, safari < 14.0, samsung < 14.0 } es.regexp.constructor { android < 64, chrome < 64, edge < 79, firefox < 78, ie, ios < 11.3, opera < 51, safari < 11.1, samsung < 9.0 } es.regexp.dot-all { android < 62, chrome < 62, edge < 79, firefox < 78, ie, ios < 11.3, opera < 49, safari < 11.1, samsung < 8.0 } es.regexp.exec { android < 64, chrome < 64, edge < 79, firefox < 78, ie, ios < 11.3, opera < 51, safari < 11.1, samsung < 9.0 } es.regexp.flags { android < 111, chrome < 111, edge < 111, firefox < 78, ie, ios < 11.3, opera < 97, safari < 11.1, samsung < 22.0 } es.regexp.sticky { ie, samsung < 5.0 } es.regexp.test { edge < 79, ie, samsung < 5.0 } es.regexp.to-string { edge < 79, ie, samsung < 5.0 } es.set { firefox < 53, ie, samsung < 5.0 } es.set.difference.v2 { android < 123, chrome < 123, edge < 123, firefox < 127, ie, ios, opera < 109, opera_mobile < 82, safari, samsung } es.set.intersection.v2 { android < 123, chrome < 123, edge < 123, firefox < 127, ie, ios, opera < 109, opera_mobile < 82, safari, samsung } es.set.is-disjoint-from.v2 { android < 123, chrome < 123, edge < 123, firefox < 127, ie, ios, opera < 109, opera_mobile < 82, safari, samsung } es.set.is-subset-of.v2 { android < 123, chrome < 123, edge < 123, firefox < 127, ie, ios, opera < 109, opera_mobile < 82, safari, samsung } es.set.is-superset-of.v2 { android < 123, chrome < 123, edge < 123, firefox < 127, ie, ios, opera < 109, opera_mobile < 82, safari, samsung } es.set.symmetric-difference.v2 { android < 123, chrome < 123, edge < 123, firefox < 127, ie, ios, opera < 109, opera_mobile < 82, safari, samsung } es.set.union.v2 { android < 123, chrome < 123, edge < 123, firefox < 127, ie, ios, opera < 109, opera_mobile < 82, safari, samsung } es.string.at-alternative { android < 92, chrome < 92, edge < 92, firefox < 90, ie, ios < 15.4, opera < 78, safari < 15.4, samsung < 16.0 } es.string.code-point-at { ie } es.string.ends-with { edge < 79, ie, samsung < 5.0 } es.string.from-code-point { ie } es.string.includes { edge < 79, ie, samsung < 5.0 } es.string.is-well-formed { android < 111, chrome < 111, edge < 111, firefox < 119, ie, ios < 16.4, opera < 97, safari < 16.4, samsung < 22.0 } es.string.iterator { ie } es.string.match { edge < 79, ie, samsung < 5.0 } es.string.match-all { android < 80, chrome < 80, edge < 80, firefox < 73, ie, ios < 13.4, opera < 67, safari < 13.1, samsung < 13.0 } es.string.pad-end { ie, ios < 11.0, samsung < 7.0 } es.string.pad-start { ie, ios < 11.0, samsung < 7.0 } es.string.raw { ie } es.string.repeat { ie } es.string.replace { android < 64, chrome < 64, edge < 79, firefox < 78, ie, ios < 14.0, opera < 51, safari < 14.0, samsung < 9.0 } es.string.replace-all { android < 85, chrome < 85, edge < 85, firefox < 77, ie, ios < 13.4, opera < 71, safari < 13.1, samsung < 14.0 } es.string.search { edge < 79, ie, samsung < 5.0 } es.string.split { edge < 79, ie, samsung < 6.0 } es.string.starts-with { edge < 79, ie, samsung < 5.0 } es.string.to-well-formed { android < 111, chrome < 111, edge < 111, firefox < 119, ie, ios < 16.4, opera < 97, safari < 16.4, samsung < 22.0 } es.string.trim { ie, ios < 12.2, safari < 12.1, samsung < 7.0 } es.string.trim-end { android < 66, chrome < 66, edge < 79, firefox < 61, ie, ios < 12.2, opera < 53, safari < 12.1, samsung < 9.0 } es.string.trim-start { android < 66, chrome < 66, edge < 79, firefox < 61, ie, ios < 12.0, opera < 53, safari < 12.0, samsung < 9.0 } es.string.anchor { ie } es.string.big { ie } es.string.blink { ie } es.string.bold { ie } es.string.fixed { ie } es.string.fontcolor { ie } es.string.fontsize { ie } es.string.italics { ie } es.string.link { ie } es.string.small { ie } es.string.strike { ie } es.string.sub { ie } es.string.sup { ie } es.typed-array.float32-array { firefox < 55, ie, ios < 14.0, safari < 14.0, samsung < 6.0 } es.typed-array.float64-array { firefox < 55, ie, ios < 14.0, safari < 14.0, samsung < 6.0 } es.typed-array.int8-array { firefox < 55, ie, ios < 14.0, safari < 14.0, samsung < 6.0 } es.typed-array.int16-array { firefox < 55, ie, ios < 14.0, safari < 14.0, samsung < 6.0 } es.typed-array.int32-array { firefox < 55, ie, ios < 14.0, safari < 14.0, samsung < 6.0 } es.typed-array.uint8-array { firefox < 55, ie, ios < 14.0, safari < 14.0, samsung < 6.0 } es.typed-array.uint8-clamped-array { firefox < 55, ie, ios < 14.0, safari < 14.0, samsung < 6.0 } es.typed-array.uint16-array { firefox < 55, ie, ios < 14.0, safari < 14.0, samsung < 6.0 } es.typed-array.uint32-array { firefox < 55, ie, ios < 14.0, safari < 14.0, samsung < 6.0 } es.typed-array.at { android < 92, chrome < 92, edge < 92, firefox < 90, ie, ios < 15.4, opera < 78, safari < 15.4, samsung < 16.0 } es.typed-array.copy-within { ie, samsung < 5.0 } es.typed-array.every { ie, samsung < 5.0 } es.typed-array.fill { edge < 79, firefox < 55, ie, ios < 14.5, safari < 14.1, samsung < 7.0 } es.typed-array.filter { ie, samsung < 5.0 } es.typed-array.find { ie, samsung < 5.0 } es.typed-array.find-index { ie, samsung < 5.0 } es.typed-array.find-last { android < 97, chrome < 97, edge < 97, firefox < 104, ie, ios < 15.4, opera < 83, safari < 15.4, samsung < 18.0 } es.typed-array.find-last-index { android < 97, chrome < 97, edge < 97, firefox < 104, ie, ios < 15.4, opera < 83, safari < 15.4, samsung < 18.0 } es.typed-array.for-each { ie, samsung < 5.0 } es.typed-array.from { firefox < 55, ie, ios < 14.0, safari < 14.0, samsung < 6.0 } es.typed-array.includes { ie, samsung < 5.0 } es.typed-array.index-of { ie, samsung < 5.0 } es.typed-array.iterator { ie, samsung < 5.0 } es.typed-array.join { ie, samsung < 5.0 } es.typed-array.last-index-of { ie, samsung < 5.0 } es.typed-array.map { ie, samsung < 5.0 } es.typed-array.of { firefox < 55, ie, ios < 14.0, safari < 14.0, samsung < 6.0 } es.typed-array.reduce { ie, samsung < 5.0 } es.typed-array.reduce-right { ie, samsung < 5.0 } es.typed-array.reverse { ie, samsung < 5.0 } es.typed-array.set { android < 95, chrome < 95, edge < 95, firefox < 54, ie, ios < 14.5, opera < 81, safari < 14.1, samsung < 17.0 } es.typed-array.slice { ie, samsung < 5.0 } es.typed-array.some { ie, samsung < 5.0 } es.typed-array.sort { android < 74, chrome < 74, edge < 79, firefox < 67, ie, ios < 14.5, opera < 61, safari < 14.1, samsung < 11.0 } es.typed-array.subarray { ie } es.typed-array.to-locale-string { edge < 79, ie, samsung < 5.0 } es.typed-array.to-reversed { android < 110, chrome < 110, edge < 110, firefox < 115, ie, ios < 16.0, opera < 96, safari < 16.0, samsung < 21.0 } es.typed-array.to-sorted { android < 110, chrome < 110, edge < 110, firefox < 115, ie, ios < 16.0, opera < 96, safari < 16.0, samsung < 21.0 } es.typed-array.to-string { ie, samsung < 5.0 } es.typed-array.with { android < 110, chrome < 110, edge < 110, firefox < 115, ie, ios < 16.4, opera < 96, safari < 16.4, samsung < 21.0 } es.weak-map { edge < 79, firefox < 53, ie, samsung < 5.0 } es.weak-set { firefox < 53, ie, samsung < 5.0 } esnext.suppressed-error.constructor { android, chrome, edge, firefox, ie, ios, opera, opera_mobile, safari, samsung } esnext.array.from-async { android < 121, chrome < 121, edge < 121, firefox < 115, ie, ios, opera < 107, opera_mobile < 81, safari, samsung < 25.0 } esnext.array.group { android, chrome, edge, firefox, ie, ios, opera, opera_mobile, safari, samsung } esnext.array.group-to-map { android, chrome, edge, firefox, ie, ios, opera, opera_mobile, safari, samsung } esnext.iterator.constructor { android < 122, chrome < 122, edge < 122, firefox, ie, ios, opera < 108, opera_mobile < 81, safari, samsung < 26.0 } esnext.iterator.drop { android < 122, chrome < 122, edge < 122, firefox, ie, ios, opera < 108, opera_mobile < 81, safari, samsung < 26.0 } esnext.iterator.every { android < 122, chrome < 122, edge < 122, firefox, ie, ios, opera < 108, opera_mobile < 81, safari, samsung < 26.0 } esnext.iterator.filter { android < 122, chrome < 122, edge < 122, firefox, ie, ios, opera < 108, opera_mobile < 81, safari, samsung < 26.0 } esnext.iterator.find { android < 122, chrome < 122, edge < 122, firefox, ie, ios, opera < 108, opera_mobile < 81, safari, samsung < 26.0 } esnext.iterator.flat-map { android < 122, chrome < 122, edge < 122, firefox, ie, ios, opera < 108, opera_mobile < 81, safari, samsung < 26.0 } esnext.iterator.for-each { android < 122, chrome < 122, edge < 122, firefox, ie, ios, opera < 108, opera_mobile < 81, safari, samsung < 26.0 } esnext.iterator.from { android < 122, chrome < 122, edge < 122, firefox, ie, ios, opera < 108, opera_mobile < 81, safari, samsung < 26.0 } esnext.iterator.map { android < 122, chrome < 122, edge < 122, firefox, ie, ios, opera < 108, opera_mobile < 81, safari, samsung < 26.0 } esnext.iterator.reduce { android < 122, chrome < 122, edge < 122, firefox, ie, ios, opera < 108, opera_mobile < 81, safari, samsung < 26.0 } esnext.iterator.some { android < 122, chrome < 122, edge < 122, firefox, ie, ios, opera < 108, opera_mobile < 81, safari, samsung < 26.0 } esnext.iterator.take { android < 122, chrome < 122, edge < 122, firefox, ie, ios, opera < 108, opera_mobile < 81, safari, samsung < 26.0 } esnext.iterator.to-array { android < 122, chrome < 122, edge < 122, firefox, ie, ios, opera < 108, opera_mobile < 81, safari, samsung < 26.0 } esnext.json.is-raw-json { android < 114, chrome < 114, edge < 114, firefox, ie, ios, opera < 100, safari, samsung < 23.0 } esnext.json.parse { android < 114, chrome < 114, edge < 114, firefox, ie, ios, opera < 100, safari, samsung < 23.0 } esnext.json.raw-json { android < 114, chrome < 114, edge < 114, firefox, ie, ios, opera < 100, safari, samsung < 23.0 } esnext.symbol.async-dispose { android, chrome, edge, firefox, ie, ios, opera, opera_mobile, safari, samsung } esnext.symbol.dispose { android < 125, chrome < 125, edge < 125, firefox, ie, ios, opera < 111, opera_mobile, safari, samsung } esnext.symbol.metadata { android, chrome, edge, firefox, ie, ios, opera, opera_mobile, safari, samsung } web.atob { ie } web.btoa { ie } web.dom-collections.for-each { ie, samsung < 7.0 } web.dom-collections.iterator { android < 66, chrome < 66, edge < 79, firefox < 60, ie, ios < 13.4, opera < 53, safari < 13.1, samsung < 9.0 } web.dom-exception.constructor { edge < 79, ie, ios < 11.3, safari < 11.1, samsung < 5.0 } web.dom-exception.stack { android, chrome, edge, ie, ios, opera, opera_mobile, safari, samsung } web.dom-exception.to-string-tag { edge < 79, ie, ios < 11.3, safari < 11.1, samsung < 5.0 } web.immediate { android, chrome, edge, firefox, ios, opera, opera_mobile, safari, samsung } web.queue-microtask { android < 71, chrome < 71, edge < 79, firefox < 69, ie, ios < 12.2, opera < 58, safari < 12.1, samsung < 10.0 } web.self { android < 86, chrome < 86, edge < 86, ie, opera < 72, samsung < 14.0 } web.structured-clone { android, chrome, edge, firefox, ie, ios, opera, opera_mobile, safari, samsung } web.url { android < 67, chrome < 67, edge < 79, firefox < 57, ie, ios < 14.0, opera < 54, safari < 14.0, samsung < 9.0 } web.url.can-parse { android < 120, chrome < 120, edge < 120, firefox < 115, ie, ios < 17.0, opera < 106, safari < 17.0, samsung < 25.0 } web.url.parse { android < 126, chrome < 126, edge < 126, firefox < 126, ie, ios, opera < 112, opera_mobile, safari, samsung } web.url.to-json { android < 71, chrome < 71, edge < 79, firefox < 57, ie, ios < 14.0, opera < 58, safari < 14.0, samsung < 10.0 } web.url-search-params { android < 67, chrome < 67, edge < 79, firefox < 57, ie, ios < 14.0, opera < 54, safari < 14.0, samsung < 9.0 } web.url-search-params.delete { android < 118, chrome < 118, edge < 118, firefox < 115, ie, ios < 17.0, opera < 104, safari < 17.0, samsung < 25.0 } web.url-search-params.has { android < 118, chrome < 118, edge < 118, firefox < 115, ie, ios < 17.0, opera < 104, safari < 17.0, samsung < 25.0 } web.url-search-params.size { android < 113, chrome < 113, edge < 113, firefox < 112, ie, ios < 17.0, opera < 99, safari < 17.0, samsung < 23.0 }

Type of change

  • [ ] Dependency upgrade
  • [ ] Bugfix (non-breaking change which fixes an issue)
  • [x] New feature (thank you!)
  • [ ] Breaking change (fix/feature causing existing functionality to break)
  • [x] Code quality improvements to existing code or addition of tests

Example configuration


Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue or discussion:
  • Link to documentation pull request:

Checklist

  • [x] The code change is tested and works locally.
  • [x] There is no commented out code in this PR.
  • [ ] Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

Summary by CodeRabbit

  • New Features

    • Enhanced browser compatibility by refining build criteria and script loading logic.
    • Added a script loader template for more efficient and conditional script loading.
  • Improvements

    • Updated Babel configuration to support modern decorators, class properties, and private methods.
    • Simplified and optimized conditional logic for JavaScript file loading based on user agent detection.
  • Dependencies

    • Added browserslist-useragent-regexp version 4.1.3 to project dependencies.

steverep avatar May 11 '23 05:05 steverep

Should have mentioned that the regex includes all the browsers in the CanIUse.com database, not just the ones listed above. Here's the full test:

var isModern = /Edge?\/(1{2}\d|1[2-9]\d|[2-9]\d{2}|\d{4,})(\.\d+|)(\.\d+|)|Firefox\/(10[2-9]|1[1-9]\d|[2-9]\d{2}|\d{4,})\.\d+(\.\d+|)|Chrom(ium|e)\/(109|1[1-9]\d|[2-9]\d{2}|\d{4,})\.\d+(\.\d+|)|Maci.+ Version\/(15\.([6-9]|\d{2,})|(1[6-9]|[2-9]\d|\d{3,})\.\d+)([,.]\d+|)( Mobile\/\w+|) Safari\/|Chrome.+OPR\/(9[4-9]|\d{3,})\.\d+\.\d+|(CPU[ +]OS|iPhone[ +]OS|CPU[ +]iPhone|CPU IPhone OS|CPU iPad OS)[ +]+(15[._]([6-9]|\d{2,})|(1[6-9]|[2-9]\d|\d{3,})[._]\d+)([._]\d+|)|Android:?[ /-](1{2}[2-9]|1[2-9]\d|[2-9]\d{2}|\d{4,})(\.\d+|)(\.\d+|)|Mobile Safari.+OPR\/(7[3-9]|[89]\d|\d{3,})\.\d+\.\d+|Android.+Firefox\/(1{2}\d|1[2-9]\d|[2-9]\d{2}|\d{4,})\.\d+(\.\d+|)|Android.+Chrom(ium|e)\/(1{2}[2-9]|1[2-9]\d|[2-9]\d{2}|\d{4,})\.\d+(\.\d+|)|Android.+(UC? ?Browser|UCWEB|U3)[ /]?(13\.([4-9]|\d{2,})|(1[4-9]|[2-9]\d|\d{3,})\.\d+)\.\d+|SamsungBrowser\/(19|[2-9]\d|\d{3,})\.\d+|Android.+MQ{2}Browser\/(13(\.([1-9]|\d{2,})|)|(1[4-9]|[2-9]\d|\d{3,})(\.\d+|))(\.\d+|)|K[Aa][Ii]OS\/(3\.\d+|([4-9]|\d{2,})\.\d+)(\.\d+|)/.test(navigator.userAgent);

steverep avatar May 12 '23 15:05 steverep

I feel like these restraints are a bit too much, we are now pushing people to the much bigger and slower ES5 build, while their device/browser is perfectly capable of running on our latest build?

Are we fixing certain browsers with this, that now don't work with latest and are moved to ES5? If so what are we fixing and could we target that more precise?

If it would really gain us something in terms of performance I would get it, but it seems that isn't the case (at least for now?)

bramkragten avatar May 22 '23 08:05 bramkragten

I'm marking this as a draft because I want to investigate how it treats android mobile versions. The regex is only grabbing the latest version but the docs say it should be treated like desktop.

Answering your questions in the meantime...

I feel like these restraints are a bit too much, we are now pushing people to the much bigger and slower ES5 build, while their device/browser is perfectly capable of running on our latest build?

In terms of size, the 2 builds are actually not that far apart anymore after #16466. Compared to the current release of major browsers, the latest build is actually targeting browsers much closer to the legacy requirements from #16384, and that gap will keep getting smaller without redefining somehow. So this is really just trying to drive a bigger wedge between the 2 builds and eek out as much extra performance and reduced size as possible. Based on the global usage data, this might affect about 5% of users, but that's an estimate for sure.

That said, I'm certainly not claiming this is the best position for the wedge so that's worth discussing. I'm not sure how to make it more "accurate" though in the absence of including user agents in the HA analytics data.

Are we fixing certain browsers with this, that now don't work with latest and are moved to ES5? If so what are we fixing and could we target that more precise?

Yes. Though it's not turned on right now, we should be allowing Babel to inject core-js polyfills into the latest build in order to fix or support various features, some of which are used frequently. If we did under the current dynamic import test, here's the plugins and polyfills that would be used:

Modern Build Babel Plugins

@babel/preset-env: DEBUG option

Using targets: { "android": "113", "chrome": "63", "edge": "79", "firefox": "67", "ios": "13", "opera": "50", "safari": "13", "samsung": "8.2" }

Using modules transform: auto

Using plugins: proposal-class-static-block { chrome < 94, edge < 94, firefox < 93, ios, opera < 80, safari, samsung < 17 } proposal-private-property-in-object { chrome < 91, edge < 91, firefox < 90, ios < 15, opera < 77, safari < 15, samsung < 16 } proposal-class-properties { chrome < 74, firefox < 90, ios < 15, opera < 62, safari < 14.1, samsung < 11 } proposal-private-methods { chrome < 84, edge < 84, firefox < 90, ios < 15, opera < 70, safari < 15, samsung < 14 } proposal-numeric-separator { chrome < 75, firefox < 70, opera < 62, samsung < 11 } proposal-logical-assignment-operators { chrome < 85, edge < 85, firefox < 79, ios < 14, opera < 71, safari < 14, samsung < 14 } proposal-nullish-coalescing-operator { chrome < 80, edge < 80, firefox < 72, ios < 13.4, opera < 67, safari < 13.1, samsung < 13 } proposal-optional-chaining { chrome < 80, edge < 80, firefox < 74, ios < 13.4, opera < 67, safari < 13.1, samsung < 13 } proposal-json-strings { chrome < 66, opera < 53, samsung < 9 } proposal-optional-catch-binding { chrome < 66, opera < 53, samsung < 9 } syntax-async-generators syntax-object-rest-spread transform-dotall-regex { firefox < 78 } proposal-unicode-property-regex { chrome < 64, firefox < 78, opera < 51, samsung < 9 } transform-named-capturing-groups-regex { chrome < 64, firefox < 78, opera < 51, samsung < 9 } proposal-export-namespace-from { chrome < 72, firefox < 80, ios, opera < 60, safari, samsung < 11.0 } bugfix/transform-safari-id-destructuring-collision-in-function-expression { ios, safari } syntax-dynamic-import syntax-export-namespace-from syntax-top-level-await syntax-import-meta syntax-import-assertions

Modern Build Core-JS Polyfills

The following 77 polyfills may be injected by Babel:

es.symbol.description { chrome < 70, opera < 57, samsung < 10.0 } es.symbol.match-all { chrome < 73, opera < 60, samsung < 11.0 } es.error.cause { chrome < 94, edge < 94, firefox < 91, ios < 15.0, opera < 80, safari < 15.0, samsung < 17.0 } es.aggregate-error { chrome < 85, edge < 85, firefox < 79, ios < 14.0, opera < 71, safari < 14.0, samsung < 14.0 } es.aggregate-error.cause { chrome < 94, edge < 94, firefox < 91, ios < 15.0, opera < 80, safari < 15.0, samsung < 17.0 } es.array.at { chrome < 92, edge < 92, firefox < 90, ios < 15.4, opera < 78, safari < 15.4, samsung < 16.0 } es.array.find-last { chrome < 97, edge < 97, firefox < 104, ios < 15.4, opera < 83, safari < 15.4, samsung < 18.0 } es.array.find-last-index { chrome < 97, edge < 97, firefox < 104, ios < 15.4, opera < 83, safari < 15.4, samsung < 18.0 } es.array.flat { chrome < 69, opera < 56, samsung < 10.0 } es.array.flat-map { chrome < 69, opera < 56, samsung < 10.0 } es.array.includes { firefox < 102 } es.array.iterator { chrome < 66, opera < 53, samsung < 9.0 } es.array.push { android, chrome, edge, ios < 16.0, opera, safari < 16.0, samsung } es.array.reduce { chrome < 83, opera < 69, samsung < 13.0 } es.array.reduce-right { chrome < 83, opera < 69, samsung < 13.0 } es.array.sort { chrome < 70, opera < 57, samsung < 10.0 } es.array.to-reversed { chrome < 110, edge < 110, firefox, ios < 16.0, opera < 96, safari < 16.0, samsung < 21.0 } es.array.to-sorted { chrome < 110, edge < 110, firefox, ios < 16.0, opera < 96, safari < 16.0, samsung < 21.0 } es.array.to-spliced { chrome < 110, edge < 110, firefox, ios < 16.0, opera < 96, safari < 16.0, samsung < 21.0 } es.array.unscopables.flat { chrome < 73, opera < 60, samsung < 11.0 } es.array.unscopables.flat-map { chrome < 73, opera < 60, samsung < 11.0 } es.array.unshift { chrome < 71, ios < 16.0, opera < 58, safari < 16.0, samsung < 10.0 } es.array.with { chrome < 110, edge < 110, firefox, ios < 16.0, opera < 96, safari < 16.0, samsung < 21.0 } es.global-this { chrome < 71, opera < 58, samsung < 10.0 } es.json.stringify { chrome < 72, opera < 59, samsung < 11.0 } es.math.hypot { chrome < 78, opera < 65, samsung < 12.0 } es.number.to-exponential { firefox < 87 } es.object.from-entries { chrome < 73, opera < 60, samsung < 11.0 } es.object.has-own { chrome < 93, edge < 93, firefox < 92, ios < 15.4, opera < 79, safari < 15.4, samsung < 17.0 } es.promise { chrome < 67, firefox < 69, opera < 54, samsung < 9.0 } es.promise.all-settled { chrome < 76, firefox < 71, opera < 63, samsung < 12.0 } es.promise.any { chrome < 85, edge < 85, firefox < 79, ios < 14.0, opera < 71, safari < 14.0, samsung < 14.0 } es.promise.finally { chrome < 67, firefox < 69, ios < 13.2.3, opera < 54, safari < 13.0.3, samsung < 9.0 } es.reflect.to-string-tag { chrome < 86, edge < 86, firefox < 82, ios < 14.0, opera < 72, safari < 14.0, samsung < 14.0 } es.regexp.constructor { chrome < 64, firefox < 78, opera < 51, samsung < 9.0 } es.regexp.dot-all { firefox < 78 } es.regexp.exec { chrome < 64, firefox < 78, opera < 51, samsung < 9.0 } es.regexp.flags { chrome < 111, edge < 111, firefox < 78, opera < 97, samsung } es.string.at-alternative { chrome < 92, edge < 92, firefox < 90, ios < 15.4, opera < 78, safari < 15.4, samsung < 16.0 } es.string.match-all { chrome < 80, edge < 80, firefox < 73, ios < 13.4, opera < 67, safari < 13.1, samsung < 13.0 } es.string.replace { chrome < 64, firefox < 78, ios < 14.0, opera < 51, safari < 14.0, samsung < 9.0 } es.string.replace-all { chrome < 85, edge < 85, firefox < 77, ios < 13.4, opera < 71, safari < 13.1, samsung < 14.0 } es.string.trim-end { chrome < 66, opera < 53, samsung < 9.0 } es.string.trim-start { chrome < 66, opera < 53, samsung < 9.0 } es.typed-array.float32-array { ios < 14.0, safari < 14.0 } es.typed-array.float64-array { ios < 14.0, safari < 14.0 } es.typed-array.int8-array { ios < 14.0, safari < 14.0 } es.typed-array.int16-array { ios < 14.0, safari < 14.0 } es.typed-array.int32-array { ios < 14.0, safari < 14.0 } es.typed-array.uint8-array { ios < 14.0, safari < 14.0 } es.typed-array.uint8-clamped-array { ios < 14.0, safari < 14.0 } es.typed-array.uint16-array { ios < 14.0, safari < 14.0 } es.typed-array.uint32-array { ios < 14.0, safari < 14.0 } es.typed-array.at { chrome < 92, edge < 92, firefox < 90, ios < 15.4, opera < 78, safari < 15.4, samsung < 16.0 } es.typed-array.fill { ios < 14.5, safari < 14.1 } es.typed-array.find-last { chrome < 97, edge < 97, firefox < 104, ios < 15.4, opera < 83, safari < 15.4, samsung < 18.0 } es.typed-array.find-last-index { chrome < 97, edge < 97, firefox < 104, ios < 15.4, opera < 83, safari < 15.4, samsung < 18.0 } es.typed-array.from { ios < 14.0, safari < 14.0 } es.typed-array.of { ios < 14.0, safari < 14.0 } es.typed-array.set { chrome < 95, edge < 95, ios < 14.5, opera < 81, safari < 14.1, samsung < 17.0 } es.typed-array.sort { chrome < 74, ios < 14.5, opera < 61, safari < 14.1, samsung < 11.0 } es.typed-array.to-reversed { chrome < 110, edge < 110, firefox, ios < 16.0, opera < 96, safari < 16.0, samsung < 21.0 } es.typed-array.to-sorted { chrome < 110, edge < 110, firefox, ios < 16.0, opera < 96, safari < 16.0, samsung < 21.0 } es.typed-array.with { chrome < 110, edge < 110, firefox, ios < 16.4, opera < 96, safari < 16.4, samsung < 21.0 } esnext.array.group { android, chrome, edge, firefox, ios < 16.4, opera, safari < 16.4, samsung } esnext.array.group-to-map { android, chrome, edge, firefox, ios < 16.4, opera, safari < 16.4, samsung } web.dom-collections.iterator { chrome < 66, ios < 13.4, opera < 53, safari < 13.1, samsung < 9.0 } web.dom-exception.stack { android, chrome, edge, ios, opera, safari, samsung } web.immediate { android, chrome, edge, firefox, ios, opera, safari, samsung } web.queue-microtask { chrome < 71, firefox < 69, opera < 58, samsung < 10.0 } web.self { chrome < 86, edge < 86, opera < 72, samsung < 14.0 } web.structured-clone { android, chrome, edge, firefox, ios, opera, safari, samsung } web.url { chrome < 67, ios < 14.0, opera < 54, safari < 14.0, samsung < 9.0 } web.url.can-parse { android, chrome, edge, firefox, ios, opera, safari, samsung } web.url.to-json { chrome < 71, ios < 14.0, opera < 58, safari < 14.0, samsung < 10.0 } web.url-search-params { chrome < 67, ios < 14.0, opera < 54, safari < 14.0, samsung < 9.0 } web.url-search-params.size { chrome < 113, edge < 113, firefox < 112, ios, opera < 99, safari, samsung }

With these redefined requirements, there would be many less possible polyfills required (21 vs 77):

Redefined Modern Build Babel Plugins

@babel/preset-env: DEBUG option

Using targets: { "android": "113", "chrome": "109", "edge": "111", "firefox": "102", "ios": "15.6", "opera": "97", "safari": "15.6", "samsung": "19" }

Using modules transform: auto

Using plugins: proposal-class-static-block { ios, safari } syntax-private-property-in-object syntax-class-properties syntax-numeric-separator syntax-nullish-coalescing-operator syntax-optional-chaining syntax-json-strings syntax-optional-catch-binding syntax-async-generators syntax-object-rest-spread proposal-export-namespace-from { ios, safari } bugfix/transform-safari-id-destructuring-collision-in-function-expression { ios, safari } syntax-dynamic-import syntax-export-namespace-from syntax-top-level-await syntax-import-meta syntax-import-assertions

Redefined Modern Build Core-JS Polyfills

The following 21 polyfills may be injected by Babel:

es.array.find-last { firefox < 104 } es.array.find-last-index { firefox < 104 } es.array.push { android, chrome, edge, ios < 16.0, opera, safari < 16.0, samsung } es.array.to-reversed { chrome < 110, firefox, ios < 16.0, safari < 16.0, samsung < 21.0 } es.array.to-sorted { chrome < 110, firefox, ios < 16.0, safari < 16.0, samsung < 21.0 } es.array.to-spliced { chrome < 110, firefox, ios < 16.0, safari < 16.0, samsung < 21.0 } es.array.unshift { ios < 16.0, safari < 16.0 } es.array.with { chrome < 110, firefox, ios < 16.0, safari < 16.0, samsung < 21.0 } es.regexp.flags { chrome < 111, samsung } es.typed-array.find-last { firefox < 104 } es.typed-array.find-last-index { firefox < 104 } es.typed-array.to-reversed { chrome < 110, firefox, ios < 16.0, safari < 16.0, samsung < 21.0 } es.typed-array.to-sorted { chrome < 110, firefox, ios < 16.0, safari < 16.0, samsung < 21.0 } es.typed-array.with { chrome < 110, firefox, ios < 16.4, safari < 16.4, samsung < 21.0 } esnext.array.group { android, chrome, edge, firefox, ios < 16.4, opera, safari < 16.4, samsung } esnext.array.group-to-map { android, chrome, edge, firefox, ios < 16.4, opera, safari < 16.4, samsung } web.dom-exception.stack { android, chrome, edge, ios, opera, safari, samsung } web.immediate { android, chrome, edge, firefox, ios, opera, safari, samsung } web.structured-clone { android, chrome, edge, firefox, ios, opera, safari, samsung } web.url.can-parse { android, chrome, edge, firefox, ios, opera, safari, samsung } web.url-search-params.size { chrome < 113, edge < 113, firefox < 112, ios, opera < 99, safari, samsung }

If it would really gain us something in terms of performance I would get it, but it seems that isn't the case (at least for now?)

Technically, there would be a performance benefit as there are a number of things that wouldn't be transpiled or polyfilled anymore in the latest builds. Optional chaining would be one example HA uses frequently. If we used JS private fields/methods instead of just TS annotations, that would be another big one.

steverep avatar May 22 '23 20:05 steverep

FYI, to deal with the android issue, some fixes to browserslist are needed:

  • https://github.com/browserslist/browserslist-useragent-regexp/issues/1484
  • https://github.com/browserslist/browserslist/issues/761

The latter can be worked around temporarily, but the first is a hold up.

steverep avatar May 23 '23 16:05 steverep

I submitted fixes to the browserslist packages and they're now incorporated here so the regex looks much better for Android:

var isModern = /Edge?\/(10[4-9]|1[1-9]\d|[2-9]\d{2}|\d{4,})(\.\d+|)(\.\d+|)|Firefox\/(10[2-9]|1[1-9]\d|[2-9]\d{2}|\d{4,})\.\d+(\.\d+|)|Chrom(ium|e)\/(10[4-9]|1[1-9]\d|[2-9]\d{2}|\d{4,})\.\d+(\.\d+|)|Maci.+ Version\/(15\.([6-9]|\d{2,})|(1[6-9]|[2-9]\d|\d{3,})\.\d+)([,.]\d+|)( Mobile\/\w+|) Safari\/|Chrome.+OPR\/(89|9\d|\d{3,})\.\d+\.\d+|(CPU[ +]OS|iPhone[ +]OS|CPU[ +]iPhone|CPU IPhone OS|CPU iPad OS)[ +]+(15[._]([6-9]|\d{2,})|(1[6-9]|[2-9]\d|\d{3,})[._]\d+)([._]\d+|)|Android:?[ /-](10[4-9]|1[1-9]\d|[2-9]\d{2}|\d{4,})(\.\d+|)(\.\d+|)|Mobile Safari.+OPR\/(7[3-9]|[89]\d|\d{3,})\.\d+\.\d+|Android.+Firefox\/(10[3-9]|1[1-9]\d|[2-9]\d{2}|\d{4,})\.\d+(\.\d+|)|Android.+Chrom(ium|e)\/(10[4-9]|1[1-9]\d|[2-9]\d{2}|\d{4,})\.\d+(\.\d+|)|SamsungBrowser\/(1[89]|[2-9]\d|\d{3,})\.\d+/.test(navigator.userAgent);

In fixing the browserslists issues, I sort of created a Babel issue, https://github.com/babel/babel/issues/15711, with Opera, but they need to fix that.

steverep avatar Jul 02 '23 02:07 steverep

In terms of adding more browsers, I think we could safely include anything released in the last year as opposed to just the last 2 versions. The popularity of older iOS versions and inclusion of Firefox ESR keep the transpiling and polyfilling to about a year in the past anyway. Going beyond 1 year I think would be excessive.

The other parameter to play with is the usage percentage, but that will start bringing back pretty old stuff depending on the value. For example, > 0.2% goes back to IOS 12 and Chrome 79, adding extra transpiling and polyfilling of course.

Thoughts?

steverep avatar Jul 02 '23 03:07 steverep

Okay I think this is probably ready to go now:

  • Incorporated Babel update which fixes the Opera issue mentioned above (#17201).
  • Now using browsers released in last year instead of just last 2 versions. In addition to reasons in my last comment, this just makes better sense because then Edge, Chrome, and Android all line up as they should since they are based on the same Blink version (also mostly true for Opera but with different version number).

I updated the OP to reflect all changes.

steverep avatar Jul 07 '23 20:07 steverep

@bramkragten are you generally okay with this approach (minus the exact query to use perhaps)? If so, I can throw together updated documentation for https://github.com/home-assistant/home-assistant.io/issues/27509.

steverep avatar Aug 07 '23 03:08 steverep

I don't really like that we will now test on useragent instead of actual features, the useragent can be overriden by a client (Like our apps: iOS & Android) and in general I think it is saver to check for actually features

For the exact query to use I think we should try to make something that will gain us enough to justify dropping certain users to a slower version, or make sure we (almost) don't actually drop anything.

bramkragten avatar Aug 10 '23 09:08 bramkragten

Responding in reverse order...

For the exact query to use I think we should try to make something that will gain us enough to justify dropping certain users to a slower version, or make sure we (almost) don't actually drop anything.

Honestly, I think targeting browsers released in the last year + the usage threshold strikes that balance pretty well. Even though the jump in version numbers in the table above looks big, the number of users affected will be very small. Performance gains I think need to be look at as a cumulative effect of smaller gains because nothing even comes close to the ES5 to ES6 jump, and that's really difficult to prove absent a suite of benchmark tests. Just based on a usage hypothesis though, we're transpiling a bunch of things that nobody needs transpiled.

For contrast I added the ES5 build browser targets to the table above - the dynamic import + Safari test will pass on browsers 4-6 years old. Anecdotally, if anyone was using something close to that split point, they'd be getting errors due to lack of polyfills (and hopefully reporting them). I believe the next step after a PR like this would be to allow Babel to inject core-js polyfills into the modern build as well, which would allow devs to use more recent ECMA features easily and also fix bugs in browser implementations at times. Doing it before a change like this would unnecessarily bloat the build with historical stuff.

I don't really like that we will now test on useragent instead of actual features, ...

Yep, I agree with all that and hate the user agent string as much as the next dev, but playing devil's advocate:

  1. It's really the best we have until the UA client hints API becomes ubiquitous
  2. We already sniff it for several things (and so do dependencies like leaflet and codemirror as you pointed out)

The problem with using only feature detection is that it becomes a much more manual process to maintain. Pick a feature or two, fix the browsers list base on it, write and implement a test, repeat every 6-12 months. And then the results won't make much sense since the vendors don't do anything in sync, i.e. serve modern to 3 year old Chrome, 2 year old Firefox, and 1 year old Safari.

How about a hybrid approach? If you think we can safely assume any spoofing would occur up and not down, then:

  1. Regex test the user agent. If pass, then try test 2, else serve legacy build.
  2. Pick 1 or 2 simple features to test. If pass, serve modern, else serve legacy.

Unless the spoofer minority is actually using a browser in the range between the 2 tests, they'd always get served something that works correctly.

These changes already sort of do that with the import() syntax test, but I think we should pick something more recent like Object.hasOwn from ECMA 2022.

steverep avatar Aug 10 '23 19:08 steverep

Sorry for writing an essay in response 📝 😉

steverep avatar Aug 10 '23 19:08 steverep

Honestly, I think targeting browsers released in the last year + the usage threshold strikes that balance pretty well

Not entirely in agreement from my (humble frontend knowledge) perspective. While it is true that it is covering most of the clients used, we also have to think about common use cases our users have. One of those is using "wall tablets", often, those devices are cheaper bought older models or re-purposed tablets, or just on the wall for a long time already.

Actions like these may significant influence if I'm correct?

../Frenck

frenck avatar Aug 10 '23 20:08 frenck

Actions like these may significant influence if I'm correct?

No, it should be pretty insignificant. Chromium takes a really long time before they start dropping support for an Android version. For example, any device running v7 or later right now can use the latest version of Chrome (and therefore by proxy Android Web View). Even v6 supports up to Chromium 106, so we'd still hand it the modern build for a few more months at least.

In short, the device hardware has to be so old that it's frozen on a 7 year old OS in order to not get the modern build, and that's where the legacy build comes in.

steverep avatar Aug 11 '23 01:08 steverep

I believe the next step after a PR like this would be to allow Babel to inject core-js polyfills into the modern build as well, which would allow devs to use more recent ECMA features easily and also fix bugs in browser implementations at times. Doing it before a change like this would unnecessarily bloat the build with historical stuff.

As an example, I'd like to use URL.canParse() for a change I'm working on, but right now I need to either work around it or import the polyfill manually.

steverep avatar Aug 16 '23 17:08 steverep

@bramkragten what can I do to unblock this one? Are you okay with the hybrid approach and time frame I suggested, or do you really want to not use the user agent string at all?

steverep avatar Sep 28 '23 18:09 steverep

I think that is ok, but what I really think we should do before merging this, is optimise our legacy build. We currently don't focus on performance at all for legacy, and load all the polyfills without checking if they are needed (especially formatjs ones are big) if we are going to steer more users to this version we should do some work on optimising it I feel....

bramkragten avatar Sep 29 '23 09:09 bramkragten

Okay fair enough. I've got a list in my head that includes fixing that stuff plus a few other things.

steverep avatar Oct 04 '23 03:10 steverep

There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. Thank you for your contributions.

github-actions[bot] avatar Apr 07 '24 00:04 github-actions[bot]

Walkthrough

Walkthrough

The recent changes focus on enhancing performance and compatibility across modern and legacy browsers. Key updates include refining browser targeting in .browserslistrc, modifying Babel configurations for decorators, and simplifying script loading in various HTML templates. These improvements aim to leverage modern browser capabilities while maintaining support for older browsers, thus improving the overall user experience and streamlining the codebase.

Changes

Files/Paths Change Summary
.browserslistrc Updated targeting criteria for modern and legacy browsers, optimizing transpilation and polyfill usage.
build-scripts/bundle.cjs Updated Babel options for decorators and added support for class fields and private methods.
build-scripts/gulp/entry-html.js Added import for getUserAgentRegex and modified renderTemplate to include modernRegex.
cast/src/html/... Replaced JavaScript import loops with calls to render script loader templates in faq.html.template, index.html.template, and media.html.template.
demo/src/html/index.html.template Replaced script import logic with a template rendering call for the script loader.
hassio/src/entrypoint.js.template Modified logic for loading ES6 or ES5 modules based on user agent's browser version using modernRegex.
package.json Added dependency: browserslist-useragent-regexp.
src/html/_js_base.html.template Updated browser detection logic to use user agent string and feature detection.
src/html/_script_loader.html.template Introduced conditional script loading based on the useWDS flag and modern browser support.
src/html/authorize.html.template Modified script loading behavior, adding a conditional check for window.latestJS.
src/html/index.html.template Updated script loading logic to verify modern browser support.
src/html/onboarding.html.template Modified script loading to conditionally fetch steps based on window.latestJS and rendered _script_loader.html.template.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Browser
    participant Server
    User->>Browser: Request page
    Browser->>Server: Load HTML template
    Server->>Browser: Serve HTML template
    Browser->>Browser: Check user agent
    alt Modern Browser
        Browser->>Server: Load ES6 modules
    else Legacy Browser
        Browser->>Server: Load ES5 modules
    end
    Browser->>User: Render page
sequenceDiagram
    participant User
    participant Browser
    participant Server
    User->>Browser: Request onboarding
    Browser->>Browser: Check window.latestJS
    alt latestJS is true
        Browser->>Server: Fetch onboarding steps
    else latestJS is false
        Browser->>Server: Load fallback scripts
    end
    Browser->>User: Render onboarding page

Recent review details

Configuration used: CodeRabbit UI Review profile: CHILL

Commits

Files that changed from the base of the PR and between 87280e29d3ce802a2b5969598b6cf3f06135ae0f and f1214e43180f96296dc64e072e5ed84d00e53754.

Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
Files selected for processing (14)
  • .browserslistrc (2 hunks)
  • build-scripts/bundle.cjs (1 hunks)
  • build-scripts/gulp/entry-html.js (2 hunks)
  • cast/src/html/faq.html.template (1 hunks)
  • cast/src/html/index.html.template (1 hunks)
  • cast/src/html/media.html.template (1 hunks)
  • demo/src/html/index.html.template (1 hunks)
  • hassio/src/entrypoint.js.template (2 hunks)
  • package.json (1 hunks)
  • src/html/_js_base.html.template (1 hunks)
  • src/html/_script_loader.html.template (1 hunks)
  • src/html/authorize.html.template (1 hunks)
  • src/html/index.html.template (1 hunks)
  • src/html/onboarding.html.template (1 hunks)
Files skipped from review as they are similar to previous changes (13)
  • .browserslistrc
  • build-scripts/bundle.cjs
  • build-scripts/gulp/entry-html.js
  • cast/src/html/faq.html.template
  • cast/src/html/index.html.template
  • cast/src/html/media.html.template
  • demo/src/html/index.html.template
  • package.json
  • src/html/_js_base.html.template
  • src/html/_script_loader.html.template
  • src/html/authorize.html.template
  • src/html/index.html.template
  • src/html/onboarding.html.template
Additional comments not posted (2)
hassio/src/entrypoint.js.template (2)

Line range hint 7-15: Caution: Use of new Function for dynamic imports.

While using new Function to dynamically import scripts is a clever solution, it can pose security risks and may not be supported in all environments. Ensure this approach is thoroughly tested across all target browsers.

Verification successful

Caution: Use of new Function for dynamic imports.

While using new Function to dynamically import scripts is a clever solution, it can pose security risks and may not be supported in all environments. Ensure this approach is thoroughly tested across all target browsers.

  • No other instances of new Function("import' were found in the codebase.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the compatibility and support of `new Function` for dynamic imports across all target browsers.

# Test: Search for the usage of `new Function` in the codebase. Expect: Only occurances of the new usage.
rg --type js -A 5 $'new Function("import'

Length of output: 126


Script:

#!/bin/bash
# Description: Verify the compatibility and support of `new Function` for dynamic imports across all target browsers.

# Test: Search for the usage of `new Function` in the codebase. Expect: Only occurrences of the new usage.
rg --type js -A 5 'new Function\("import'

Length of output: 43


16-19: LGTM! Ensure ES5 script loading is verified.

The fallback mechanism to load ES5 scripts is well-implemented.

However, ensure that the ES5 scripts are correctly loaded and tested across all target browsers.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

coderabbitai[bot] avatar Jun 27 '24 04:06 coderabbitai[bot]

This should be good now but merge #21177 first. I can follow this up with some minor clean up:

  • Add backup feature detection
  • Don't preload modern entrypoints for legacy
  • Consolidate script tags

steverep avatar Jun 27 '24 12:06 steverep

Adding feature detection was fairly simple so that can be crossed off now.

steverep avatar Jun 27 '24 16:06 steverep

GitHub should have an achievement award for number of conflicts fixed on a single PR...

steverep avatar Jul 19 '24 14:07 steverep