Skip to content

Rails 4.0 patterns: correct JS-compressor fix, revert ASSETS_COMPRESS over-specification#106

Open
JuanVqz wants to merge 3 commits into
mainfrom
feature/rails-40-patterns-pr5
Open

Rails 4.0 patterns: correct JS-compressor fix, revert ASSETS_COMPRESS over-specification#106
JuanVqz wants to merge 3 commits into
mainfrom
feature/rails-40-patterns-pr5

Conversation

@JuanVqz

@JuanVqz JuanVqz commented May 26, 2026

Copy link
Copy Markdown
Member

Summary

I was unsure if adding this as PR, because the usage of terser seems too specific, but then I thought there might be more apps using it in Rails 3.2, and it is better if we got a reference on how we solved it one time.

But I'm open to your opinions on whether we should keep them or not.

@JuanVqz JuanVqz self-assigned this May 26, 2026
@JuanVqz JuanVqz requested review from etagwerker and removed request for etagwerker May 26, 2026 15:02
@JuanVqz JuanVqz changed the title Rails 4.0 patterns: assets/Sprockets (JS compressor mismatch + Form-2 caveat) Rails 4.0 patterns: correct JS-compressor fix, revert ASSETS_COMPRESS over-specification May 27, 2026
@JuanVqz JuanVqz requested review from arielj and etagwerker May 27, 2026 21:13
@JuanVqz JuanVqz marked this pull request as ready for review May 27, 2026 21:14
JuanVqz added 3 commits July 3, 2026 20:42
The previous fix said simply "Replace with config.assets.js_compressor
= :uglifier and config.assets.css_compressor = :sass." That advice
silently fails on dual-boot setups where the next? and !next?
bundles ship different JS-compressor gems.

The :uglifier / :terser / :sass symbol values are resolved against
the actual gem at boot. If terser is in the current bundle and
uglifier is in the next bundle, an unconditional
`config.assets.js_compressor = :uglifier` raises
NameError: uninitialized constant Uglifier on the side that lacks
the gem.

Updated explanation calls out the symbol-vs-gem dependency directly.
Updated fix adds the rule of thumb: unconditional symbol assignment
is safe only when the named compressor gem is present in BOTH
bundles. When the Gemfile gates the gem, gate the symbol assignment
too with NextRails.next?.

Example included in the fix so operators recognize the safe shape:

  config.assets.js_compressor = NextRails.next? ? :uglifier : :terser

Same priority and kind — high_priority, breaking.
Modern JS-compressor gems (terser, recent uglifier lines,
closure-compiler builds) declare a runtime dependency on
sprockets/digest_utils, which lives in Sprockets >= 4. Rails 4.x
and 5.x lock Sprockets to the 2.x / 3.x line via sprockets-rails
constraints.

The next bundle resolves cleanly — gemspec passes railsbump's
dependency check — but loading the gem at boot raises:

  LoadError: cannot load such file -- sprockets/digest_utils

This is a class of gem-compat issue invisible to railsbump because
bundle install succeeds against the gemspec; the failure happens
at require-time, after the bundle is locked. Catalog the pattern
so operators recognize the LoadError stack trace immediately
during a Workflow 06 Step 12 boot smoke or a Workflow 09
test-suite run.

Detection: regex matches `gem "terser"` and `gem "closure-compiler"`
in the Gemfile explicitly. For uglifier the breaking versions are
4.x+; a hit on a bare `gem "uglifier"` needs a version-pin check,
called out in the explanation.

Fix: gate the gem in the Gemfile so the next side gets a
Rails-4-era equivalent (`gem "uglifier", ">= 1.3.0"`) while the
current side keeps the modern gem. Pair with the ASSETS_COMPRESS
pattern's gated symbol assignment so the :uglifier symbol resolves
on the next side and terser's auto-registration handles the
current side.

Classified high_priority / kind: breaking — boot-fatal at gem
require time on the next side.
- JS_COMPRESSOR_GEM_MISMATCH: previous fix swapped terser for uglifier on
  the next side, which discards the modern-JS assets terser was added for.
  Rewrite to the real recipe (terser require:false + uglifier symbol shim +
  runtime rake swap) and move the full writeup to a reference file. Trim the
  cross-version boundary text; this is the 4.0 file.
- ASSETS_COMPRESS: revert to the plain documented fix. The Form-2/NameError
  dual-boot caveat was engagement-specific and misleading for general users.
- Add references/js-compressor-sprockets-dual-boot.md.
@etagwerker etagwerker force-pushed the feature/rails-40-patterns-pr5 branch from 4ba8894 to 577d262 Compare July 4, 2026 00:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant