Hi all,
This was originally incorrectly posted at
https://github.com/rails/rails/issues/28072 - as advised, I'm now posting it here instead.
It is very easy to accidentally call content_for from within a block that will be fragment cached, especially if the cached fragment calls out to a partial. eg:
<!-- index.html.erb -->
<%= cache "fragment" do %>
<!-- ... -->
<%= render "javascript_widget" %>
<% end %>
<!-- load javascript files last -->
<%= content_for :javascript_includes %>
<!--- _javascript_widget.html.erb -->
<div class="jsPlaceholder />
<% content_for :javascript_includes do %>
<%= javascript_include_tag ... %>
<script>doTheThing('.jsPlaceholder')</script>
<% end %>
Steps to reproduce
Call content_for from within code that will end up in a fragment cache
Expected behavior
An error should be raised letting the developer know that the content_for would not occur.
Actual behavior
The contents of the content_for are silently discarded.