From 8783aa6e184dd32dd2fd59dfcafe981c8c9a445f Mon Sep 17 00:00:00 2001 From: Arthur Bassi Date: Mon, 10 Aug 2026 13:37:56 -0300 Subject: [PATCH] fix(work-orders): keep mention cursor sync on current value [SH-217] --- src/components/common/comment-mention-composer.tsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) 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); };