fix(webui): lazily render collapsed tool traces
Keep trace rows unmounted until their group is opened, then release them only after the closing disclosure transition finishes. Hidden historical traces should not allocate a DOM row per tool call merely to support animation. Add a 1,000-row regression test covering initial allocation, exit cleanup, rapid reopening, and subsequent expansion.
This commit is contained in:
1 parent
14f46d21fd
commit
11a03595f4
2 files changed
+46
-5
No files matched your search
@@ -936,12 +936,17 @@ function TraceGroup({ message }: TraceGroupProps) {
|
||||
const lines = message.traces ?? [message.content];
|
||||
const count = lines.length;
|
||||
const [open, setOpen] = useState(false);
|
||||
const [hasOpened, setHasOpened] = useState(false);
|
||||
const releaseContent = useCallback(() => setHasOpened(false), []);
|
||||
const contentId = useId();
|
||||
return (
|
||||
<div className="w-full">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setOpen((v) => !v)}
|
||||
onClick={() => {
|
||||
if (!open) setHasOpened(true);
|
||||
setOpen((value) => !value);
|
||||
}}
|
||||
className={cn(
|
||||
"group flex w-full items-center gap-2 rounded-md px-2 py-1.5",
|
||||
"text-xs text-muted-foreground transition-colors hover:bg-muted/45",
|
||||
@@ -963,8 +968,8 @@ function TraceGroup({ message }: TraceGroupProps) {
|
||||
)}
|
||||
/>
|
||||
</button>
|
||||
<DisclosureContent id={contentId} open={open}>
|
||||
<ul
|
||||
<DisclosureContent id={contentId} open={open} onExitComplete={releaseContent}>
|
||||
{hasOpened && <ul
|
||||
className="mt-1 space-y-0.5 border-l border-muted-foreground/20 pl-3"
|
||||
>
|
||||
{lines.map((line, i) => (
|
||||
@@ -975,7 +980,7 @@ function TraceGroup({ message }: TraceGroupProps) {
|
||||
{line}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</ul>}
|
||||
</DisclosureContent>
|
||||
</div>
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user