authorgravatar for 206951365+cursor[bot]@users.noreply.github.comcursor[bot] <206951365+cursor[bot]@users.noreply.github.com> 2026-06-23 11:47:26-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2026-06-23 11:47:26-07:00
logc6c64918f8c582cc8b12de155d6c9aae12037147
treefd84fba317dac5412b9ea499eac7d01190e8e7c5
parent4abf8b46c591ae2b36aa29598c388100df651411
signature Signed by PGP key B5690EEEBB952194

Reduce ChatMarkdown settings rerenders (#3536)

Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Julius Marminge <juliusmarminge@users.noreply.github.com>

1 files changed, 7 insertions(+), 3 deletions(-)

apps/web/src/components/ChatMarkdown.tsx+7-3
...@@ -54,7 +54,7 @@ import { resolveDiffThemeName, type DiffThemeName } from "../lib/diffRendering";...@@ -54,7 +54,7 @@ import { resolveDiffThemeName, type DiffThemeName } from "../lib/diffRendering";
54import { fnv1a32 } from "../lib/diffRendering";54import { fnv1a32 } from "../lib/diffRendering";
55import { LRUCache } from "../lib/lruCache";55import { LRUCache } from "../lib/lruCache";
56import { useTheme } from "../hooks/useTheme";56import { useTheme } from "../hooks/useTheme";
57import { useClientSettings } from "../hooks/useSettings";57import { getClientSettings } from "../hooks/useSettings";
58import {58import {
59 chatMarkdownClipboardPayload,59 chatMarkdownClipboardPayload,
60 serializeTableElementToCsv,60 serializeTableElementToCsv,
...@@ -293,10 +293,14 @@ function getHighlighterPromise(language: string): Promise<DiffsHighlighter> {...@@ -293,10 +293,14 @@ function getHighlighterPromise(language: string): Promise<DiffsHighlighter> {
293 return promise;293 return promise;
294}294}
295295
296function readInitialWordWrapSetting(): boolean {
297 return getClientSettings().wordWrap;
298}
299
296function MarkdownTable({ children, ...props }: React.ComponentProps<"table">) {300function MarkdownTable({ children, ...props }: React.ComponentProps<"table">) {
297 const containerRef = useRef<HTMLDivElement | null>(null);301 const containerRef = useRef<HTMLDivElement | null>(null);
298 const tableRef = useRef<HTMLTableElement | null>(null);302 const tableRef = useRef<HTMLTableElement | null>(null);
299 const [expanded, setExpanded] = useState(useClientSettings((settings) => settings.wordWrap));303 const [expanded, setExpanded] = useState(readInitialWordWrapSetting);
300 const [copied, setCopied] = useState(false);304 const [copied, setCopied] = useState(false);
301 const copiedTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);305 const copiedTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
302 const expandLabel = expanded ? "Collapse table cells" : "Expand table cells";306 const expandLabel = expanded ? "Collapse table cells" : "Expand table cells";
...@@ -526,7 +530,7 @@ function MarkdownCodeBlock({...@@ -526,7 +530,7 @@ function MarkdownCodeBlock({
526 children: ReactNode;530 children: ReactNode;
527}) {531}) {
528 const [copied, setCopied] = useState(false);532 const [copied, setCopied] = useState(false);
529 const [wrapped, setWrapped] = useState(useClientSettings((settings) => settings.wordWrap));533 const [wrapped, setWrapped] = useState(readInitialWordWrapSetting);
530 const copiedTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);534 const copiedTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
531 const wrapLabel = wrapped ? "Disable line wrap" : "Wrap lines";535 const wrapLabel = wrapped ? "Disable line wrap" : "Wrap lines";
532 const copyLabel = copied ? "Copied" : "Copy code";536 const copyLabel = copied ? "Copied" : "Copy code";