From 84c8f51c54934fcd5a3588ad177fdb706eaa02ed Mon Sep 17 00:00:00 2001 From: Alan Guo Xiang Tan Date: Mon, 28 Apr 2025 15:50:01 +0800 Subject: [PATCH] DEV: Account for relative url root in `Stylesheet::Manager` cache keys (#32487) This is mainly used for the test environment where `Discourse.current_hostname` and `GlobalSetting.relative_url_root` can be stubbed. ### Reviewer notes We don't really need a test here since this doesn't really affect the production environment. --- lib/stylesheet/manager.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/stylesheet/manager.rb b/lib/stylesheet/manager.rb index 5b5c132a50b..a876f1317b5 100644 --- a/lib/stylesheet/manager.rb +++ b/lib/stylesheet/manager.rb @@ -46,7 +46,7 @@ class Stylesheet::Manager color_scheme_name = Slug.for(color_scheme.name) + color_scheme&.id.to_s theme_string = theme_id ? "_theme#{theme_id}" : "" dark_string = dark ? "_dark" : "" - "#{COLOR_SCHEME_STYLESHEET}_#{color_scheme_name}_#{theme_string}_#{Discourse.current_hostname}#{dark_string}" + "#{COLOR_SCHEME_STYLESHEET}_#{color_scheme_name}_#{theme_string}_#{Discourse.current_hostname}_#{GlobalSetting.relative_url_root}_#{dark_string}" end def self.precompile_css @@ -285,14 +285,15 @@ class Stylesheet::Manager def stylesheet_details(target = :desktop, media = "all") target = target.to_sym current_hostname = Discourse.current_hostname + relative_url_root = GlobalSetting.relative_url_root is_theme_target = !!(target.to_s =~ THEME_REGEX) array_cache_key = ( if is_theme_target - "array_themes_#{@theme_ids.join(",")}_#{target}_#{current_hostname}" + "array_themes_#{@theme_ids.join(",")}_#{target}_#{current_hostname}_#{relative_url_root}" else - "array_#{target}_#{current_hostname}" + "array_#{target}_#{current_hostname}_#{relative_url_root}" end )