perf(webui): reduce repeated work and bound history rendering (#5703)

* perf(webui): reduce repeated work and bound history rendering

* fix(webui): keep continuation reasoning with its answer

* refactor(webui): reuse answer buffers and prepared copy text

* perf(webui): restore conditional replay buffer initialization

* fix(webui): remove code block pagination
This commit is contained in:
chengyongru authored and GitHub committed 2026-09-09 14:02:26 +08:00
1 parent 1c451b5b5f
commit 1469d4811c
32 files changed
+1156 -361

No files matched your search

+6 -5
View File
@@ -1,4 +1,4 @@
import { Suspense, lazy, useCallback, useState, type ReactNode } from "react";
import { Suspense, lazy, useCallback, useMemo, useState, type ReactNode } from "react";
import { Check, Copy } from "lucide-react";
import { useTranslation } from "react-i18next";
@@ -138,7 +138,7 @@ function CodeTextBlock({
className?: string;
renderText?: (value: string) => ReactNode;
}) {
const lines = code.split("\n");
const lines = showLineNumbers ? code.split("\n") : [];
return (
<pre
className={cn(
@@ -184,19 +184,20 @@ export function CodeBlock({
}: CodeBlockProps) {
const { t } = useTranslation();
const [copied, setCopied] = useState(false);
const renderAnsi = useMemo(() => shouldRenderAnsi(language, code), [language, code]);
const plainCode = useMemo(() => renderAnsi ? stripAnsi(code) : code, [renderAnsi, code]);
const isDark = useThemeValue() === "dark";
const hasChrome = chrome === "default";
const renderAnsi = shouldRenderAnsi(language, code);
const syntaxLanguage = normalizeCodeLanguage(language);
const copyLabel = copied ? t("code.copied") : t("code.copyAria");
const onCopy = useCallback(() => {
void copyTextToClipboard(renderAnsi ? stripAnsi(code) : code).then((ok) => {
void copyTextToClipboard(plainCode).then((ok) => {
if (!ok) return;
setCopied(true);
setTimeout(() => setCopied(false), 1_500);
});
}, [code, renderAnsi]);
}, [plainCode]);
return (
<div