Skip to content

[LiveComponent] Fix (de)hydration of DTO collections containing a null item - #4194

Merged
Kocal merged 1 commit into
symfony:3.xfrom
0xABCD01:fix/livecollection-null-item
Nov 3, 2026
Merged

Kocal merged 1 commit into
symfony:3.xfrom
0xABCD01:fix/livecollection-null-item

Conversation

@0xABCD01

@0xABCD01 0xABCD01 commented Nov 2, 2026

Copy link
Copy Markdown
Contributor
Q A
Bug fix? yes
New feature? no
Docs? no
Issues Fix #1384
License MIT

When a LiveProp holds DTO objects in an array and one item is null, dehydrating the component throws:

LogicException: The LiveProp "..." on component "..." is an array. We determined the array is full of "..." objects, but at least one key had a different value of "null".

That null item is the normal state after LiveCollectionTrait::addCollectionItem() adds a row whose form entry has not been filled in yet, so adding a row to a DTO-backed LiveCollectionType breaks the component as soon as the collection already holds at least one record.

LiveComponentHydrator::dehydrateValue() rejected every item that did not match the collection's object type. hydrateValue() had the mirror problem: it passed null items into hydrateObjectValue(), which cannot hydrate them.

This keeps null items as null in both directions. The added integration test runs a CustomerDetails[] prop holding one filled DTO and one null item through a full dehydrate/hydrate round trip.

@carsonbot carsonbot added Bug Bug Fix LiveComponent Status: Needs Review Needs to be reviewed labels Nov 2, 2026
@Kocal
Kocal force-pushed the fix/livecollection-null-item branch from 3fcbc78 to 52e32d6 Compare November 3, 2026 19:50
@carsonbot carsonbot added Status: Reviewed Has been reviewed by a maintainer and removed Status: Needs Review Needs to be reviewed labels Nov 3, 2026
@Kocal

Kocal commented Nov 3, 2026

Copy link
Copy Markdown
Member

Thank you @0xABCD01.

@Kocal
Kocal merged commit 05e6bfd into symfony:3.x Nov 3, 2026
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Bug Fix LiveComponent Status: Reviewed Has been reviewed by a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[LiveComponent] addCollectionItem don't work when using DTO as source

3 participants