fix(web): preserve Agents panel scroll position #9637
Closedf4llenz(GitHub profile, opens in a new tab)wants to merge 8 commits into
main fromrefs/pull/9637/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
- apps/web/src/components/AgentsPanel.tsx lines 546 to 551OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -528,6 +531,21 @@528531 threadId = null,529532 }: {530533 model: AgentPanelModel;534+ threadKey: string | null;531535 environmentId?: EnvironmentId | null;532536 threadId?: ThreadId | null;533537 }) {538+ const viewportRef = useRef<HTMLDivElement>(null);539+540+ useLayoutEffect(() => {541+ const viewport = viewportRef.current;542+ if (!model.hasAgents || threadKey === null || viewport === null) {543+ return;544+ }545+546+ viewport.scrollTop = agentsScrollTopByThreadKey.get(threadKey) ?? 0;547+548+ const captureScrollTop = () => {549+ agentsScrollTopByThreadKey.set(threadKey, viewport.scrollTop);550+ };551+ viewport.addEventListener("scroll", captureScrollTop, { passive: true });@@ -23,10 +23,11 @@2323 } from "@t3tools/client-runtime/state/subagentRuntime";2424 import type { EnvironmentId, ThreadId } from "@t3tools/contracts";2525 import { Bot, Braces, Check, ChevronDown, ChevronRight, X } from "lucide-react";26-import { useEffect, useRef, useState } from "react";26+import { useEffect, useLayoutEffect, useRef, useState } from "react";27272828 import { cn } from "~/lib/utils";2929 import { orchestrationEnvironment } from "~/state/orchestration";3030 import { ScrollArea } from "~/components/ui/scroll-area";3131 import { Button } from "~/components/ui/button";323233+const agentsScrollTopByThreadKey = new Map<string, number>();
- apps/web/src/components/AgentsPanel.tsx line 558OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -533,0 +538,21 @@538+ const viewportRef = useRef<HTMLDivElement>(null);539+540+ useLayoutEffect(() => {541+ const viewport = viewportRef.current;542+ if (!model.hasAgents || threadKey === null || viewport === null) {543+ return;544+ }545+546+ const restoredScrollTop = agentsScrollTopByThreadKey.get(threadKey) ?? 0;547+ viewport.scrollTop = restoredScrollTop;548+549+ const captureScrollTop = () => {550+ const maxScrollTop = Math.max(0, viewport.scrollHeight - viewport.clientHeight);551+ const savedScrollTop = agentsScrollTopByThreadKey.get(threadKey);552+ if (553+ savedScrollTop !== undefined &&554+ savedScrollTop > maxScrollTop &&555+ viewport.scrollTop === maxScrollTop556+ ) {557+ return;558+ }
juliusmarminge closed this
Sign in to join this conversation.


macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed