41 lines
1.8 KiB
Diff
41 lines
1.8 KiB
Diff
|
|
From 770060d93a897cb5fb5108bb828b927fe6bb5353 Mon Sep 17 00:00:00 2001
|
||
|
|
From: Jean Boussier <jean.boussier@gmail.com>
|
||
|
|
Date: Mon, 14 Aug 2023 11:20:43 +0200
|
||
|
|
Subject: [PATCH] Handle non-string partial body in
|
||
|
|
ActionView::CollectionCaching
|
||
|
|
|
||
|
|
Followup: https://github.com/rails/rails/pull/48645
|
||
|
|
|
||
|
|
Some template engines such as `jbuilder` use these Action View primitives
|
||
|
|
with types other than strings, which breaks a bunch of assumptions.
|
||
|
|
|
||
|
|
I wish I could add a test for this, but this is deep in private methods
|
||
|
|
I don't see a way to cover this.
|
||
|
|
---
|
||
|
|
.../renderer/partial_renderer/collection_caching.rb | 11 +++++++++--
|
||
|
|
1 file changed, 9 insertions(+), 2 deletions(-)
|
||
|
|
|
||
|
|
diff --git a/actionview/lib/action_view/renderer/partial_renderer/collection_caching.rb b/actionview/lib/action_view/renderer/partial_renderer/collection_caching.rb
|
||
|
|
index d65d4c0cafaba..6ee720aa4896b 100644
|
||
|
|
--- a/actionview/lib/action_view/renderer/partial_renderer/collection_caching.rb
|
||
|
|
+++ b/actionview/lib/action_view/renderer/partial_renderer/collection_caching.rb
|
||
|
|
@@ -96,9 +96,16 @@ def fetch_or_cache_partial(cached_partials, template, order_by:)
|
||
|
|
build_rendered_template(content, template)
|
||
|
|
else
|
||
|
|
rendered_partial = yield
|
||
|
|
- if fragment = rendered_partial.body&.to_str
|
||
|
|
- entries_to_write[cache_key] = fragment
|
||
|
|
+ body = rendered_partial.body
|
||
|
|
+
|
||
|
|
+ # We want to cache buffers as raw strings. This both improve performance and
|
||
|
|
+ # avoid creating forward compatibility issues with the internal representation
|
||
|
|
+ # of these two types.
|
||
|
|
+ if body.is_a?(ActionView::OutputBuffer) || body.is_a?(ActiveSupport::SafeBuffer)
|
||
|
|
+ body = body.to_str
|
||
|
|
end
|
||
|
|
+
|
||
|
|
+ entries_to_write[cache_key] = body
|
||
|
|
rendered_partial
|
||
|
|
end
|
||
|
|
end
|