Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ nav_order: 6

## main

* Return `html_safe` empty string from `render_in` when `render?` is false.

*Copilot*

## 4.5.0

* Fix initialization ordering issue causing missing asset errors in Sprockets.
Expand Down
2 changes: 1 addition & 1 deletion lib/view_component/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def render_in(view_context, &block)

value
else
""
"".html_safe
end
ensure
view_context.instance_variable_set(:@virtual_path, @old_virtual_path)
Expand Down
6 changes: 6 additions & 0 deletions test/sandbox/test/rendering_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,12 @@ def test_does_not_render_passed_in_content_if_render_is_false
assert total < 1
end

def test_render_in_returns_html_safe_string_when_render_is_false
render_inline(ConditionalRenderComponent.new(should_render: false))

assert_predicate @rendered_content, :html_safe?
end

def test_collection_parameter_does_not_require_compile
dynamic_component =
Class.new(ViewComponent::Base) do
Expand Down
Loading