FIX: Recompile theme translations when fallback data changes (#24371)

Previously we would only recompile a theme locale when its own data changes. However, the output also includes fallback data from other locales, so we need to invalidate all locales when fallback locale data is changed. Building a list of dependent locales is tricky, so let's just invalidate them all.
This commit is contained in:
David Taylor 2023-11-14 19:53:27 +00:00 committed by GitHub
parent 69a70f8159
commit eda79186ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 54 additions and 1 deletions

View File

@ -6,7 +6,7 @@ require "json_schemer"
class Theme < ActiveRecord::Base
include GlobalPath
BASE_COMPILER_VERSION = 77
BASE_COMPILER_VERSION = 78
class SettingsMigrationError < StandardError
end

View File

@ -664,6 +664,8 @@ class ThemeField < ActiveRecord::Base
name: ThemeField.scss_fields + ThemeField.html_fields,
)
)
elsif translation_field?
return theme.theme_fields.where(target_id: Theme.targets[:translations])
end
ThemeField.none
end

View File

@ -595,6 +595,57 @@ HTML
expect(fr1.javascript_cache.content).to include("helloworld")
expect(fr1.javascript_cache.content).to include("enval1")
end
it "is recreated when data changes" do
t = Fabricate(:theme)
t.set_field(
target: "translations",
name: "fr",
value: { fr: { mykey: "initial value" } }.deep_stringify_keys.to_yaml,
)
t.save!
field = t.theme_fields.find_by(target_id: Theme.targets[:translations], name: "fr")
expect(field.javascript_cache.content).to include("initial value")
t.set_field(
target: "translations",
name: "fr",
value: { fr: { mykey: "new value" } }.deep_stringify_keys.to_yaml,
)
t.save!
field = t.theme_fields.find_by(target_id: Theme.targets[:translations], name: "fr")
expect(field.javascript_cache.reload.content).to include("new value")
end
it "is recreated when fallback data changes" do
t = Fabricate(:theme)
t.set_field(
target: "translations",
name: "fr",
value: { fr: {} }.deep_stringify_keys.to_yaml,
)
t.set_field(
target: "translations",
name: "en",
value: { en: { myotherkey: "initial value" } }.deep_stringify_keys.to_yaml,
)
t.save!
field = t.theme_fields.find_by(target_id: Theme.targets[:translations], name: "fr")
expect(field.javascript_cache.content).to include("initial value")
t.set_field(
target: "translations",
name: "en",
value: { en: { myotherkey: "new value" } }.deep_stringify_keys.to_yaml,
)
t.save!
field = t.theme_fields.find_by(target_id: Theme.targets[:translations], name: "fr")
expect(field.javascript_cache.reload.content).to include("new value")
end
end
describe "prefix injection" do