Skip to content

Commit 31fafe3

Browse files
Avoid allocating new string when output_postamble is blank (#1911)
* Avoid allocating new string when output_postamble is blank * Apply suggestions from code review --------- Co-authored-by: Joel Hawksley <[email protected]> Co-authored-by: Joel Hawksley <[email protected]>
1 parent d5f2544 commit 31fafe3

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

docs/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ nav_order: 5
3030

3131
*Olle Jonsson*
3232

33+
* Avoid duplicating rendered string when `output_postamble` is blank.
34+
35+
*Mitchell Henke*
36+
3337
## 3.8.0
3438

3539
* Use correct value for the `config.action_dispatch.show_exceptions` config option for edge Rails.

lib/view_component/base.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,12 @@ def render_in(view_context, &block)
104104
before_render
105105

106106
if render?
107-
render_template_for(@__vc_variant).to_s + output_postamble
107+
# Avoid allocating new string when output_postamble is blank
108+
if output_postamble.blank?
109+
render_template_for(@__vc_variant).to_s
110+
else
111+
render_template_for(@__vc_variant).to_s + output_postamble
112+
end
108113
else
109114
""
110115
end

0 commit comments

Comments
 (0)