Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dependency Tracker finds dependencies in HTML tags and incorrectly in render calls #23536

Closed
romaimperator opened this issue Feb 7, 2016 · 2 comments

Comments

@romaimperator
Copy link
Contributor

I'm not sure that this is technically a bug but it does list extra dependencies for templates that are not actually dependencies. This occurs because of how the dependency tracker looks for render calls in templates.

I ran into this bug when I was using a decorator object that defined to_partial_path. I had in my view a render call like this <%= render MyDecorator.new(model_object) %> and I also had calls to the cache helper in the same template. When the cache helper was getting the dependencies to use for digesting, I saw in the log Couldn't find template for digesting: news/new. I was able to track this down to how the dependency tracker finds render calls and then processes them. The relevant code is here https://github.com/rails/rails/blob/v5.0.0.beta2/actionview/lib/action_view/dependency_tracker.rb#L118.

I am also going to submit a pull request with a fix for this issue. I believe this issue #21951 is related and is also will be fixed by the pull request.

To reproduce this problem:

  1. create a new rails project

  2. create a controller with an action (name doesn't matter) and the corresponding view template

  3. in the view template add the following erb:

    <script>
      var render = document.getElementById('#render');
      render(data.autokinds);
    </script>
    
    <div id="render" data-auto_kinds="value">
      <h1>hello</h1>
    </div>
    
    <%= render ApplicationHelper::ClassWithPartialPath.new %>
    <%= render ClassWithPartialPath.new %>
    <%= render ApplicationHelper::employee %>
  4. run bundle exec rake cache_digests:dependencies TEMPLATE=that_template_name

=> [
  "autokinds/autokind",
  "static/ data-auto_kinds=", # static is the name of the controller I chose
  "ApplicationHelpers/ApplicationHelper",
  "news/new"
]

After the fix, running the cache_digests command on the same template will produce:

=> [
  "employees/employee"
]

This is matching the last render call, the scoped access of a record in the ApplicationHelper. I'm not sure that anyone actually uses that but it is a side-effect fix to prevent the 3rd dependency, "ApplicationHelpers/ApplicationHelper", from showing as a dependency.

@gmcnaughton
Copy link

Possibly related: if I use the word "rendered" in an ERB comment, the parser gets confused and makes a dependency on "eds/ed" - rails/cache_digests#17

@byroot
Copy link
Member

byroot commented Dec 14, 2024

The HTML part has been fixed by #42458 and subsequent PRs.

For the constant refs, it still not quite fixed but ultimately the dependency tracker is understood as being best effort, so I don't think it's worth keeping this open, but people running into this issue are welcome to open a PR to fix these false positives.

@byroot byroot closed this as completed Dec 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants