lookbook icon indicating copy to clipboard operation
lookbook copied to clipboard

Getting missing partial error for collections on v2

Open robinator opened this issue 1 year ago • 4 comments

Describe the bug

Whenever a partial references partials within it (relative to it), there is a missing partial error raised. I believe this is because the parent partial's directory is not in the partial search path:

To Reproduce

Given these partials:

# app/views/shifts/_shift_card.html.slim
.shifts-card
   = render shifts # an array of Shift instances

and

# app/views/shifts/_shift.html.slim
.shift
   = shift.name

Calling this in a preview will throw an error:

def shift_card
  render 'shifts/shift_card', shifts: FactoryBot.create_list(:shift, 2)
end
Missing partial lookbook/shifts/_shift with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby, :slim]}.

Searched in:
  * ".../test/components/previews"
  * ".../app/views"

Expected behavior

Rails collections partials should be rendered normally without including the direct path from within the partial.

Version numbers

Please complete the following information:

  • Lookbook: '>= 2.0.0-rc.2'
  • ViewComponent: > 2.0
  • Rails: 7.1.0.alpha
  • Ruby: 3.2.2

Additional context

Rendering works if the direct path from the views directory is given:

= render shifts # fails
= render partial: 'shift', collection: shifts # fails
= render partial: 'shifts/shift', collection: shifts # works

robinator avatar Apr 23 '23 01:04 robinator