fix(search): stop redundant setState cascade in semantic-search effect#192
Open
rotecodefraktion wants to merge 1 commit into
Open
Conversation
The semantic-search effect depends on activeNotes and, in the early- return branch, called setSemanticResults([]) (a fresh array each time) plus two more setState calls on every pass. During a large note influx activeNotes changes in rapid batches, re-firing the effect and feeding a re-render cascade that hit 'Maximum update depth exceeded'. Route the resets through resetSemanticState(), which uses functional updaters that return the same reference when already-clear — a no-op in React. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
a8c6756 to
623e4f7
Compare
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.
What changed
The semantic-search effect (keyed on
activeNotes) calledsetSemanticResults([])— a fresh array each pass — plus two moresetStatecalls in its early-return branch. The resets now go throughresetSemanticState(), which uses functional updaters that return thesame reference when state is already clear, making the reset a no-op in
React.
Why
During a large note influx
activeNoteschanges in rapid batches,re-firing the effect. The always-fresh-array resets fed a re-render
cascade that could hit
Maximum update depth exceeded. Returning stablereferences breaks the cascade.
How it was tested
npm run lintnpm run typecheck(clean)npm test—semanticSearch,settingsSearch: 17 tests passnpm run build(verified on a sibling branch off the samedevbase)Notes
Single-file change (
src/components/modals/SearchModal.tsx).