Repository navigation
Reset tool selection when a re-trace replaces the polygons - #202
Merged
Merged
Conversation
The trace page held the included-tool ids in a plain useState set. Every trace mints fresh uuids for its polygons, so a selection made before a re-trace survived it while referring to polygons that no longer existed. The counter then read "3 of 2 selected", and the save button stayed enabled for tools the backend would filter out on save. Move the selection into usePolygonSelection, which keeps it a subset of the polygons currently on screen. Ids that survive a re-trace stay selected; the rest are dropped. Deriving during render rather than pruning in an effect avoids a frame where the counter is wrong. The hook returns a plain (next: Set<string>) => void rather than a Dispatch<SetStateAction<...>>. The updater form it would otherwise permit receives the raw unpruned state, not the pruned set the hook hands back, so the narrower type keeps that trap out of reach. Closes #201 Signed-off-by: Jason Madigan <jason@jasonmadigan.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.
Summary
useState<Set<string>>on the trace page. Each trace mints fresh uuids for its polygons, so a selection made before a re-trace survived while pointing at polygons that no longer existed. The counter read "3 of 2 selected".handleSaveToLibraryposted the stale ids and the backend filtered them on save, so the button could offer to save 3 tools and save fewer.usePolygonSelectionnow owns the set and keeps it a subset of the polygons on screen. Pruning derives during render rather than in an effect, so there is no frame where the counter is wrong. Ids surviving a re-trace stay selected.polygonscovers all of them.(next: Set<string>) => voidrather than aDispatch<SetStateAction<...>>. The updater form the wider type permits would hand back the raw unpruned state, so the narrower type keeps that trap out of reach.Test evidence
pnpm test145 passed / 17 files (145 = 143 baseline + 2 added)make lintexit 0, 0 errors, 9 pre-existing warnings in untouched filesnpx tsc --noEmitexit 0Backend pytest not run: the diff touches no backend files.
The 9 hook tests were checked against deliberately broken pruning, not just against the fix. The referential-stability test was vacuous in an earlier revision (it reused one array reference, so the memo never recomputed and the assertion held even against broken logic); it now reassigns a fresh array and fails correctly when the stale-check is removed.
Closes #201