Skip to content

fix(search): stop redundant setState cascade in semantic-search effect#192

Open
rotecodefraktion wants to merge 1 commit into
ipapakonstantinou:devfrom
rotecodefraktion:fix/search-semantic-setstate-cascade
Open

fix(search): stop redundant setState cascade in semantic-search effect#192
rotecodefraktion wants to merge 1 commit into
ipapakonstantinou:devfrom
rotecodefraktion:fix/search-semantic-setstate-cascade

Conversation

@rotecodefraktion

Copy link
Copy Markdown

What changed

The semantic-search effect (keyed on activeNotes) called
setSemanticResults([]) — a fresh array each pass — plus two more
setState calls in its early-return branch. The resets now go through
resetSemanticState(), which uses functional updaters that return the
same reference when state is already clear, making the reset a no-op in
React.

Why

During a large note influx activeNotes changes 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 stable
references breaks the cascade.

How it was tested

  • npm run lint
  • npm run typecheck (clean)
  • npm testsemanticSearch, settingsSearch: 17 tests pass
  • npm run build (verified on a sibling branch off the same dev base)
  • Sync change? n/a
  • UI change? No visual change.

Notes

Single-file change (src/components/modals/SearchModal.tsx).

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>
@rotecodefraktion rotecodefraktion force-pushed the fix/search-semantic-setstate-cascade branch from a8c6756 to 623e4f7 Compare June 15, 2026 07:19
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.

1 participant