Dynamically inserting livewire components from ajax requests

I have a few modals when opened they dynamically load their contents via AJAX and set their own innerHTML from the response. These responses have livewire components in them. When they’re added to page via innertHTML, livewire components are not initialized. I’ve checked how TurboLinks integration is doing it, and tried calling window.livewire.restart()after updating the innerHTML, but this time I get the following JS error on the console:

TypeError: Cannot read property 'data' of null

image

Do you have any ideas on how to initialize livewire components that are loaded via ajax and added to the page via innertHTML?

I was able to init dynamically loaded livewire components by calling window.livewire.rescan(); but it’s not documented anywhere. So, @calebporzio is it safe to use rescan on this scenario?

2 Likes

Thanks bro, window.livewire.rescan(); work fantastic for it. i was try with window.livewire.restart();