loadedOnRequest() not loading assets on request

I register the followinf assets in my service provider:
FilamentAsset::register([
Js::make('local-player-script', __DIR__ . '/../../resources/js/local-player.js')->loadedOnRequest(),
Js::make('radio-player-script', __DIR__ . '/../../resources/js/radio-player.js')->loadedOnRequest(),
Css::make('player-stylesheet', __DIR__ . '/../../resources/css/player.css')->loadedOnRequest(),
]);
FilamentAsset::register([
Js::make('local-player-script', __DIR__ . '/../../resources/js/local-player.js')->loadedOnRequest(),
Js::make('radio-player-script', __DIR__ . '/../../resources/js/radio-player.js')->loadedOnRequest(),
Css::make('player-stylesheet', __DIR__ . '/../../resources/css/player.css')->loadedOnRequest(),
]);
I have a custom widget the needs one of the JS files. But they arent loaded when requested! widget:
<x-filament-widgets::widget>
<div
x-data="radioPlayerCode"
x-load-js="[@js(\Filament\Support\Facades\FilamentAsset::getScriptSrc('radio-player-script'))]"
x-load-css="[@js(\Filament\Support\Facades\FilamentAsset::getStyleHref('player-stylesheet'))]"
>
<!-- ... -->
</div>
</x-filament-widgets::widget>
<x-filament-widgets::widget>
<div
x-data="radioPlayerCode"
x-load-js="[@js(\Filament\Support\Facades\FilamentAsset::getScriptSrc('radio-player-script'))]"
x-load-css="[@js(\Filament\Support\Facades\FilamentAsset::getStyleHref('player-stylesheet'))]"
>
<!-- ... -->
</div>
</x-filament-widgets::widget>
If I remove the loadedOnRequest(), then they are always loaded, but I dont really want that. I only want them to load when this widget is rendered. Am I missing something?
6 Replies
Matthew
MatthewOP5mo ago
Let me know if you need more information 🙂 bump
awcodes
awcodes5mo ago
What is the exact version of filament you have installed? Code looks ok to me.
Matthew
MatthewOP5mo ago
Filament .........................................................................................................................................
Blade Icons ............................................................................................................................... CACHED
Packages ......................................................................................... filament, forms, notifications, support, tables
Panel Components ...................................................................................................................... NOT CACHED
Version .................................................................................................................................. v3.3.34
Views .............................................................................................................................. NOT PUBLISHED
Filament .........................................................................................................................................
Blade Icons ............................................................................................................................... CACHED
Packages ......................................................................................... filament, forms, notifications, support, tables
Panel Components ...................................................................................................................... NOT CACHED
Version .................................................................................................................................. v3.3.34
Views .............................................................................................................................. NOT PUBLISHED
awcodes
awcodes5mo ago
Hmm. Should be fine then. I’m not seeing anything wrong. Are you registering them in boot() or register() in the service provider?
Matthew
MatthewOP5mo ago
in boot() If its ok with you I can try making a minimum reproduction repo
awcodes
awcodes5mo ago
Sure

Did you find this page helpful?