Search code examples
phplaravelturbolinkslaravel-livewirelivewires

SPA on Livewire not loading js elements after 2nd page Render


My SPA based on livewire is not loading javascript events after second page rendering: For example, two cases :

  1. First page refresh in dashboard loads the charts plugin. After I render some other page and come back to dashboard, the chart does not load again.

  2. I refresh the page, my menus in sidebar are collapsed. After I render some other page, they do not appear collapsed.

I'm using Turbolinks with Livewire on Laravel 8.

Thank you in advance.


Solution

  • I had a similar problem, for me it did not work because I put the JS code into a window.onload function but when I removed the function, the inner code executed twice so I placed the inner code into a separate file and imported it and it works. Try putting the Charts initialization in a separate file.

    Else have a look @ this: https://github.com/livewire/livewire/issues/1022