Conversation
435818b to
b297cb5
Compare
60489f4 to
b53bdfb
Compare
f3e32fe to
ff1866d
Compare
…educe duplication with storybook stories
0e6df3a to
d123fb1
Compare
Fixes issue where clicking the kebab menu on find/replace results caused the program to blank out with "Tried to send payload while not connected" error. Changes: 1. Make focus event handler more conservative - require relatedTarget to be a valid Node to avoid spurious focus events during dropdown interactions 2. Add event.stopPropagation() to dropdown menu items to prevent event bubbling 3. In find.web-view.tsx handleFocusedResultChange: add silent error handling to prevent cascading failures if editor controller is temporarily unavailable 4. In find.web-view.tsx handleOpenAtResult: chain selectRange and setAnnotation calls sequentially to ensure stable connection state Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
| return () => { | ||
| clearTimeout(saveSearchTermTimeoutRef.current); | ||
| setLastSearchTermSetting?.(searchTerm); | ||
| }; |
There was a problem hiding this comment.
🟡 Effect cleanup writes stale search term to project settings on every keystroke
The cleanup function of the search-term persistence effect fires on every searchTerm change (since searchTerm is a dependency). Each cleanup invocation immediately writes the previous search term value to the project setting via setLastSearchTermSetting?.(searchTerm), because the closure captures the value from the previous render. For a user typing "hello", this produces the write sequence: "h", "he", "hel", "hell", then after 1 second "hello" — four unnecessary project-setting writes per word. Since setLastSearchTermSetting writes to a useProjectSetting-backed store (likely involving network/IPC), this creates unnecessary I/O on every keystroke.
Trace of the issue
When searchTerm changes from "a" to "ab":
- React runs cleanup from the previous effect:
setLastSearchTermSetting?.("a")— immediate write of stale value - React runs the new effect: sets a 1-second timeout for
"ab" - 1 second later:
setLastSearchTermSetting?.("ab")— final correct value
The cleanup should only clear the timeout; the eager write should be limited to unmount.
Was this helpful? React with 👍 or 👎 to provide feedback.
https://paratextstudio.atlassian.net/browse/PT-3897

Demo Video (had to zip it because it was just a little bit over the size limit for files):
replace-preview-options-picker.zip
This change is