What seems to be the problem:
I have spend an exorbitant amount of time trying to figure out why one of the values in my state was reset to null when I upload a file. Value sits in $state array populated in mount(), and why it was happening was not obvious at all.
Steps to Reproduce:
Create a generic component WithFileUploads
, add an integer state variable with default value, upload a file and observe the value of variable
Are you using the latest version of Livewire:
yes.
Do you have any screenshots or code examples:
<?php
namespace App\Http\Livewire;
use Livewire\Component;
use Livewire\WithFileUploads;
class Edit extends Component
{
use AuthorizesRequests;
use WithFileUploads;
/**
* @var array
*/
public $state = [];
public function mount()
{
$this->state = [
'property' => 1,
'attachments' => [],
];
}
...
}
and the view has a
<div wire:poll>
<input type="text" wire:model="state.property">
<input type="file" wire:model="state.attachments">
<pre>@json($state)</pre>
</div>
Upload a file and kaboom, the integer in state.property
is completely gone and is suddenly null (poll
and @json
added to visualize the issue)
I think the reason is somewhere in HashDataPropertiesForDirtyDetection::hash(), but i could be wrong