fix: repopulate corrupts repeat groups when rows are deleted on the server (#1940)#2008
Open
clinnygee wants to merge 1 commit into
Open
fix: repopulate corrupts repeat groups when rows are deleted on the server (#1940)#2008clinnygee wants to merge 1 commit into
clinnygee wants to merge 1 commit into
Conversation
…erver (issue #1940) The Value Restoration step in getFilteredItemsToRepopulate spliced accepted deletions out of serverQRItems inside the same forward loop that fills unselected slots from current values. Splicing shifted unvisited deletion markers into already-visited indices (so they leaked into the QuestionnaireResponse) and re-opened their vacated tail slots to be re-filled from current values, resurrecting the deleted rows as duplicates. Split the loop into two passes: fill unselected slots first, then filter out all items marked with the mark-as-deleted extension. This also strips the internal marker extension from the final response and drops sparse-array holes. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes the re-opened part of #1940, reported by Liam: when rows are deleted on the server between repopulations, the repopulate dialog correctly identifies the deletions, but applying them corrupts the form — deleted rows are resurrected/duplicated, and the internal
mark-as-deletedextension leaks into theQuestionnaireResponse.Root cause
The Value Restoration step in
getFilteredItemsToRepopulate(itemsToRepopulateSelector.ts) did two things in one forward loop overserverQRItems:spliceout items marked with themark-as-deletedextensionSplicing in-place while iterating forward without adjusting
imeant:undefinedagain, so the fill branch re-filled it fromcurrentQRItems— resurrecting the row the user had just accepted as deleted.Concrete trace — form has rows
[A, B, C]; A and B deleted on the server (server returns[C]); user accepts both deletions in the dialog:current = [C, A, B],server = [C]— dialog correctly shows "A removed", "B removed" ✓server = [_, A+del, B+del]i=0fills C →i=1splices A+del (B+del shifts to index 1, skipped) →i=2now empty, re-filled with B from current[C, B+del, B]instead of the promised[C]Fix
Split the loop into two passes: fill all unselected slots first, then
filter()out every item carrying themark-as-deletedextension. This also strips the internal marker so it never enters theQuestionnaireResponse, and drops any holes left in the sparse array.Tests
Added regression tests modelling the scenario above:
mark-as-deletedextension does not leak into the resultAll three fail against the previous code and pass with the fix (verified by stash-reverting the fix and re-running).
🤖 Generated with Claude Code