Skip to content

A platform for community discussion. Free, open, simple.

FIX: Support `light-dark` on older browsers (#34438)

David Taylorb12f153a9e1d
diff --git a/app/assets/javascripts/theme-transpiler/package.json b/app/assets/javascripts/theme-transpiler/package.json
index 4cf977eaa8f..0b7dfdb83e6 100644
--- a/app/assets/javascripts/theme-transpiler/package.json
+++ b/app/assets/javascripts/theme-transpiler/package.json
@@ -35,6 +35,7 @@
"postcss": "^8.5.6",
"postcss-js": "^4.0.1",
"postcss-media-minmax": "^5.0.0",
+ "postcss-nesting": "^13.0.2",
"readable-stream": "^4.7.0",
"source-map-js": "^1.2.1",
"terser": "^5.43.1"
diff --git a/app/assets/javascripts/theme-transpiler/postcss.js b/app/assets/javascripts/theme-transpiler/postcss.js
index 42c6780fb77..bd7483a1d71 100644
--- a/app/assets/javascripts/theme-transpiler/postcss.js
+++ b/app/assets/javascripts/theme-transpiler/postcss.js
@@ -3,6 +3,7 @@ import postcssLightDark from "@csstools/postcss-light-dark-function";
import autoprefixer from "autoprefixer";
import postcss from "postcss";
import minmax from "postcss-media-minmax";
+import postcssNesting from "postcss-nesting";
import { browsers } from "../discourse/config/targets";
import postcssVariablePrefixer from "./postcss-variable-prefixer";
@@ -12,6 +13,7 @@ const postCssProcessor = postcss([
}),
minmax(),
postcssLightDark,
+ postcssNesting, // Un-nests the native css nesting from postcssLightDark
postcssVariablePrefixer(),
]);
let lastPostcssError, lastPostcssResult;
diff --git a/lib/stylesheet/manager.rb b/lib/stylesheet/manager.rb
index 0e155417b23..41ad57d621d 100644
--- a/lib/stylesheet/manager.rb
+++ b/lib/stylesheet/manager.rb
@@ -8,7 +8,7 @@ end
class Stylesheet::Manager
# Bump this number to invalidate all stylesheet caches (e.g. if you change something inside the compiler)
- BASE_COMPILER_VERSION = 5
+ BASE_COMPILER_VERSION = 6
# Add any dependencies here which should automatically cause a global cache invalidation.
BASE_CACHE_KEY = "#{BASE_COMPILER_VERSION}::#{DiscourseFonts::VERSION}"
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 3e72cf68719..700b8a16339 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -1105,6 +1105,9 @@ importers:
postcss-media-minmax:
specifier: ^5.0.0
version: 5.0.0([email protected])
+ postcss-nesting:
+ specifier: ^13.0.2
+ version: 13.0.2([email protected])
readable-stream:
specifier: ^4.7.0
version: 4.7.0
@@ -1847,6 +1850,12 @@ packages:
peerDependencies:
postcss: ^8.4
+ '@csstools/[email protected]':
+ resolution: {integrity: sha512-mf1LEW0tJLKfWyvn5KdDrhpxHyuxpbNwTIwOYLIvsTffeyOf85j5oIzfG0yosxDgx/sswlqBnESYUcQH0vgZ0g==}
+ engines: {node: '>=18'}
+ peerDependencies:
+ postcss-selector-parser: ^7.0.0
+
'@csstools/[email protected]':
resolution: {integrity: sha512-PCqQV3c4CoVm3kdPhyeZ07VmBRdH2EpMFA/pd9OASpOEC3aXNGoqPDAZ80D0cLpMBxnmk0+yNhGsEx31hq7Gtw==}
engines: {node: '>=18'}
@@ -7480,6 +7489,12 @@ packages:
peerDependencies:
postcss: ^8.1.0
+ resolution: {integrity: sha512-1YCI290TX+VP0U/K/aFxzHzQWHWURL+CtHMSbex1lCdpXD1SoR2sYuxDu5aNI9lPoXpKTCggFZiDJbwylU0LEQ==}
+ engines: {node: '>=18'}
+ peerDependencies:
+ postcss: ^8.4
+
resolution: {integrity: sha512-0sglIs9Wmkzbr8lQwEyIzlDOOC9bGmfVKcJTaxv3vMmd3uo4o4DerC3En0bnmgceeql9BfC8hRkp7cg0fjdVqw==}
@@ -10943,6 +10958,10 @@ snapshots:
postcss: 8.5.6
postcss-value-parser: 4.2.0
+ dependencies:
+ postcss-selector-parser: 7.1.0
+
dependencies:
postcss-selector-parser: 7.1.0
@@ -17967,6 +17986,13 @@ snapshots:
icss-utils: 5.1.0([email protected])
postcss: 8.5.6
+ dependencies:
+ '@csstools/selector-resolve-nested': 3.1.0([email protected])
+ '@csstools/selector-specificity': 5.0.0([email protected])
+ postcss: 8.5.6
+ postcss-selector-parser: 7.1.0
+
diff --git a/spec/lib/stylesheet/compiler_spec.rb b/spec/lib/stylesheet/compiler_spec.rb
index d244b58f2eb..8aab295ce62 100644
--- a/spec/lib/stylesheet/compiler_spec.rb
+++ b/spec/lib/stylesheet/compiler_spec.rb
@@ -245,6 +245,7 @@ RSpec.describe Stylesheet::Compiler do
SCSS
expect(css).to include("csstools-light-dark-toggle")
+ expect(css).not_to include("& * {") # No native nesting
expect(map.size).to be > 10
end