fix: Prevent hidden builder fields from breaking repeaters (#19676)

* test: add test for saving builder block with repeater and hidden field

* fix: Prevent hidden builder fields from breaking repeaters
This commit is contained in:
RenHai Wen
2026-04-13 10:08:16 +01:00
committed by GitHub
parent 790376b450
commit 08dd068675
2 changed files with 55 additions and 1 deletions
@@ -381,11 +381,17 @@ trait HasState
$container = $this->getContainer();
while ($parentComponent = $container->getParentComponent()) {
$parentContainer = $parentComponent->getContainer();
if ($parentComponent->hasStatePath()) {
break;
}
$container = $parentComponent->getContainer();
if ($parentContainer->getStatePath() !== $container->getStatePath()) {
break;
}
$container = $parentContainer;
}
foreach ($container->getFlatComponents(withActions: false, withHidden: true) as $component) {
@@ -278,6 +278,13 @@ it('can access correct block state from `extraItemActions()`', function (): void
$undoBuilderFake();
});
it('can save a builder block containing a repeater and hidden field', function (): void {
livewire(TestComponentWithBuilderRepeaterAndHiddenField::class)
->assertSuccessful()
->call('save')
->assertHasNoFormErrors();
});
class TestComponentWithActionInBuilder extends Livewire
{
public function mount(): void
@@ -342,6 +349,47 @@ class TestComponentWithExtraItemActionInBuilder extends Livewire
}
}
class TestComponentWithBuilderRepeaterAndHiddenField extends Livewire
{
public function form(Schema $form): Schema
{
return $form
->components([
Builder::make('builder')
->blocks([
Builder\Block::make('services')
->schema([
Repeater::make('items')
->schema([
TextInput::make('service')
->required(),
]),
TextInput::make('hidden')
->visible(false),
]),
])
->default([
[
'type' => 'services',
'data' => [
'items' => [
[
'service' => 'Service 1',
],
],
],
],
]),
])
->statePath('data');
}
public function save(): void
{
$this->form->getState();
}
}
describe('properties', function (): void {
it('can set `addActionLabel()` and get with `getAddActionLabel()`', function (): void {
$builder = Builder::make('content')