Data binding not working when component added with Alpine js

I’m building at the moment a Alpine js Modal that can dynamically add a Livewire form component.

When I’m including the component in a normal blade view, everything works fine. But when I’m adding the form component with Alpine js (fetch and x-ref) the wire:model inputs are showing no value. There are also no ajax requests from livewire when I’m writing in the input fields.

I think the reactivity of the form component gets lost when he is between <template x-for=""> loop from Alpine js.

Here the shortened code of the modal component:

<div>
    <div
        x-data="{...windowManager()}"
        x-on:add-window.window="addWindow($event, $dispatch)"
    >
        <template x-for="(window, index) in windows" :key="index">
            <div>
                <div x-ref="test"></div>
            </div>
        </template>
    </div>
</div>

<script>
  	function windowManager() {
            /* 
               Modal logic
            */

            /* Fetch view and add it to modal with x-ref */
            fetch('/frontend/blog')
                .then(response => response.text())
                .then(html => { this.$refs.test.innerHTML = html })
        }
</script>

Here I fetch a view that contains the Livewire form component, but when the component is between the <template x-for=""> loop the reactivity gets lost. Do I have to somehow refresh the form component?

Did someone had a similar problem and how can i fix this?

Sorry to tell you this but you need to have a different approach.

Livewire components are rendered by Blade. They cannot just be injected into the page client-side, no more than you can load php code into a client.

Look at the HTML source for a Livewire component. It has been expanded to include all the hooks for Livewire.

A simple tag like;

@livewire('feedback-modal')

becomes something like

<div wire:initial-data="{&quot;id&quot;:&quot;6xO2l1X6Gqz20CEP5uNh&quot;,&quot;name&quot;:&quot;feedback-modal&quot;,&quot;redirectTo&quot;:false,&quot;events&quot;:[&quot;setcontent&quot;,&quot;setmockcontent&quot;],&quot;eventQueue&quot;:[],&quot;dispatchQueue&quot;:[],&quot;data&quot;:{&quot;modelid&quot;:null,&quot;mock&quot;:null,&quot;listeners&quot;:[&quot;setcontent&quot;,&quot;setmockcontent&quot;]},&quot;children&quot;:[],&quot;checksum&quot;:&quot;c2a742e2bfdf91e9a04c756a7ed591d7e5e9d339270c6111f304856f86084b0d&quot;}" wire:id="6xO2l1X6Gqz20CEP5uNh" >

after being rendered by blade.

Thank you for your answer!
I will try another approach.