SPA Mode & custom JS

Hello guys, When I activate the SPA mode the custom JS stops working. In this specific case I am loading preline to handle tabs in a custom edit-model page. The script is loaded via: ->renderHook('panels::scripts.after', fn() => app(Vite::class)('resources/js/admin.js')) in AdminPanelProvider. If i refresh the page after the first spa-access everything is working fine. It would be a pity to drop the spa support in my project just for this reason. Any hints?
5 Replies
toeknee
toeknee14mo ago
You shouldn't be rendering that like that. You should inject the JS into the assets as the CSS is
giuseppemastrodonato
Oh, just want to let you know that I have solved the issue. I have added this hook in the JS file to refresh preline components on "livewire:navigate". document.addEventListener('livewire:navigated', () => { window.HSStaticMethods.autoInit(); }) I tried that but it wasn't working. What would be the syntax for Vite JS scripts?
jaocero
jaocero13mo ago
Hi @giuseppemastrodonato would you mind sharing a code snippet of your full js code? I also experience this issue that for a third party js
zezont4
zezont413mo ago
I added this code to AdminPanelProvider.php inside boot() method but still not working ``php \Filament\Support\Facades\FilamentView::registerRenderHook( 'panels::body.end', fn () => " <script> document.addEventListener('livewire:navigated', () => { window.HSStaticMethods.autoInit(); }) </script>" ); also I got this error in console : Uncaught TypeError: Cannot read properties of undefined (reading 'autoInit') at HTMLDocument how did you do it ? I tried this still not working !

Did you find this page helpful?