fix: fillForm() merges list state into existing repeater record keys (#19339)

When `fillForm()` is called with list-style arrays (numeric keys) on a
repeater that has loaded existing relationship records (`record-{id}`
keys), `unsetMissingNumericArrayKeys()` only removes orphaned numeric
keys but leaves the old `record-{id}` keys intact. This causes both
key sets to coexist, leading to data duplication on save.

Adding `array_is_list($state)` to the condition ensures that when the
new state is a sequential list, all non-matching keys are removed —
including `record-{id}` keys — giving `fillForm()` proper replacement
semantics for list arrays.
This commit is contained in:
Alan
2026-02-27 13:47:35 +01:00
committed by GitHub
parent a741183221
commit aa50829496
@@ -90,7 +90,7 @@ trait InteractsWithForms
protected function unsetMissingNumericArrayKeys(array &$target, array $state): void
{
foreach ($target as $key => $value) {
if (is_numeric($key) && (! array_key_exists($key, $state))) {
if ((is_numeric($key) || array_is_list($state)) && (! array_key_exists($key, $state))) {
unset($target[$key]);
continue;