fix(ui): deleted array item reappears after reorder with autosave#15906
Conversation
There was a problem hiding this comment.
Hey @ed-cscosta, thanks for the PR!
I found an edge case with nested arrays that might be an issue. When checking a path like blocks.0.items.1.text, your implementation stops at the first matching array (blocks) and doesn't verify the inner array (blocks.0.items).
This means if the inner array is reordered but the outer one isn't, stale data gets accepted.
I've added a couple test cases that covers this scenario and should fail with your current approach. The fix needs to check the deepest array level in the path rather than the first match.
I can go ahead and implement this in your PR
|
Both CI failures are unrelated to this PR:
|
…es to prevent stale data from overwriting the wrong row during autosave merges
…host-item-autosave-reorder
|
@ed-cscosta I reviewed your approach and came up with a bit of a simpler implementation that parses array paths on-demand instead of pre-computing Maps. It achieves the same result but with a bit less overhead. Really appreciate your work on this! |
…host-item-autosave-reorder
Overview
Fixes deleted array items reappearing after reordering with autosave enabled.
Key Changes
Added row ID validation in
mergeServerFormStatebefore accepting server values for array fieldsSyncs the
valuefield to match actual row count after merging when they differDesign Decisions
When rows are reordered or deleted while an autosave request is in-flight, the same index can point to different rows in client vs server state. For example, after reordering
[A, B, C] → [C, A, B]and deleting A, the client has[C, B]but the server responds with[C, A, B]. Without validation,array.1.textwould get A's stale data instead of B's current data.The fix parses paths right-to-left to find the deepest numeric index, ensuring nested arrays are handled correctly (e.g.,
blocks.0.items.1.textchecksblocks.0.items[1], notblocks[0]).During autosave with
overrideLocalChanges: false, the client is source of truth for structural changes made while the request was pending.Fixes #15889