A platform for community discussion. Free, open, simple.
DEV: Update browser feature-detection and remove Safari 15 workaround (#34419)
David Taylorf84e391ea6a2
diff --git a/README.md b/README.mdindex 7c78869e8c9..72cecd3007f 100644--- a/README.md+++ b/README.md@@ -64,7 +64,7 @@ Discourse supports the **latest, stable releases** of all major browsers and pla| Microsoft Edge | | || Mozilla Firefox | | |-Additionally, we aim to support Safari on iOS 15.7+.+Additionally, we aim to support Safari on iOS 16.4+.## Built Withdiff --git a/app/assets/javascripts/discourse/app/instance-initializers/safari-15-deprecation.js b/app/assets/javascripts/discourse/app/instance-initializers/safari-15-deprecation.jsdeleted file mode 100644index 5b8fd1f3764..00000000000--- a/app/assets/javascripts/discourse/app/instance-initializers/safari-15-deprecation.js+++ /dev/null@@ -1,35 +0,0 @@-import { apiInitializer } from "discourse/lib/api";-import { i18n } from "discourse-i18n";--function supportsLookbehind() {- try {- return new RegExp("(?<=a)b").test("ab");- } catch {- return false;- }-}--// We're expecting to catch Safari < 16 here, but using feature detection-// instead of user-agent parsing, so that we also warn any other browsers missing-// these features.-const checks = {- relativeColor: CSS.supports("(color: hsl(from white h s l))"),- subgrid: CSS.supports("(grid-template-rows: subgrid)"),- lookbehindRegex: supportsLookbehind(),-};--export default apiInitializer((api) => {- if (!Object.values(checks).every(Boolean)) {- // eslint-disable-next-line no-console- console.error("Feature detection result", checks);- api.addGlobalNotice(- i18n("safari_15_warning", { url: "https://meta.discourse.org/t/358131" }),- "browser-deprecation-warning",- {- dismissable: true,- level: "warn",- dismissDuration: moment.duration(1, "week"),- }- );- }-});diff --git a/app/assets/javascripts/discourse/config/targets.js b/app/assets/javascripts/discourse/config/targets.jsindex 09210acbf6b..4bd54d4554f 100644--- a/app/assets/javascripts/discourse/config/targets.js+++ b/app/assets/javascripts/discourse/config/targets.js@@ -7,10 +7,11 @@ const browsers = ["last 1 Chrome versions","last 1 Firefox versions","last 1 Safari versions",+ "Safari 16.4",];if (isCI || isProduction) {- browsers.push("Safari 15");+ // Add older browsers here if needed}module.exports = {diff --git a/app/assets/javascripts/discourse/ember-cli-build.js b/app/assets/javascripts/discourse/ember-cli-build.jsindex a037c93c114..a509dae59e7 100644--- a/app/assets/javascripts/discourse/ember-cli-build.js+++ b/app/assets/javascripts/discourse/ember-cli-build.js@@ -135,14 +135,6 @@ module.exports = function (defaults) {minimizer: [new TerserPlugin({minify: TerserPlugin.swcMinify,- terserOptions: {- compress: {- // Stop swc unwrapping 'unnecessary' IIFE wrappers which are added by Babel- // to workaround a bug in Safari 15 class fields.- inline: false,- reduce_funcs: false,- },- },}),],},diff --git a/app/assets/javascripts/discourse/scripts/browser-detect.js b/app/assets/javascripts/discourse/scripts/browser-detect.jsindex 90e4d9605a8..292e7080f53 100644--- a/app/assets/javascripts/discourse/scripts/browser-detect.js+++ b/app/assets/javascripts/discourse/scripts/browser-detect.js@@ -1,13 +1,22 @@/* eslint-disable no-var */ // `let` is not supported in very old browsers(function () {+ function check(name, passed) {+ if (!passed) {+ // eslint-disable-next-line no-console+ console.warn(name + " is not supported");+ }+ return passed;+ }if (- !window.WeakMap ||- !window.Promise ||- typeof globalThis === "undefined" ||- !String.prototype.replaceAll ||- !CSS.supports ||- !CSS.supports("aspect-ratio: 1")+ !check("weakMap", window.WeakMap) ||+ !check("promise", window.Promise) ||+ !check("globalThis", typeof globalThis !== "undefined") ||+ !check("replaceAll", String.prototype.replaceAll) ||+ !check("supports", CSS.supports) ||+ !check("aspectRatio", CSS.supports("aspect-ratio: 1")) ||+ !check("relativeColor", CSS.supports("(color: hsl(from white h s l))")) ||+ !check("subgrid", CSS.supports("(grid-template-rows: subgrid)"))) {window.unsupportedBrowser = true;} else {diff --git a/spec/lib/discourse_js_processor_spec.rb b/spec/lib/discourse_js_processor_spec.rbindex 3d82e51606c..f3b70f3630d 100644--- a/spec/lib/discourse_js_processor_spec.rb+++ b/spec/lib/discourse_js_processor_spec.rb@@ -75,7 +75,7 @@ RSpec.describe DiscourseJsProcessor doJSresult = DiscourseJsProcessor.transpile(script, "blah", "blah/mymodule")- expect(result).to include("static #_ = (() => dt7948.n")+ expect(result).to include("dt7948.n(")enddescribe "Transpiler#terser" do@@ -151,7 +151,7 @@ RSpec.describe DiscourseJsProcessor do{ "discourse/initializers/foo.js" => script },{},)- expect(result["code"]).to include("() => dt7948.n")+ expect(result["code"]).to include("dt7948.n")endit "supports object literal decorators without errors" dodiff --git a/spec/lib/stylesheet/compiler_spec.rb b/spec/lib/stylesheet/compiler_spec.rbindex 018d77071ac..d244b58f2eb 100644--- a/spec/lib/stylesheet/compiler_spec.rb+++ b/spec/lib/stylesheet/compiler_spec.rb@@ -244,7 +244,6 @@ RSpec.describe Stylesheet::Compiler do}SCSS- expect(css).to include("-webkit-min-device-pixel-ratio")expect(css).to include("csstools-light-dark-toggle")expect(map.size).to be > 10enddiff --git a/spec/lib/theme_javascript_compiler_spec.rb b/spec/lib/theme_javascript_compiler_spec.rbindex 6000cbd394d..1e8c12d523e 100644--- a/spec/lib/theme_javascript_compiler_spec.rb+++ b/spec/lib/theme_javascript_compiler_spec.rb@@ -255,18 +255,4 @@ RSpec.describe ThemeJavascriptCompiler doexpect(compiler.content).to include("createTemplateFactory")endend-- describe "safari <16 class field bugfix" do- it "is applied" do- compiler.append_tree({ "discourse/components/my-component.js" => <<~JS })- export default class MyComponent extends Component {- value = "foo";- complexValue = this.value + "bar";- }- JS-- expect(compiler.content).to include('value = "foo";')- expect(compiler.content).to include('complexValue = (() => this.value + "bar")();')- end- endenddiff --git a/themes/horizon/common/head_tag.html b/themes/horizon/common/head_tag.htmldeleted file mode 100644index 2e776cb7e31..00000000000--- a/themes/horizon/common/head_tag.html+++ /dev/null@@ -1,7 +0,0 @@-<script>- if (!CSS.supports("(color: hsl(from white h s l))")) {- window.unsupportedBrowser = true;- window.I18n.translations[I18n.locale].js.browser_update =- 'The Horizon theme does not support your browser. Please update your browser, or <a href="?safe_mode=no_themes">switch to safe mode</a>.';- }-</script>