I have two partials which refer to one another. When I calculate nested dependencies in the console likes so (with some debug code outputting which template is being loaded):
finder = ApplicationController.new.lookup_context
ActionView::Digestor.new(name: "posts/show", finder: finder).nested_dependencies
or via the rake task like so:
rake cache_digests:nested_dependencies TEMPLATE=posts/show
I get a short list of initial dependencies, and then this in an infinite loop, until the ruby stack is full:
...
>>>>>>> users/foo
>>>>>>> users/bar
>>>>>>> users/baz
>>>>>>> users/bip
>>>>>>> users/foo
>>>>>>> users/bar
>>>>>>> users/baz
>>>>>>> users/bip
SystemStackError: stack level too deep
(template names changed)
However, when I run the app server and request the template, things run just fine, no infinite loops.
Here are my settings in all of the above cases:
config.action_controller.perform_caching = true
config.cache_store = :file_store, Rails.root.to_s + '/tmp/cache/stuff'
ActionView::Base.cache_template_loading = true
The code indicates that it does have recursive reference protection: https://github.com/rails/rails/blob/v4.1.8/actionview/lib/action_view/digestor.rb#L35
Why is this protection working in the server environment but not in console or the rake task?
(also a github issue https://github.com/rails/rails/issues/18667 )
Rails and the rake task uses two completely different methods of the ActionView::Digestor
.
Rails usually calls ActionView::Digestor.digest
which calls into compute_and_store_digest
which has the infinite loop protection.
However nested_dependencies
only calls DependencyTracker.find
_dependencies recursively without any infinite loop detection.
If you check for usages of nested_dependencies
on github you can see that it is only used from the rake task and nowhere else.
So IMHO this is a bug in nested_dependencies
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With