Skip to content

Commit 2af4ef5

Browse files
committed
Refactor chat components to utilize memoization for performance optimization rather than virtualization
- Removed all Virtuoso logic, replaced with normal stuff. - Updated `BrowserSessionRowContent` and `ChatRowContent` components to use `memo`. - Refactored scrolling logic in `ChatView`, ensuring smooth scrolling behavior and maintaining scroll position during row expansion. - Adjusted event handling for scroll and wheel events to better manage auto-scroll functionality and user interactions.
1 parent b196489 commit 2af4ef5

File tree

3 files changed

+1285
-1253
lines changed

3 files changed

+1285
-1253
lines changed

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

Lines changed: 77 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -419,85 +419,87 @@ interface BrowserSessionRowContentProps extends Omit<BrowserSessionRowProps, "me
419419
isStreaming: boolean
420420
}
421421

422-
const BrowserSessionRowContent = ({
423-
message,
424-
isExpanded,
425-
onToggleExpand,
426-
lastModifiedMessage,
427-
isLast,
428-
setMaxActionHeight,
429-
isStreaming,
430-
}: BrowserSessionRowContentProps) => {
431-
const { t } = useTranslation()
432-
const headerStyle: React.CSSProperties = {
433-
display: "flex",
434-
alignItems: "center",
435-
gap: "10px",
436-
marginBottom: "10px",
437-
}
422+
const BrowserSessionRowContent = memo(
423+
({
424+
message,
425+
isExpanded,
426+
onToggleExpand,
427+
lastModifiedMessage,
428+
isLast,
429+
setMaxActionHeight,
430+
isStreaming,
431+
}: BrowserSessionRowContentProps) => {
432+
const { t } = useTranslation()
433+
const headerStyle: React.CSSProperties = {
434+
display: "flex",
435+
alignItems: "center",
436+
gap: "10px",
437+
marginBottom: "10px",
438+
}
438439

439-
switch (message.type) {
440-
case "say":
441-
switch (message.say) {
442-
case "api_req_started":
443-
case "text":
444-
return (
445-
<div style={{ padding: "10px 0 10px 0" }}>
446-
<ChatRowContent
447-
message={message}
448-
isExpanded={isExpanded(message.ts)}
449-
onToggleExpand={() => {
450-
if (message.say === "api_req_started") {
451-
setMaxActionHeight(0)
452-
}
453-
onToggleExpand(message.ts)
454-
}}
455-
lastModifiedMessage={lastModifiedMessage}
456-
isLast={isLast}
457-
isStreaming={isStreaming}
440+
switch (message.type) {
441+
case "say":
442+
switch (message.say) {
443+
case "api_req_started":
444+
case "text":
445+
return (
446+
<div style={{ padding: "10px 0 10px 0" }}>
447+
<ChatRowContent
448+
message={message}
449+
isExpanded={isExpanded(message.ts)}
450+
onToggleExpand={() => {
451+
if (message.say === "api_req_started") {
452+
setMaxActionHeight(0)
453+
}
454+
onToggleExpand(message.ts)
455+
}}
456+
lastModifiedMessage={lastModifiedMessage}
457+
isLast={isLast}
458+
isStreaming={isStreaming}
459+
/>
460+
</div>
461+
)
462+
463+
case "browser_action":
464+
const browserAction = JSON.parse(message.text || "{}") as ClineSayBrowserAction
465+
return (
466+
<BrowserActionBox
467+
action={browserAction.action}
468+
coordinate={browserAction.coordinate}
469+
text={browserAction.text}
458470
/>
459-
</div>
460-
)
461-
462-
case "browser_action":
463-
const browserAction = JSON.parse(message.text || "{}") as ClineSayBrowserAction
464-
return (
465-
<BrowserActionBox
466-
action={browserAction.action}
467-
coordinate={browserAction.coordinate}
468-
text={browserAction.text}
469-
/>
470-
)
471-
472-
default:
473-
return null
474-
}
471+
)
475472

476-
case "ask":
477-
switch (message.ask) {
478-
case "browser_action_launch":
479-
return (
480-
<>
481-
<div style={headerStyle}>
482-
<span style={{ fontWeight: "bold" }}>{t("chat:browser.sessionStarted")}</span>
483-
</div>
484-
<div
485-
style={{
486-
borderRadius: 3,
487-
border: "1px solid var(--vscode-editorGroup-border)",
488-
overflow: "hidden",
489-
backgroundColor: CODE_BLOCK_BG_COLOR,
490-
}}>
491-
<CodeBlock source={`${"```"}shell\n${message.text}\n${"```"}`} forceWrap={true} />
492-
</div>
493-
</>
494-
)
473+
default:
474+
return null
475+
}
495476

496-
default:
497-
return null
498-
}
499-
}
500-
}
477+
case "ask":
478+
switch (message.ask) {
479+
case "browser_action_launch":
480+
return (
481+
<>
482+
<div style={headerStyle}>
483+
<span style={{ fontWeight: "bold" }}>{t("chat:browser.sessionStarted")}</span>
484+
</div>
485+
<div
486+
style={{
487+
borderRadius: 3,
488+
border: "1px solid var(--vscode-editorGroup-border)",
489+
overflow: "hidden",
490+
backgroundColor: CODE_BLOCK_BG_COLOR,
491+
}}>
492+
<CodeBlock source={`${"```"}shell\n${message.text}\n${"```"}`} forceWrap={true} />
493+
</div>
494+
</>
495+
)
496+
497+
default:
498+
return null
499+
}
500+
}
501+
},
502+
)
501503

502504
const BrowserActionBox = ({
503505
action,

0 commit comments

Comments
 (0)