Skip to content

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

FIX: Do not `@import` `.css` assets for plugins (#32014)

David Taylor042c48004945
diff --git a/lib/stylesheet/compiler.rb b/lib/stylesheet/compiler.rb
index 8b494b2d7c3..5034f6a501e 100644
--- a/lib/stylesheet/compiler.rb
+++ b/lib/stylesheet/compiler.rb
@@ -24,7 +24,11 @@ module Stylesheet
plugin_assets.each do |src|
options[:load_paths] << File.expand_path(File.dirname(src))
- file += "@import \"#{src}\";\n"
+ if src.end_with?(".scss")
+ file += "@import \"#{src}\";\n"
+ else
+ file += File.read(src)
+ end
end
else # Core asset
file += "@import \"#{asset}\";\n"
diff --git a/lib/stylesheet/manager.rb b/lib/stylesheet/manager.rb
index b0fd5b1059b..5b5c132a50b 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 = 4
+ BASE_COMPILER_VERSION = 5
# Add any dependencies here which should automatically cause a global cache invalidation.
BASE_CACHE_KEY = "#{BASE_COMPILER_VERSION}::#{DiscourseFonts::VERSION}"
diff --git a/spec/fixtures/plugins/scss_plugin/assets/stylesheets/simple.css b/spec/fixtures/plugins/scss_plugin/assets/stylesheets/simple.css
new file mode 100644
index 00000000000..e8cd7dd3c6c
--- /dev/null
+++ b/spec/fixtures/plugins/scss_plugin/assets/stylesheets/simple.css
@@ -0,0 +1,3 @@
+body {
+ --simple-css-color: red;
+}
\ No newline at end of file
diff --git a/spec/fixtures/plugins/scss_plugin/plugin.rb b/spec/fixtures/plugins/scss_plugin/plugin.rb
index 1a5845193b0..a9b6fd87218 100644
--- a/spec/fixtures/plugins/scss_plugin/plugin.rb
+++ b/spec/fixtures/plugins/scss_plugin/plugin.rb
@@ -5,3 +5,4 @@
# version: 1.0
register_asset "stylesheets/common/common.scss"
+register_asset "stylesheets/simple.css"
diff --git a/spec/lib/stylesheet/compiler_spec.rb b/spec/lib/stylesheet/compiler_spec.rb
index aeb517404f9..8db671f152f 100644
--- a/spec/lib/stylesheet/compiler_spec.rb
+++ b/spec/lib/stylesheet/compiler_spec.rb
@@ -110,6 +110,7 @@ RSpec.describe Stylesheet::Compiler do
expect(css).to include("fill:green")
expect(css).to include("line-height:1.2em")
expect(css).to include("border-color:#c00")
+ expect(css).to include("--simple-css-color: red")
end
end
end