Skip to content

Commit ecbb22b

Browse files
authored
Merge pull request #14340 from coleshirley/fix-parent-component-dehydrate-state-when-hidden
Fix parent component dehydrate state when hidden
2 parents ef7729a + 80fcd8b commit ecbb22b

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

packages/forms/src/Components/Concerns/HasState.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,11 @@ public function dehydrateState(array &$state, bool $isDehydrated = true): void
192192
}
193193
}
194194

195-
foreach ($this->getChildComponentContainers() as $container) {
196-
if ($container->isHidden()) {
197-
continue;
198-
}
195+
if ($this->isHiddenAndNotDehydrated()) {
196+
return;
197+
}
199198

199+
foreach ($this->getChildComponentContainers(withHidden: true) as $container) {
200200
$container->dehydrateState($state, $isDehydrated);
201201
}
202202
}

tests/src/Forms/StateTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,25 @@
487487

488488
expect($container)
489489
->dehydrateState()->not()->toBe([]);
490+
491+
$container = ComponentContainer::make(Livewire::make())
492+
->statePath('data')
493+
->components([
494+
(new Component)
495+
->id('parent')
496+
->hidden()
497+
->dehydratedWhenHidden()
498+
->childComponents([
499+
(new Component)
500+
->id('child')
501+
->statePath(Str::random())
502+
->default(Str::random()),
503+
]),
504+
])
505+
->fill();
506+
507+
expect($container)
508+
->dehydrateState()->not()->toBe([]);
490509
});
491510

492511
test('disabled components are excluded from state dehydration', function () {

0 commit comments

Comments
 (0)