FIX: Invalidate stylesheet cache when discourse-fonts is bumped (#30869)

This commit is contained in:
David Taylor 2025-01-20 12:25:28 +00:00 committed by GitHub
parent 89ff7d51e6
commit 23edfe7cc2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 4 deletions

View File

@ -7,8 +7,12 @@ module Stylesheet
end
class Stylesheet::Manager
# Bump this number to invalidate all stylesheet caches (e.g. if you change something inside the compiler)
BASE_COMPILER_VERSION = 2
# Add any dependencies here which should automatically cause a global cache invalidation.
BASE_CACHE_KEY = "#{BASE_COMPILER_VERSION}::#{DiscourseFonts::VERSION}"
CACHE_PATH = "tmp/stylesheet-cache"
private_constant :CACHE_PATH
@ -132,13 +136,13 @@ class Stylesheet::Manager
if File.exist?(manifest_full_path)
File.readlines(manifest_full_path, "r")[0]
else
cachebuster = "#{BASE_COMPILER_VERSION}:#{fs_assets_hash}"
cachebuster = "#{BASE_CACHE_KEY}:#{fs_assets_hash}"
FileUtils.mkdir_p(MANIFEST_DIR)
File.open(manifest_full_path, "w") { |f| f.print(cachebuster) }
cachebuster
end
else
"#{BASE_COMPILER_VERSION}:#{max_file_mtime}"
"#{BASE_CACHE_KEY}:#{max_file_mtime}"
end
end

View File

@ -1043,7 +1043,7 @@ RSpec.describe Stylesheet::Manager do
describe ".fs_asset_cachebuster" do
it "returns a number in test/development mode" do
expect(Stylesheet::Manager.fs_asset_cachebuster).to match(/\A[0-9]+:[0-9]+\z/)
expect(Stylesheet::Manager.fs_asset_cachebuster).to match(/\A.*:[0-9]+\z/)
end
context "with production mode enabled" do
@ -1056,7 +1056,7 @@ RSpec.describe Stylesheet::Manager do
it "returns a hash" do
cachebuster = Stylesheet::Manager.fs_asset_cachebuster
expect(cachebuster).to match(/\A[0-9]+:[0-9a-f]{40}\z/)
expect(cachebuster).to match(/\A.*:[0-9a-f]{40}\z/)
end
it "caches the value on the filesystem" do