diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md
index 4a3bbec15..28362dc41 100644
--- a/docs/CHANGELOG.md
+++ b/docs/CHANGELOG.md
@@ -10,6 +10,10 @@ nav_order: 6
## main
+* Allow `render_inline` with Nokogiri::HTML5 to parse more arbitrary content including bare table content otherwise illegal fragments like `
`.
+
+ *Jonathan Rochkind*
+
* Remove known issue from docs as ActiveScaffold is [now compatible](https://github.com/activescaffold/active_scaffold/pull/743) with ViewComponent.
*David Löwenfels*
diff --git a/lib/view_component/test_helpers.rb b/lib/view_component/test_helpers.rb
index e3de34f1b..63d4f12fc 100644
--- a/lib/view_component/test_helpers.rb
+++ b/lib/view_component/test_helpers.rb
@@ -40,7 +40,7 @@ def render_inline(component, **args, &block)
@page = nil
@rendered_content = vc_test_view_context.render(component, args, &block)
- fragment = Nokogiri::HTML5.fragment(@rendered_content)
+ fragment = Nokogiri::HTML5.fragment(@rendered_content, context: "template")
@vc_test_view_context = nil
fragment
end
diff --git a/test/sandbox/app/components/table_contents_component.rb b/test/sandbox/app/components/table_contents_component.rb
new file mode 100644
index 000000000..9c20afaa5
--- /dev/null
+++ b/test/sandbox/app/components/table_contents_component.rb
@@ -0,0 +1,7 @@
+# frozen_string_literal: true
+
+class TableContentsComponent < ViewComponent::Base
+ def call
+ " | td contents | ".html_safe
+ end
+end
diff --git a/test/sandbox/test/rendering_test.rb b/test/sandbox/test/rendering_test.rb
index 343cfaef3..2a0a094fb 100644
--- a/test/sandbox/test/rendering_test.rb
+++ b/test/sandbox/test/rendering_test.rb
@@ -20,7 +20,7 @@ def test_render_inline_allocations
MyComponent.__vc_ensure_compiled
with_instrumentation_enabled_option(false) do
- assert_allocations({"3.5" => 67, "3.4" => 72..74, "3.3" => 72, "3.2" => 75..76}) do
+ assert_allocations({"3.5" => 67, "3.4" => 72..74, "3.3" => 75, "3.2" => 78..79}) do
render_inline(MyComponent.new)
end
end
@@ -34,7 +34,7 @@ def test_render_collection_inline_allocations
ViewComponent::CompileCache.cache.delete(ProductComponent)
ProductComponent.__vc_ensure_compiled
- allocations = {"3.5" => 66, "3.4" => 70..82, "3.3" => 86, "3.2" => 89..90}
+ allocations = {"3.5" => 66, "3.4" => 70..82, "3.3" => 89, "3.2" => 92..93}
products = [Product.new(name: "Radio clock"), Product.new(name: "Mints")]
notice = "On sale"
@@ -77,6 +77,10 @@ def test_render_inline_returns_nokogiri_fragment
assert_includes render_inline(MyComponent.new).css("div").to_html, "hello,world!"
end
+ def test_render_inline_handles_table_contents
+ assert_includes render_inline(TableContentsComponent.new).css("td").to_html, "td contents | "
+ end
+
def test_render_inline_sets_rendered_content
render_inline(MyComponent.new)