Skip to content

Partials that yield result in double rendering bug #2423

@camertron

Description

@camertron

This issue is the result of me re-filing #2408 (comment) as a new issue.

Components that render partials that yield exhibit a double rendering bug.

It worked correctly on v3.x with config.view_component.capture_compatibility_patch_enabled = true. Broke with upgrade to v4.

Steps to reproduce

A minimal reproducible example:

# app/components/example_component.rb

class ExampleComponent < ViewComponent::Base
end
<%# app/components/example_component.html.erb %>

<%= render "shared/partial" do %>
  abc
<% end %>
<%# app/views/shared/_partial.html.erb %>

def <%= yield %>

Expected behavior

Output should be (not sure about line breaks):

<!-- BEGIN app/components/example_component.html.erb -->

<!-- BEGIN app/views/shared/_partial.html.erb -->def 
  abc

<!-- END app/views/shared/_partial.html.erb --><!-- END app/components/example_component.html.erb -->

Actual behavior

The actual output (with annotations by rails) is:

<!-- BEGIN app/components/example_component.html.erb -->
  abc
<!-- BEGIN app/views/shared/_partial.html.erb -->def 
  abc

<!-- END app/views/shared/_partial.html.erb --><!-- END app/components/example_component.html.erb -->

abc (component html) is output twice 🤔

System configuration

Rails version:
8.0.2

Ruby version:
3.3.5

Gem version:
4.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions