Fix spell check callback causing input clearing issues

- Remove value dependency from performSpellCheck useCallback to prevent recreation
- Use direct DOM access via hiddenTextareaRef for current value comparison
- Prevent stale spell check results from interfering with active typing
- Fixes issue where input would clear or stop recording when spell check highlights mid-word
This commit is contained in:
spencrmartin
2025-09-25 13:15:50 -04:00
parent 174ae08ee0
commit c2f7d7aab9
+8 -3
View File
@@ -283,8 +283,12 @@ export const RichChatInput = forwardRef<RichChatInputRef, RichChatInputProps>(({
const misspelledWords = await checkSpelling(text);
console.log('🔍 ELECTRON SPELL CHECK: System spell check result:', misspelledWords);
// Critical: Check current value at time of update, not captured value
const currentValue = hiddenTextareaRef.current?.value || '';
// Only update if the text hasn't changed since we started checking
if (text === value) {
if (text === currentValue) {
// Use functional update to avoid dependency on value in useCallback
setMisspelledWords(misspelledWords);
lastSpellCheckedTextRef.current = text;
} else {
@@ -293,11 +297,12 @@ export const RichChatInput = forwardRef<RichChatInputRef, RichChatInputProps>(({
} catch (error) {
console.error('🔍 ELECTRON SPELL CHECK: Error performing spell check:', error);
// Fallback to no spell checking on error
if (text === value) {
const currentValue = hiddenTextareaRef.current?.value || '';
if (text === currentValue) {
setMisspelledWords([]);
}
}
}, [value]);
}, []); // Remove value dependency to prevent recreation
// Smart spell check timing - check after word completion and with shorter delays
useEffect(() => {