FIX: Memoization in EmberCli ruby helper class (#24139)

Previously we were memoizing based on `defined?`, but the `clear_cache!` method was doing `@blah = nil`. That meant that after the cache was cleared, future calls to the memoized method would return `nil` instead of triggering a recalculation.
This commit is contained in:
David Taylor 2023-10-27 13:35:33 +01:00 committed by GitHub
parent 3f3d2ee2c0
commit 983fd04f4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,11 +6,11 @@ module EmberCli
end end
def self.assets def self.assets
@@assets ||= Dir.glob("**/*.{js,map,txt}", base: "#{dist_dir}/assets") @assets ||= Dir.glob("**/*.{js,map,txt}", base: "#{dist_dir}/assets")
end end
def self.script_chunks def self.script_chunks
return @@chunk_infos if defined?(@@chunk_infos) return @chunk_infos if @chunk_infos
chunk_infos = {} chunk_infos = {}
@ -24,7 +24,7 @@ module EmberCli
index_html = File.read("#{dist_dir}/index.html") index_html = File.read("#{dist_dir}/index.html")
chunk_infos.merge! parse_chunks_from_html(index_html) chunk_infos.merge! parse_chunks_from_html(index_html)
@@chunk_infos = chunk_infos if Rails.env.production? @chunk_infos = chunk_infos if Rails.env.production?
chunk_infos chunk_infos
rescue Errno::ENOENT rescue Errno::ENOENT
{} {}
@ -80,7 +80,7 @@ module EmberCli
end end
def self.clear_cache! def self.clear_cache!
@@chunk_infos = nil @chunk_infos = nil
@@assets = nil @assets = nil
end end
end end