ndbroadbent / turbo-sprockets-rails3

Speeds up your Rails 3 assets:precompile by only recompiling changed files, and only compiling once to generate all assets
MIT License
974 stars 76 forks source link

Unhandled CircularDependencyError with ActiveScaffold and jquery-ui-rails #85

Open jcrate opened 10 years ago

jcrate commented 10 years ago

In my Rails 3.2.x project that includes both active_scaffold and jquery-ui-rails gems, a CircularDependencyError is thrown when compiling asses with turbo-sprockets-rails3, while assets are compiled successfully without turbo-sprockets-rails3. This is reproducible in a sample project.

gemfile:

source 'https://rubygems.org'

gem 'rails', '3.2.16'
gem 'sqlite3'

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'
  gem 'uglifier', '>= 1.0.3'
  gem 'turbo-sprockets-rails3'
end

gem 'jquery-rails'
gem 'jquery-ui-rails'

gem 'active_scaffold', "~> 3.3.1"
gem "render_component_vho", "~> 3.2.1"

application.js:

//= require jquery
//= require jquery.ui.all
//= require jquery_ujs
//= require active_scaffold

application.css:

/*
 *= require jquery.ui.all
 *= require active_scaffold
 */

top few lines of stack trace:

 rake aborted!
 /Users/jcrate/.rvm/gems/ruby-2.0.0-p353@assets_turbo/gems/jquery-ui-rails-4.1.1/app/assets/stylesheets/jquery.ui.datepicker.css.erb has already been required
   (in /Users/jcrate/.rvm/gems/ruby-2.0.0-p353@assets_turbo/gems/active_scaffold-3.3.3/app/assets/stylesheets/active_scaffold.css.scss)
 /Users/jcrate/.rvm/gems/ruby-2.0.0-p353@assets_turbo/gems/sprockets-2.2.2/lib/sprockets/base.rb:267:in `circular_call_protection'
 /Users/jcrate/.rvm/gems/ruby-2.0.0-p353@assets_turbo/gems/turbo-sprockets-rails3-0.3.11/lib/turbo-sprockets/sprockets_overrides/base.rb:14:in `build_asset'

Assets compile successfully with turbo-sprockets-rails3 if I remove the inclusion of jquery.ui.all from application.css, so if I don't need any parts of jquery-ui that active_scaffold doesn't include, that may be a possible workaround. However, the default (slow) compilation handles this scenario without errors, so it's possible that other combinations of gems with assets could trigger the same error.

lulalala commented 10 years ago

Here is a minimalistic project demonstrating this bug:

https://github.com/lulalala/turbo-sprocket-issue

Normally this project will asset-precompile just fine.
If turbo-sprocket-rails3 is installed, a Sprockets::CircularDependencyError will be raised. This happens if I @import a file and later require that file too.

This is quite common because nested requires will cause the same error too.
I can require a gem, which only @imports "jquery.ui.datepicker", which will require jquery.ui.core.
Then if I require jquery.ui.spinner myself, it will also try to require jquery.ui.core, and cause the exception.