Skip to content

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

FIX: Load base color scheme when default theme is not set

Penar Musaraj266c0c50d731
diff --git a/lib/stylesheet/manager.rb b/lib/stylesheet/manager.rb
index fbdf89df8c6..819c4bc33f5 100644
--- a/lib/stylesheet/manager.rb
+++ b/lib/stylesheet/manager.rb
@@ -97,7 +97,7 @@ class Stylesheet::Manager
color_scheme = begin
ColorScheme.find(color_scheme_id)
rescue
- Theme.find(SiteSetting.default_theme_id).color_scheme || ColorScheme.base
+ Theme.find_by_id(SiteSetting.default_theme_id)&.color_scheme || ColorScheme.base
end
target = COLOR_SCHEME_STYLESHEET.to_sym
diff --git a/spec/components/stylesheet/manager_spec.rb b/spec/components/stylesheet/manager_spec.rb
index f99a403571c..692b7287a25 100644
--- a/spec/components/stylesheet/manager_spec.rb
+++ b/spec/components/stylesheet/manager_spec.rb
@@ -171,6 +171,12 @@ describe Stylesheet::Manager do
expect(link).not_to eq("")
end
+ it "does not crash when no default theme is set" do
+ SiteSetting.default_theme_id = -1
+ link = Stylesheet::Manager.color_scheme_stylesheet_link_tag()
+ expect(link).not_to eq("")
+ end
+
it "does not crash on missing color scheme" do
link = Stylesheet::Manager.color_scheme_stylesheet_link_tag(125)
expect(link).not_to eq("")