Skip to content

Commit

Permalink
FIX: Recompile theme translations when fallback data changes (#24371)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
davidtaylorhq committed Nov 14, 2023
1 parent 69a70f8 commit eda7918
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/theme.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class Theme < ActiveRecord::Base
include GlobalPath

BASE_COMPILER_VERSION = 77
BASE_COMPILER_VERSION = 78

class SettingsMigrationError < StandardError
end
Expand Down
2 changes: 2 additions & 0 deletions app/models/theme_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,8 @@ def dependent_fields
name: ThemeField.scss_fields + ThemeField.html_fields,
)
)
elsif translation_field?
return theme.theme_fields.where(target_id: Theme.targets[:translations])
end
ThemeField.none
end
Expand Down
51 changes: 51 additions & 0 deletions spec/models/theme_field_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,57 @@ def create_yaml_field(value)
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
Expand Down

0 comments on commit eda7918

Please sign in to comment.