Fix conditional slots being always rendered#134
Conversation
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Folding extracts slots at compile time, so a slot wrapped in a runtime control structure (@if, @foreach, etc.) would always render regardless of the condition. Detect unclosed control structures around call-site slots and fall back to the regular compiler, which now evaluates them at runtime. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Took this for a spin today — nice work. I verified it against a repro of #119: on main, a slot wrapped in I pushed two commits:
Full suite is green locally (211 passed, 6 skipped). I also added truthy-condition comparison tests to make sure slots that should render still do, in both the folded and non-folded paths. One thing I checked that this doesn't cover: #182 (slots declared inside an Feel free to un-draft if you're happy with the fold-detection approach. |
This comment was marked as off-topic.
This comment was marked as off-topic.
|
I would prefer a more robust solution for parsing of directives instead of just adding a bunch of regexes. We already hack around directive parsing using a separate instance of blade compiler, which ensures we stay aligned with Laravel. It would be ideal to come up with something that would cover all these needs. Additionally, this solution would only work with the listed directives: Wrapping a slot in I envision something that detects if a slot is wrapped in any directive (to be safe). |
The scenario
Wrapping
<x-slot>in@ifalways renders the slot, even when the condition is false.The problem
Blaze extracted slot declarations at compile time, stripping them from their surrounding Blade directives. Runtime conditionals like
@ifwere never evaluated around the slot.The solution
We now compile slots inline alongside the rest of the template instead of extracting them upfront.
Fixes #119