lookbook-hq / lookbook

A UI development environment for Ruby on Rails apps ✨
https://lookbook.build
MIT License
853 stars 90 forks source link

Previews not rendering nested components #581

Closed iamdriz closed 5 months ago

iamdriz commented 5 months ago

We have a nested component in our views which will render both components (the inner component via content).

<%= render ExampleComponent.new do %>
  <%= render AnotherExampleComponent.new %>
<% end %>

However when doing the same in Lookbook previews, the inner component doesn't render:

def default
  render ExampleComponent.new do
    render AnotherExampleComponent.new
  end
end

Only the ExampleComponent renders in the preview and the AnotherExampleComponent is ignored!

How we get Lookbook to render the inner component?

Version numbers

iamdriz commented 5 months ago

I figured it out, seems you have to use render on the component block itself:

def default
  render ExampleComponent.new do |component|
    component.render(AnotherExampleComponent.new)
  end
end
ben-flyht commented 5 months ago

I figured it out, seems you have to use render on the component block itself:

def default
  render ExampleComponent.new do |component|
    component.render(AnotherExampleComponent.new)
  end
end

How would you do this if you wanted to render two components within the ExampleComponent? For me the root of wanting to do this is not being able to have production find the preview html.erb file due to it being in the test folder.