Fix digesting non-HTML templates with non-unique logical names #25411
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes a pathological-sounding-but-it-happened-to-us scenario that caused incorrect template digests for
*/*requests that render non-HTML (JSON, in our case) templates. The scene looks something like this:append_view_path(Rails.root.join("app/views/api"))app/views, but for different formats:app/views/api/todos/_todo.json.jbuilderandapp/views/todos/_todo.html.erb, both "logically" known astodos/todo. Both of these partials havecachefragments.schedules#show) with a corresponding JSON template (show.json.jbuilder) that in turn renders a collection of partials:json.todos @todos, partial: 'todos/todo', as: :todo.fetchrequests to this action that doesn't set anAcceptheader so it defaults to*/*.The JSON response is correctly returned, but the template digest it uses for caching is computed using the HTML templates. Altering
_todo.json.jbuilderdoes not invalidate its cache, but altering_todo.html.erbdoes.We worked around the issue by adding an
Accept: application/jsonheader. Adding a.jsonformat to the URL would have worked around it too.Here are the new tests failing without the changes to
ActionView::Digestor:All green with the changes.
/cc @jeremy @matthewd