Skip to content

Remove custom compressor wrappers when replacing or disabling compression - #849

Closed
OskarEichler wants to merge 1 commit into
rails:mainfrom
OskarEichler:codex/compressor-removal
Closed

Remove custom compressor wrappers when replacing or disabling compression#849
OskarEichler wants to merge 1 commit into
rails:mainfrom
OskarEichler:codex/compressor-removal

Conversation

@OskarEichler

Copy link
Copy Markdown

Summary

Assigning nil to js_compressor or css_compressor disables the current compressor, including objects implementing compress. Assigning another compressor replaces the previous one.

Remember the actual registered processor separately from the existing public compressor reader value. A compress object is wrapped in a Proc, but removal previously used the reader symbol instead of that Proc. Existing reader values are preserved. Checks cover object-to-object, object-to-callable/class/symbol, nil, repeated nil, JS/CSS, processor counts and preservation of other processors. The reproduction clears the asset cache to isolate registration behavior; this does not solve arbitrary custom processor cache-key configuration.

Reproduction

With require "sprockets"; require "tmpdir":

Dir.mktmpdir do |dir|
  File.write(File.join(dir, "entry.js"), "var value=1;")
  env = Sprockets::Environment.new(dir); env.append_path(dir)
  compressor = Object.new
  def compressor.compress(data); data + "/*CUSTOM*/"; end
  env.js_compressor = compressor
  env.js_compressor = nil
  env.cache.clear
  p env["entry.js"].to_s.include?("CUSTOM")
  # false; previously true. CSS and replacing the compressor have the same defect.
end

Verification

  • Isolated patch: unchanged bundle exec rake test and bundle exec rake test_isolated each pass 913 tests / 4,109 assertions / zero failures/errors / four skips, on Ruby 3.2.11 and 4.0.6 with Rack 3.2.7.
  • 196 focused external checks pass on each Ruby. Baseline reproduces the defect. All Ruby commands used rbenv.
  • Full RuboCop: 133 files, zero offenses. Changed Ruby files pass syntax checks on both Rubies; git diff --check passes.
  • Gem build and content comparison preserve all 84 package paths, version 4.4.1, Ruby >=2.5 and dependency metadata. Only README, CHANGELOG and the relevant runtime files differ.

Compatibility and limitations

Breaking changes: no intended change to valid supported behavior; the incorrect behavior described above changes. No new dependencies or version upgrades. Nested configuration ownership, unrelated cache invalidation and HTTP behavior are outside this focused patch.

Based on installed release/current upstream main 49d9f20c00ac7d9a7ee57db058961edcccd86699. This is an upstream-only contribution; no personal fork is being adopted in the application. Older Ruby/Linux/JRuby verification is left to upstream CI, not claimed locally. No checked-in tests were added or edited under the requesting repository's no-test-edit policy; focused reproductions ran externally. Prepared with AI assistance. This does not claim exhaustive Sprockets coverage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants