Merge pull request #16419 from alanost/test/dehydration-issues-section

Hidden fields in Section incorrectly dehydrated in Section with state path
This commit is contained in:
Dan Harrin
2025-06-10 16:36:31 +01:00
committed by GitHub
2 changed files with 23 additions and 1 deletions
@@ -189,7 +189,7 @@ trait HasState
// we need to dehydrate the child component containers while
// informing them that they are not dehydrated, so that their
// child components get removed from the state.
foreach ($this->getChildComponentContainers() as $container) {
foreach ($this->getChildComponentContainers(withHidden: true) as $container) {
$container->dehydrateState($state, isDehydrated: false);
}
+22
View File
@@ -599,6 +599,28 @@ test('hidden components are not excluded from state dehydration if there is anot
->dehydrateState()->data->not()->toBe([]);
});
test('components in a hidden parent component with a grandparent component with a state path are excluded from state dehydration', function () {
$container = ComponentContainer::make(Livewire::make())
->statePath('data')
->components([
(new Component)
->statePath('data')
->schema([
(new Component)
->schema([
(new Component)
->statePath(Str::random())
->default(Str::random()),
])
->hidden(),
]),
])
->fill();
expect($container)
->dehydrateState()->toBe(['data' => ['data' => []]]);
});
test('disabled components are excluded from state dehydration', function () {
$container = ComponentContainer::make(Livewire::make())
->statePath('data')