diff --git a/src/components/common/comment-mention-composer.tsx b/src/components/common/comment-mention-composer.tsx index 815969c4..63c84f22 100644 --- a/src/components/common/comment-mention-composer.tsx +++ b/src/components/common/comment-mention-composer.tsx @@ -35,6 +35,8 @@ export function CommentMentionComposer({ onSubmit, }: CommentMentionComposerProps) { const inputRef = useRef(null); + const valueRef = useRef(value); + valueRef.current = value; const [anchorEl, setAnchorEl] = useState(null); const [cursor, setCursor] = useState(0); const [menuOpen, setMenuOpen] = useState(false); @@ -59,12 +61,14 @@ export function CommentMentionComposer({ return; } - const nextCursor = element.selectionStart ?? value.length; + const currentValue = valueRef.current; + const nextCursor = element.selectionStart ?? currentValue.length; setCursor(nextCursor); - setMenuOpen(Boolean(findActiveMentionQuery(value, nextCursor))); - }, [value]); + setMenuOpen(Boolean(findActiveMentionQuery(currentValue, nextCursor))); + }, []); const handleChange = (nextValue: string) => { + valueRef.current = nextValue; onChange(nextValue); requestAnimationFrame(syncCursor); };