File upload fails the first time but works afterwards when in a slide-over

Ok I have this weird issue. Here is my setup This is the custom action I'm using to show a slide-over on a table. It contains a custom component that has a form with a file upload.
Action::make('messages')
->icon('heroicon-o-envelope')
->modalContent(fn ($record) => view('livewire.common.messaging-wrapper', [
'id' => $record->id,
]))
->slideOver(),
Action::make('messages')
->icon('heroicon-o-envelope')
->modalContent(fn ($record) => view('livewire.common.messaging-wrapper', [
'id' => $record->id,
]))
->slideOver(),
this is the wrapper
@props(['object_id'])
<div>
@if(auth()->user()->is_admin)
<livewire:common.admin-messaging :id=$object_id/>
@else
<livewire:common.customer-messaging :id=$object_id/>
@endif
</div>
@props(['object_id'])
<div>
@if(auth()->user()->is_admin)
<livewire:common.admin-messaging :id=$object_id/>
@else
<livewire:common.customer-messaging :id=$object_id/>
@endif
</div>
Here is the form
Textarea::make('message')
->label(__('Message'))
->required(),
SpatieMediaLibraryFileUpload::make('media')
->label('Attachments')
->multiple()
->directory(config('filesystems.paths.images.messages'))
->visibility('private'),
Textarea::make('message')
->label(__('Message'))
->required(),
SpatieMediaLibraryFileUpload::make('media')
->label('Attachments')
->multiple()
->directory(config('filesystems.paths.images.messages'))
->visibility('private'),
Most of it is boilerplate, and it works fine when I use it in a page (I use the same wrapper). However, when I use this in a slide over as a custom action, the first time I try to upload an image, it fails and I get the following console error At first I thought it might have been an issue with the table polling, but I've disabled it and the issue is still there. If I try to upload something again, it works as expected. I know this is a weird issue, so any ideas are welcome.
4 Replies
ChesterS
ChesterS8mo ago
Here is a gif of how it looks in practice As you can see, it fails the first time, but works the second, without any changes (same file, same form, same modal)
No description
ChesterS
ChesterS8mo ago
Here's the error
No description
toeknee
toeknee8mo ago
I have a feeling you are loading the view opposed to the livewire view and the element Spatie is a livewire package I believe so it fails on first load until the assets are loaded
ChesterS
ChesterS8mo ago
@toeknee Sorry can you elaborate a bit? I'm not sure what you mean 😦 I am loading a view in the custom action
->modalContent(fn ($record) => view('livewire.common.messaging-wrapper', [
'id' => $record->id,
]))
->modalContent(fn ($record) => view('livewire.common.messaging-wrapper', [
'id' => $record->id,
]))
but that view has a livewire component in it
<livewire:common.admin-messaging :id=$object_id/>
<livewire:common.admin-messaging :id=$object_id/>
is there a better way to do this?