filamentphp / filament

A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS.
https://filamentphp.com
MIT License
19.28k stars 2.96k forks source link

Save form with Builder + RichEditor causing Undefined array key "type" #7957

Closed howdu closed 1 year ago

howdu commented 1 year ago

Package

filament/filament

Package Version

v3.0.28

Laravel Version

10.19.0

Livewire Version

v3.0.0-beta.10

PHP Version

8.1.14

Problem description

An issue with the Builder when it contains a RichEditor.

On first saves it works but throws an error on the third save.

Forms\Components\Repeater::make('addresses')
    ->relationship('addresses')
    ->schema([
        Forms\Components\Builder::make('blocks')
            ->minItems(1)
            ->required()
            ->blocks([
                Forms\Components\Builder\Block::make('block')
                    ->schema([
                        Forms\Components\RichEditor::make('address1')
                    ])
            ])
    ])

Checking the Livewire request it looks to be getting mixed up with two keys that refer to the same block.

{
  "_token": "123",
  "components": [
    {
      "updates": {
        "data.addresses.record-2.blocks.5a9f0253-1c13-4af3-8c9d-66bbe6694403.data.address1": "<p>Test2345</p>",
        "data.addresses.record-2.blocks.5faf51e2-d957-4b46-ac23-f313b0e3f1fe": {
          "data": {
            "address1": null
          }
        }
      },
      "calls": [
        {
          "path": "",
          "method": "save",
          "params": []
        }
      ]
    }
  ]
}

Error is thrown from Undefined array key "type" but appears to be issue from the Livewire request

public function getChildComponentContainers(bool $withHidden = false): array
    {
        return collect($this->getState())
            ->filter(fn (array $itemData): bool => $this->hasBlock($itemData['type']))

https://github.com/filamentphp/filament/assets/533658/f512bb8e-8d39-4550-a64c-2f0201d52119

Expected behavior

Save to work each time.

Steps to reproduce

Reproduction repository

https://github.com/howdu/filament-tester

Relevant log output

No response

Focusnik commented 1 year ago

Still relevant on liveware 3.0.0-beta10

pboivin commented 1 year ago

Related to https://github.com/filamentphp/filament/issues/7450

danharrin commented 1 year ago

I believe livewire/livewire#6521 is a failing test for this

lukas-frey commented 1 year ago

Can confirm this. It happens with any kind of "repeating" component, such as Builder, Repeater, etc.

After you add an item, remove it and then repeat the same process it will throw that error.

EDIT: sorry, didn't realise that it was already fixed and waiting for release in Livewire :)

howdu commented 1 year ago

Fixed in Livewire v3.0.2