mirror of
https://github.com/discourse/discourse.git
synced 2025-01-19 03:12:46 +08:00
FIX: Use fresh theme setting values when compiling stylesheets
If a theme is updated to introduce a new setting AND immediately make use of it in a stylesheet, then an error was being shown. This is because the stylesheet compilation was using the theme's cached settings, and the cache is only cleared **after** the theme has finished compiling.
This commit updates the SCSS compilation to use uncached values for settings. A similar fix was applied to other parts of theme compilation back in 2020: (a51b8d9c66
)
This commit is contained in:
parent
51afa579f7
commit
c8d956374d
|
@ -155,7 +155,7 @@ class Theme < ActiveRecord::Base
|
||||||
SvgSprite.expire_cache
|
SvgSprite.expire_cache
|
||||||
end
|
end
|
||||||
|
|
||||||
BASE_COMPILER_VERSION = 54
|
BASE_COMPILER_VERSION = 55
|
||||||
def self.compiler_version
|
def self.compiler_version
|
||||||
get_set_cache "compiler_version" do
|
get_set_cache "compiler_version" do
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
@ -563,10 +563,10 @@ class Theme < ActiveRecord::Base
|
||||||
hash = {}
|
hash = {}
|
||||||
|
|
||||||
Theme.where(id: Theme.transform_ids(id)).each do |theme|
|
Theme.where(id: Theme.transform_ids(id)).each do |theme|
|
||||||
hash.merge!(theme.cached_settings)
|
hash.merge!(theme.build_settings_hash)
|
||||||
end
|
end
|
||||||
|
|
||||||
hash.merge!(self.cached_settings)
|
hash.merge!(self.build_settings_hash)
|
||||||
hash
|
hash
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -341,6 +341,18 @@ HTML
|
||||||
expect(scss).to include('font-size:"#{$fakeinterpolatedvariable}\a andanothervalue \'withquotes\'; margin: 0;\a"')
|
expect(scss).to include('font-size:"#{$fakeinterpolatedvariable}\a andanothervalue \'withquotes\'; margin: 0;\a"')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "can use a setting straight away after introducing it" do
|
||||||
|
theme.set_field(target: :common, name: :scss, value: 'body {background-color: red;}')
|
||||||
|
theme.save!
|
||||||
|
|
||||||
|
theme.reload
|
||||||
|
theme.set_field(target: :settings, name: :yaml, value: "background_color: red\nfont_size: 25px")
|
||||||
|
theme.set_field(target: :common, name: :scss, value: 'body {background-color: $background_color;}')
|
||||||
|
theme.save!
|
||||||
|
|
||||||
|
expect(theme.theme_fields.find_by(target_id: Theme.targets[:common], name: "scss").error).to eq(nil)
|
||||||
|
end
|
||||||
|
|
||||||
it "allows values to be used in JS" do
|
it "allows values to be used in JS" do
|
||||||
theme.name = 'awesome theme"'
|
theme.name = 'awesome theme"'
|
||||||
theme.set_field(target: :settings, name: :yaml, value: "name: bob")
|
theme.set_field(target: :settings, name: :yaml, value: "name: bob")
|
||||||
|
@ -440,6 +452,10 @@ HTML
|
||||||
end
|
end
|
||||||
|
|
||||||
def cached_settings(id)
|
def cached_settings(id)
|
||||||
|
Theme.find_by(id: id).cached_settings.to_json
|
||||||
|
end
|
||||||
|
|
||||||
|
def included_settings(id)
|
||||||
Theme.find_by(id: id).included_settings.to_json
|
Theme.find_by(id: id).included_settings.to_json
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -549,32 +565,32 @@ HTML
|
||||||
expect(json["my_upload"]).to eq("http://cdn.localhost#{upload.url}")
|
expect(json["my_upload"]).to eq("http://cdn.localhost#{upload.url}")
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'handles settings cache correctly' do
|
it 'handles child settings correctly' do
|
||||||
Theme.destroy_all
|
Theme.destroy_all
|
||||||
|
|
||||||
expect(cached_settings(theme.id)).to eq("{}")
|
expect(included_settings(theme.id)).to eq("{}")
|
||||||
|
|
||||||
theme.set_field(target: :settings, name: "yaml", value: "boolean_setting: true")
|
theme.set_field(target: :settings, name: "yaml", value: "boolean_setting: true")
|
||||||
theme.save!
|
theme.save!
|
||||||
expect(cached_settings(theme.id)).to match(/\"boolean_setting\":true/)
|
expect(included_settings(theme.id)).to match(/\"boolean_setting\":true/)
|
||||||
|
|
||||||
theme.settings.first.value = "false"
|
theme.settings.first.value = "false"
|
||||||
theme.save!
|
theme.save!
|
||||||
expect(cached_settings(theme.id)).to match(/\"boolean_setting\":false/)
|
expect(included_settings(theme.id)).to match(/\"boolean_setting\":false/)
|
||||||
|
|
||||||
child.set_field(target: :settings, name: "yaml", value: "integer_setting: 54")
|
child.set_field(target: :settings, name: "yaml", value: "integer_setting: 54")
|
||||||
|
|
||||||
child.save!
|
child.save!
|
||||||
theme.add_relative_theme!(:child, child)
|
theme.add_relative_theme!(:child, child)
|
||||||
|
|
||||||
json = cached_settings(theme.id)
|
json = included_settings(theme.id)
|
||||||
expect(json).to match(/\"boolean_setting\":false/)
|
expect(json).to match(/\"boolean_setting\":false/)
|
||||||
expect(json).to match(/\"integer_setting\":54/)
|
expect(json).to match(/\"integer_setting\":54/)
|
||||||
|
|
||||||
expect(cached_settings(child.id)).to eq("{\"integer_setting\":54}")
|
expect(included_settings(child.id)).to eq("{\"integer_setting\":54}")
|
||||||
|
|
||||||
child.destroy!
|
child.destroy!
|
||||||
json = cached_settings(theme.id)
|
json = included_settings(theme.id)
|
||||||
expect(json).not_to match(/\"integer_setting\":54/)
|
expect(json).not_to match(/\"integer_setting\":54/)
|
||||||
expect(json).to match(/\"boolean_setting\":false/)
|
expect(json).to match(/\"boolean_setting\":false/)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user