Skip to content

fix: re-index state array after block deletion to prevent undefined k…#21

Merged
GigaGiorgadze merged 4 commits intomainfrom
fix/reindex-state-after-block-delete
Mar 2, 2026
Merged

fix: re-index state array after block deletion to prevent undefined k…#21
GigaGiorgadze merged 4 commits intomainfrom
fix/reindex-state-after-block-delete

Conversation

@Davitamgl
Copy link
Collaborator

🐛 Fix: Crash when deleting blocks sequentially

Closes #15


Problem

Deleting the first block then trying to delete any remaining block threw:

ErrorException: Undefined array key 0

After unset($items[0]), PHP keeps the original keys — so the array goes from [0, 1, 2] to [1, 2]. The blade template always passes $loop->index (0-based) as the index argument. On the next delete, it sends index = 0, but key 0 no longer exists in the state array.


Fix

Use array_values() after unsetting to reset keys back to 0, 1, 2...

// Before
$component->state($items);

// After
$component->state(array_values($items));

Test

Added a regression test that creates 2 blocks, deletes the first, then deletes the second — covering the exact scenario that was broken.

@GigaGiorgadze GigaGiorgadze self-requested a review March 2, 2026 08:48
@GigaGiorgadze GigaGiorgadze merged commit e1e381e into main Mar 2, 2026
16 checks passed
@GigaGiorgadze GigaGiorgadze deleted the fix/reindex-state-after-block-delete branch March 2, 2026 12:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Undefined array key 0

2 participants