Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion webview-ui/src/components/chat/ChatRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export const ChatRowContent = ({
const [editMode, setEditMode] = useState<Mode>(mode || "code")
const [editImages, setEditImages] = useState<string[]>([])
const { copyWithFeedback } = useCopyToClipboard()
const userEditRef = useRef<HTMLDivElement>(null)

// Handle message events for image selection during edit mode
useEffect(() => {
Expand Down Expand Up @@ -351,6 +352,22 @@ export const ChatRowContent = ({
return null
}, [message.type, message.ask, message.partial, message.text])

// Scroll to user edits when they appear
useEffect(() => {
if (message.say === "user_feedback_diff" && userEditRef.current) {
const tool = safeJsonParse<ClineSayTool>(message.text)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we improve performance here? This useEffect runs on every render when message.say === "user_feedback_diff". The tool is parsed twice - once in the condition check and once inside. Consider memoizing the parsed tool to avoid unnecessary JSON parsing on each render.

if (tool?.diff) {
// Use a small delay to ensure the element is rendered
setTimeout(() => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor suggestion: Consider extracting this magic number to a named constant like SCROLL_DELAY_MS = 100 at the top of the file for better maintainability and clarity about its purpose.

userEditRef.current?.scrollIntoView({
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intentional? The code assumes scrollIntoView is always available, but it might not be supported in all environments (e.g., during SSR or in test environments). Consider adding a safety check:

Suggested change
userEditRef.current?.scrollIntoView({
if (userEditRef.current?.scrollIntoView) {
userEditRef.current.scrollIntoView({
behavior: "smooth",
block: "center",
})
}

behavior: "smooth",
block: "center",
})
}, 100)
}
}
}, [message.say, message.text])

if (tool) {
const toolIcon = (name: string) => (
<span
Expand Down Expand Up @@ -1241,7 +1258,7 @@ export const ChatRowContent = ({
case "user_feedback_diff":
const tool = safeJsonParse<ClineSayTool>(message.text)
return (
<div style={{ marginTop: -10, width: "100%" }}>
<div ref={userEditRef} style={{ marginTop: -10, width: "100%" }}>
<CodeAccordian
code={tool?.diff}
language="diff"
Expand Down
Loading