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.
This commit is contained in:
Alan Guo Xiang Tan 2025-04-28 15:50:01 +08:00 committed by GitHub
parent 621e095739
commit 84c8f51c54
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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
)