fix: Coordinate state loading for multiple Group->relationship() components #18827
+38
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes state overwrites when multiple
Group::make()->relationship()components access the same HasOne relationship across different tabs.Problem
The
saveRelationshipsBeforeChildrenUsingcallback already coordinates multiple Groups - only the first Group saves, collecting data from all Groups:However,
loadStateFromRelationshipsUsinglacks this coordination - it callsfillFromRelationship()for every Group, causing state overwrites:With 3+ Groups:
Errors:
foreach() argument must be of type array|object, string givenatBaseFileUpload.php:742Argument #2 ($rawState) must be of type ?array, string givenatRichEditor.php:346Solution
Apply the same coordination pattern from
saveRelationshipsBeforeChildrenUsingtoloadStateFromRelationshipsUsing:fillFromRelationship()(sets raw state + hydrates all)hydrateState()(state already set, applies StateCasts)Benefits
fillFromRelationship()unchangedhydrateState()Testing
Reproduction repo: https://github.com/iotron/filament-bug-reproduction
Verified both errors are fixed after applying this change.
Fixes #18826
Related to #18718, #18727