Skip to content

Commit c0980d3

Browse files
authored
Merge pull request rails#48936 from Shopify/jbuilder-collection-caching
Handle non-string partial body in ActionView::CollectionCaching
2 parents b6669e5 + 770060d commit c0980d3

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

actionview/lib/action_view/renderer/partial_renderer/collection_caching.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,16 @@ def fetch_or_cache_partial(cached_partials, template, order_by:)
9696
build_rendered_template(content, template)
9797
else
9898
rendered_partial = yield
99-
if fragment = rendered_partial.body&.to_str
100-
entries_to_write[cache_key] = fragment
99+
body = rendered_partial.body
100+
101+
# We want to cache buffers as raw strings. This both improve performance and
102+
# avoid creating forward compatibility issues with the internal representation
103+
# of these two types.
104+
if body.is_a?(ActionView::OutputBuffer) || body.is_a?(ActiveSupport::SafeBuffer)
105+
body = body.to_str
101106
end
107+
108+
entries_to_write[cache_key] = body
102109
rendered_partial
103110
end
104111
end

0 commit comments

Comments
 (0)