You're absolutely right that the stray {{ $slot }} in your _drawer file caused the confusion. Let me explain what happened:
Why Did This Happen?
In Laravel Blade components, whenever you use {{ $slot }} in a component file, the content you pass between the component tags gets inserted there.
When you used:
<x-layout>
<form x-target="risks-list" ...>...</form>
<div id="list"></div>
</x-layout>
The part starting from <form ...> to </div> (everything between the <x-layout> tags) is assigned to $slot. If an included (nested or partial) file inside your layout also contains {{ $slot }}, then your content appears multiple times in the rendered HTML—once in the main layout and once in _drawer.
Why did Alpine Ajax plugin Target the Wrong Place?
- Alpine's Ajax plugin probably scans for a matching DOM element (
#risks-listin your example). - Since your layout ends up rendering the same content multiple times (inside both
<body>and#drawer)—you have multiple#risks-listelements! - When Alpine tries to replace
#risks-list, depending on plugin logic, it may replace the first occurrence it finds—which could be the one inside your drawer (which is not visible!), not the expected one on the page. - This is why you saw new content ending up in your hidden drawer.
Solution Recap
Remove any unintended or duplicate {{ $slot }} from partials or includes that aren't meant to host your main content.
So your _drawer partial should be:
<div id="drawer" class="hidden"></div>
And your layout should include the slot only where the page content should appear:
<html>
<head>
<!-- scripts and styles -->
</head>
<body>
@include('_drawer')
{{ $slot }}
</body>
</html>
Summary
- Never include
{{ $slot }}in partials or includes unless that partial is directly designed to be a slot host! - Always check rendered HTML for duplicate IDs or slot content—this can trip up any client-side code, especially when working with DOM manipulation/replacement.
- The plugin acted on the first
#risks-listit found, which was in the hidden drawer due to the duplicate slot.
This is a classic case of "unexpected Blade slot propagation"—an easy mistake to make, but you've got it resolved!
If you have any more AlpineJS or Blade questions, feel free to ask.