komposable / komponent

An opinionated way of organizing front-end code in Ruby on Rails, based on components
http://komponent.io
MIT License
428 stars 31 forks source link

Nested yields #130

Closed aldhsu closed 7 months ago

aldhsu commented 5 years ago

I'm trying to write a Komponent with a method that renders another Komponent but something seems to be up with how the blocks are passed around.

I have built a repro case at https://github.com/aldhsu/komponent-nested-yields.

Expected

Expect this:

<%# index.html.erb %>
<%= c "foo" do |foo| %>
  <%= foo.bar do %>
     Hello
  <% end %>
<% end %>
<%# _foo.html.erb %>
<div class="foo">
  <%= yield self %>
</div>
#foo_component.rb
module FooComponent
  extend ComponentHelper
  def bar(&block)
    component("bar", &block)
  end
end
<%# _bar.html.erb %>
<div class="bar">
  <%= yield %>
</div>

To output:

<div class="foo">
  <div class="bar">
     Hello
  </div>
</div>

Actual

<div class="foo">
  Hello
  <div class="bar">
    Hello
  </div>
</div>

I'm not sure I entirely understand how the capture is supposed to work in this case so I don't know where to start looking. Basically I'm wrapping this behaviour:

<%= c "foo" do %>
  <%= c "bar" do %>
    Hello
  <% end %>
<% end %>
Spone commented 5 years ago

I think this issue is similar to #83, that has been handled with a workaround. Since it's the second time this issue is raised, I think we should investigate further.