Skip to content

Commit bdee517

Browse files
Fix render_in to return html_safe empty string when render? is false
Co-authored-by: joelhawksley <1940294+joelhawksley@users.noreply.github.com> Agent-Logs-Url: https://github.com/ViewComponent/view_component/sessions/bfc044d6-6ca7-4999-a544-ff12b3f1b00d
1 parent 82aeafc commit bdee517

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

lib/view_component/base.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def render_in(view_context, &block)
160160

161161
value
162162
else
163-
""
163+
"".html_safe
164164
end
165165
ensure
166166
view_context.instance_variable_set(:@virtual_path, @old_virtual_path)

test/sandbox/test/rendering_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,12 @@ def test_does_not_render_passed_in_content_if_render_is_false
877877
assert total < 1
878878
end
879879

880+
def test_render_in_returns_html_safe_string_when_render_is_false
881+
render_inline(ConditionalRenderComponent.new(should_render: false))
882+
883+
assert_predicate @rendered_content, :html_safe?
884+
end
885+
880886
def test_collection_parameter_does_not_require_compile
881887
dynamic_component =
882888
Class.new(ViewComponent::Base) do

0 commit comments

Comments
 (0)