DEV: Fix live CSS watching when viewing non-default theme

DEV: Fix live CSS watching when viewing non-default theme

State was being stored in a class variable, so was not consistent across processes. This commit moves the storage to redis. The change only affects development environments.

diff --git a/lib/stylesheet/watcher.rb b/lib/stylesheet/watcher.rb
index e2425c4..7d73ec5 100644
--- a/lib/stylesheet/watcher.rb
+++ b/lib/stylesheet/watcher.rb
@@ -2,16 +2,14 @@ require 'listen'
 
 module Stylesheet
   class Watcher
+    REDIS_KEY = "dev_last_used_theme_id"
 
     def self.theme_id=(v)
-      @theme_id = v
+      $redis.set(REDIS_KEY, v)
     end
 
     def self.theme_id
-      if @theme_id.blank? && SiteSetting.default_theme_id != -1
-        @theme_id = SiteSetting.default_theme_id
-      end
-      @theme_id
+      ($redis.get(REDIS_KEY) || SiteSetting.default_theme_id).to_i
     end
 
     def self.watch(paths = nil)

GitHub sha: 16fbbd09

1 Like

This commit has been mentioned on Discourse Meta. There might be relevant details there: