fix(ui): memoize highlighted text [ENG-1355] (#7786)

* fix(ui): memoize highlighted text

Optimize UserMessage and TaskHeader components by using useMemo to cache highlighted text results. This prevents unnecessary recalculations of text highlighting on every render, improving performance when text or editedText props haven't changed.

Changes:
- Add useMemo hook to UserMessage component for highlightText result
- Replace inline highlightText calls with memoized values
- Reduces redundant text processing during re-renders

* add changeset
This commit is contained in:
Bee authored and GitHub committed 2025-12-01 10:50:56 -08:00
1 parent 0b0e8c36cb
commit 68b93fcbea
3 files changed
+10 -3

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
---
"claude-dev": patch
---
Fix highlighted text flashing when task header is collapsed.
@@ -1,6 +1,6 @@
import { CheckpointRestoreRequest } from "@shared/proto/cline/checkpoints"
import { ClineCheckpointRestore } from "@shared/WebviewMessage"
import React, { forwardRef, useRef, useState } from "react"
import React, { forwardRef, useMemo, useRef, useState } from "react"
import DynamicTextArea from "react-textarea-autosize"
import Thumbnails from "@/components/common/Thumbnails"
import { useExtensionState } from "@/context/ExtensionStateContext"
@@ -21,6 +21,8 @@ const UserMessage: React.FC<UserMessageProps> = ({ text, images, files, messageT
const textAreaRef = useRef<HTMLTextAreaElement>(null)
const { checkpointManagerErrorMessage } = useExtensionState()
const highlightedText = useMemo(() => highlightText(editedText || text), [editedText, text])
// Create refs for the buttons to check in the blur handler
const restoreAllButtonRef = useRef<HTMLButtonElement>(null)
const restoreChatButtonRef = useRef<HTMLButtonElement>(null)
@@ -146,7 +148,7 @@ const UserMessage: React.FC<UserMessageProps> = ({ text, images, files, messageT
</>
) : (
<span className="ph-no-capture text-sm" style={{ display: "block" }}>
{highlightText(editedText || text)}
{highlightedText}
</span>
)}
{((images && images.length > 0) || (files && files.length > 0)) && (
@@ -156,7 +156,7 @@ const TaskHeader: React.FC<TaskHeaderProps> = ({
<div className="flex items-center select-none grow min-w-0 gap-1 justify-between">
{!isTaskExpanded && (
<div className="whitespace-nowrap overflow-hidden text-ellipsis grow min-w-0">
<span className="ph-no-capture text-base">{highlightText(task.text, false)}</span>
<span className="ph-no-capture text-base">{highlightedText}</span>
</div>
)}
</div>