Skip to content

Commit e0c5248

Browse files
committed
fix(chat): ensure edit area scrolls into view and clear timeout to avoid leaks
1 parent b28edab commit e0c5248

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

webview-ui/src/components/chat/ChatRow.tsx

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,14 +168,21 @@ export const ChatRowContent = ({
168168

169169
// Scroll to edit area when entering edit mode
170170
useEffect(() => {
171-
if (isEditing && editAreaRef.current) {
172-
// Use a small delay to ensure the DOM has updated
173-
setTimeout(() => {
174-
editAreaRef.current?.scrollIntoView({
175-
behavior: "smooth",
176-
block: "center",
177-
})
178-
}, 100)
171+
if (!isEditing) return
172+
173+
let cancelled = false
174+
const timeoutId = window.setTimeout(() => {
175+
if (cancelled) return
176+
editAreaRef.current?.scrollIntoView({
177+
behavior: "smooth",
178+
block: "center",
179+
inline: "nearest",
180+
})
181+
}, 100)
182+
183+
return () => {
184+
cancelled = true
185+
window.clearTimeout(timeoutId)
179186
}
180187
}, [isEditing])
181188

0 commit comments

Comments
 (0)