Skip to content

Commit

Permalink
Merge pull request #14340 from coleshirley/fix-parent-component-dehyd…
Browse files Browse the repository at this point in the history
…rate-state-when-hidden

Fix parent component dehydrate state when hidden
  • Loading branch information
danharrin authored Oct 8, 2024
2 parents ef7729a + 80fcd8b commit ecbb22b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/forms/src/Components/Concerns/HasState.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,11 @@ public function dehydrateState(array &$state, bool $isDehydrated = true): void
}
}

foreach ($this->getChildComponentContainers() as $container) {
if ($container->isHidden()) {
continue;
}
if ($this->isHiddenAndNotDehydrated()) {
return;
}

foreach ($this->getChildComponentContainers(withHidden: true) as $container) {
$container->dehydrateState($state, $isDehydrated);
}
}
Expand Down
19 changes: 19 additions & 0 deletions tests/src/Forms/StateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,25 @@

expect($container)
->dehydrateState()->not()->toBe([]);

$container = ComponentContainer::make(Livewire::make())
->statePath('data')
->components([
(new Component)
->id('parent')
->hidden()
->dehydratedWhenHidden()
->childComponents([
(new Component)
->id('child')
->statePath(Str::random())
->default(Str::random()),
]),
])
->fill();

expect($container)
->dehydrateState()->not()->toBe([]);
});

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

0 comments on commit ecbb22b

Please sign in to comment.