{"action":"created","issue":{"url":"https://api.github.com/repos/rails/rails/issues/28503","repository_url":"https://api.github.com/repos/rails/rails","labels_url":"https://api.github.com/repos/rails/rails/issues/28503/labels{/name}","comments_url":"https://api.github.com/repos/rails/rails/issues/28503/comments","events_url":"https://api.github.com/repos/rails/rails/issues/28503/events","html_url":"https://github.com/rails/rails/issues/28503","id":215737880,"number":28503,"title":"Fragment cache digest is blank when HTML partial is rendered inside JS view","user":{"login":"thomasfedb","id":193831,"avatar_url":"https://avatars0.githubusercontent.com/u/193831?v=4","gravatar_id":"","url":"https://api.github.com/users/thomasfedb","html_url":"https://github.com/thomasfedb","followers_url":"https://api.github.com/users/thomasfedb/followers","following_url":"https://api.github.com/users/thomasfedb/following{/other_user}","gists_url":"https://api.github.com/users/thomasfedb/gists{/gist_id}","starred_url":"https://api.github.com/users/thomasfedb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thomasfedb/subscriptions","organizations_url":"https://api.github.com/users/thomasfedb/orgs","repos_url":"https://api.github.com/users/thomasfedb/repos","events_url":"https://api.github.com/users/thomasfedb/events{/privacy}","received_events_url":"https://api.github.com/users/thomasfedb/received_events","type":"User","site_admin":false},"labels":[{"id":3666649,"url":"https://api.github.com/repos/rails/rails/labels/actionview","name":"actionview","color":"d7e102","default":false},{"id":128692,"url":"https://api.github.com/repos/rails/rails/labels/needs%20feedback","name":"needs feedback","color":"ededed","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":27,"created_at":"2017-03-21T13:23:44Z","updated_at":"2018-03-20T14:07:37Z","closed_at":"2018-03-20T11:36:27Z","author_association":"CONTRIBUTOR","body":"### Steps to reproduce\r\n\r\n1. `git clone https://github.com/thomasfedb/rails-cache-test.git`\r\n2. `touch tmp/caching-dev.txt`\r\n3. Run `rails s` and open in browser. Note that the paragraph is **red**.\r\n4. Click the link to reload partial over JS. The paragraph is still **red**.\r\n5. `git checkout blue` but **do not** restart Rails server.\r\n6. Reload browser. Note that the paragraph is **blue**.\r\n7. Click the link to reload partial over JS. The paragraph changes back to **red**.\r\n\r\nWhen you review the logs from `rails s` you'll find that the following:\r\n\r\n**Loading red partial via `index.html.erb`**\r\n```\r\nStarted GET \"/\" for ::1 at 2017-03-21 21:05:30 +0800\r\nProcessing by HomeController#index as HTML\r\n  Rendering home/index.html.erb within layouts/application\r\nRead fragment views/x.dev.localhost//a8f265d1f73f3dafd91c3d947bbaac43 (0.0ms)\r\nWrite fragment views/x.dev.localhost//a8f265d1f73f3dafd91c3d947bbaac43 (0.0ms)\r\n```\r\n\r\n**Loading red partial via `index.js.erb`**\r\n```\r\nStarted GET \"/\" for ::1 at 2017-03-21 21:05:54 +0800\r\nProcessing by HomeController#index as JS\r\n  Rendering home/index.js.erb\r\n  'home/_partial' file doesn't exist, so no dependencies\r\n  Couldn't find template for digesting: home/_partial\r\nRead fragment views/x.dev.localhost// (0.1ms)\r\nWrite fragment views/x.dev.localhost// (0.1ms)\r\n```\r\n\r\n**Loading blue partial via `index.html.erb`**\r\n```\r\nStarted GET \"/\" for 127.0.0.1 at 2017-03-21 21:06:23 +0800\r\nProcessing by HomeController#index as HTML\r\n  Rendering home/index.html.erb within layouts/application\r\nRead fragment views/x.dev.localhost//2338c21dccfbc4347d872c453af9f072 (0.1ms)\r\nWrite fragment views/x.dev.localhost//2338c21dccfbc4347d872c453af9f072 (0.1ms)\r\n```\r\n\r\n**Loading blue partial via `index.js.erb`**\r\n```\r\nStarted GET \"/\" for ::1 at 2017-03-21 21:06:24 +0800\r\nProcessing by HomeController#index as JS\r\n  Rendering home/index.js.erb\r\n  'home/_partial' file doesn't exist, so no dependencies\r\n  Couldn't find template for digesting: home/_partial\r\nRead fragment views/x.dev.localhost// (0.1ms)\r\n```\r\n\r\n### Expected behavior\r\nThe cache digest should be calculated correctly when rendering an HTML partial inside a JS view.\r\n\r\n### Actual behavior\r\nWhen rendering a HTML partial inside a JS view, the cache digest is blank. When the partial source changes, the key does not change, leading to the wrong content being displayed.\r\n\r\nThe issue seems to stem from [this line](https://github.com/rails/rails/blob/4d6feef79248a63c4cefde3f9ceb2242925e8d8d/actionview/lib/action_view/digestor.rb#L48) in `ActionView::Digestor`:\r\n```\r\noptions[:formats] = [finder.rendered_format] if finder.rendered_format\r\n```\r\n\r\nWhich, [as seen here](https://github.com/rails/rails/blob/fc2aa53f875b12df93b0d07932e3ab563b89152c/actionview/lib/action_view/renderer/template_renderer.rb#L12), will take only the first format (in this case `:js`) when it should probably take all formats (which would be `[:js, :html]`):\r\n```\r\n@lookup_context.rendered_format ||= (template.formats.first || formats.first)\r\n```\r\n\r\n### System configuration\r\n**Rails version**: 5.0.2\r\n**Ruby version**: 2.4.0\r\n"},"comment":{"url":"https://api.github.com/repos/rails/rails/issues/comments/374610493","html_url":"https://github.com/rails/rails/issues/28503#issuecomment-374610493","issue_url":"https://api.github.com/repos/rails/rails/issues/28503","id":374610493,"user":{"login":"thomasfedb","id":193831,"avatar_url":"https://avatars0.githubusercontent.com/u/193831?v=4","gravatar_id":"","url":"https://api.github.com/users/thomasfedb","html_url":"https://github.com/thomasfedb","followers_url":"https://api.github.com/users/thomasfedb/followers","following_url":"https://api.github.com/users/thomasfedb/following{/other_user}","gists_url":"https://api.github.com/users/thomasfedb/gists{/gist_id}","starred_url":"https://api.github.com/users/thomasfedb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thomasfedb/subscriptions","organizations_url":"https://api.github.com/users/thomasfedb/orgs","repos_url":"https://api.github.com/users/thomasfedb/repos","events_url":"https://api.github.com/users/thomasfedb/events{/privacy}","received_events_url":"https://api.github.com/users/thomasfedb/received_events","type":"User","site_admin":false},"created_at":"2018-03-20T14:07:37Z","updated_at":"2018-03-20T14:07:37Z","author_association":"CONTRIBUTOR","body":"Many thanks @javan "}}
{"actor":{"display_login":"thomasfedb"}}