FIX: Components mobile-specific CSS was missing (#12259)

Fix for: https://meta.discourse.org/t/our-components-stop-working/181580?u=osama.

This fixes an old hidden bug that was exposed in cf0192018e. The bug is that we call the `Stylesheet::Manager.stylesheet_details` method with the `target` arg as `:mobile_theme` when we want to retrieve a theme component's mobile CSS. The problem is that this `target` value will at some point be looked up in the `Theme.targets` enum which doesn't have a `:mobile_theme` key, instead it has `:mobile` key.

This commit adds a step that removes the `_theme` suffix in the `Theme.list_baked_fields` method to fix this problem.
This commit is contained in:
Osama Sayegh 2021-03-02 17:20:43 +03:00 committed by GitHub
parent 31f3563f2d
commit c0e2fdd200
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 0 deletions

View File

@ -356,6 +356,8 @@ class Theme < ActiveRecord::Base
if target == :translations
fields = ThemeField.find_first_locale_fields(theme_ids, I18n.fallbacks[name])
else
target = :mobile if target == :mobile_theme
target = :desktop if target == :desktop_theme
fields = ThemeField.find_by_theme_ids(theme_ids)
.where(target_id: [Theme.targets[target], Theme.targets[:common]])
fields = fields.where(name: name.to_s) unless name.nil?

View File

@ -119,6 +119,17 @@ describe Stylesheet::Manager do
expect(hrefs.count).to eq(3) # theme + child_theme + embedded_scss_child
end
it '.stylesheet_details can find components mobile SCSS when target is `:mobile_theme`' do
child_with_mobile_scss = Fabricate(:theme, component: true)
child_with_mobile_scss.set_field(target: :mobile, name: :scss, value: "body { color: red; }")
child_with_mobile_scss.save!
theme.add_relative_theme!(:child, child_with_mobile_scss)
hrefs = Stylesheet::Manager.stylesheet_details(:mobile_theme, 'all', [theme.id])
expect(hrefs.find { |h| h[:theme_id] == child_with_mobile_scss.id }).to be_present
expect(hrefs.count).to eq(3)
end
it 'does not output multiple assets for non-theme targets' do
hrefs = Stylesheet::Manager.stylesheet_details(:admin, 'all', [theme.id])
expect(hrefs.count).to eq(1)