In lieu of a pr I have a suspected cause, detailed at the end of this issue.
Steps to reproduce
Using with_content on a pass through slot with no arguments, like what is documented here.
Expected behavior
The content argument passed into with_content is rendered as the slot.
Actual behavior
The error undefined method with_content for nil:NilClass is raised.
System configuration
Rails version:
6.1.3.1
Ruby version:
3.0.0
Gem version:
2.31.1
Suspected cause
SlotableV2's defined method for a slot, seen here, checks to see if the slots caller passed in args or a block and uses that to determine the response.
If you call the slot without args or a block it's value is the result of get_slot(slot_name) which is the value nil returned on line 202 of that file.
If I pass args into the slot <% modal.header(classes: nil).with_content(title) %> it renders the slot correctly.
Potential solution
I'm happy to open a PR to fix this, but I'm not sure what the solution should be. To get access to with_content the slot's method will need to return an instance of SlotV2 whether or not arguments/a block are passed in. I don't know if that means the parts of set_slot responsible for initializing the slot need to be extracted to a method both get_slotandset_slotcall or ifget_slot` should just be removed completely. I could also be way off base with my proposed solution.
In lieu of a pr I have a suspected cause, detailed at the end of this issue.
Steps to reproduce
Using
with_contenton a pass through slot with no arguments, like what is documented here.Expected behavior
The content argument passed into
with_contentis rendered as the slot.Actual behavior
The error undefined method
with_contentfor nil:NilClass is raised.System configuration
Rails version:
6.1.3.1
Ruby version:
3.0.0
Gem version:
2.31.1
Suspected cause
SlotableV2's defined method for a slot, seen here, checks to see if the slots caller passed in args or a block and uses that to determine the response.If you call the slot without args or a block it's value is the result of
get_slot(slot_name)which is the value nil returned on line 202 of that file.If I pass args into the slot
<% modal.header(classes: nil).with_content(title) %>it renders the slot correctly.Potential solution
I'm happy to open a PR to fix this, but I'm not sure what the solution should be. To get access to
with_contentthe slot's method will need to return an instance ofSlotV2whether or not arguments/a block are passed in. I don't know if that means the parts ofset_slot responsible for initializing the slot need to be extracted to a method bothget_slotandset_slotcall or ifget_slot` should just be removed completely. I could also be way off base with my proposed solution.