8000 Reset tool selection when a re-trace replaces the polygons by jasonmadigan · Pull Request #202 · tracefinity/tracefinity · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@jasonmadigan
Copy link
Copy Markdown
Collaborator

Summary

  • Selection of traced tools lived in a plain 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".
  • Not display-only, as the issue suspected: handleSaveToLibrary posted the stale ids and the backend filtered them on save, so the button could offer to save 3 tools and save fewer.
  • usePolygonSelection now 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.
  • Resetting at the call sites was rejected: three separate paths replace polygons, and a fourth would silently reintroduce the bug. Deriving from polygons covers all of them.
  • The hook returns (next: Set<string>) => void rather than a Dispatch<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 test 145 passed / 17 files (145 = 143 baseline + 2 added)
make lint exit 0, 0 errors, 9 pre-existing warnings in untouched files
npx tsc --noEmit exit 0

Backend 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

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>
@jasonmadigan
jasonmadigan marked this pull request as ready for review August 29, 2026 15:32
@jasonmadigan
jasonmadigan merged commit b2431ec into main Aug 29, 2026
6 checks passed
@jasonmadigan
jasonmadigan deleted the 201-retrace-selection-count branch August 29, 2026 15:32
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.

Selected tools count upon tracing carries over on re-trace

1 participant

0