Skip to content

Commit fba8bef

Browse files
fix: plan content view losing scroll position on unmount (#1307)
Co-authored-by: Jonathan Mieloo <32547391+jonathanlab@users.noreply.github.com>
1 parent 4133fd3 commit fba8bef

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

apps/code/src/renderer/components/permissions/PlanContent.tsx

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,43 @@
11
import { Box } from "@radix-ui/themes";
2+
import { useEffect, useRef } from "react";
23
import ReactMarkdown from "react-markdown";
34
import remarkGfm from "remark-gfm";
45

6+
const planScrollPosition = new Map<string, number>();
7+
58
interface PlanContentProps {
9+
id: string;
610
plan: string;
711
}
812

9-
export function PlanContent({ plan }: PlanContentProps) {
13+
export function PlanContent({ id, plan }: PlanContentProps) {
14+
const scrollRef = useRef<HTMLDivElement>(null);
15+
16+
useEffect(() => {
17+
const el = scrollRef.current;
18+
if (!el) return;
19+
20+
const position = planScrollPosition.get(id);
21+
if (position !== undefined) {
22+
el.scrollTop = position;
23+
}
24+
25+
const handleScroll = () => {
26+
planScrollPosition.set(id, el.scrollTop);
27+
};
28+
29+
el.addEventListener("scroll", handleScroll, { passive: true });
30+
31+
return () => {
32+
el.removeEventListener("scroll", handleScroll);
33+
};
34+
}, [id]);
35+
1036
return (
11-
<Box className="max-h-[50vh] max-w-[750px] overflow-y-auto rounded-lg border-2 border-blue-6 bg-blue-2 p-4">
37+
<Box
38+
ref={scrollRef}
39+
className="max-h-[50vh] max-w-[750px] overflow-y-auto rounded-lg border-2 border-blue-6 bg-blue-2 p-4"
40+
>
1241
<Box className="plan-markdown text-blue-12">
1342
<ReactMarkdown remarkPlugins={[remarkGfm]}>{plan}</ReactMarkdown>
1443
</Box>

apps/code/src/renderer/features/sessions/components/session-update/PlanApprovalView.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ export function PlanApprovalView({
4040

4141
return (
4242
<Box className="my-3">
43-
{showPlanContent && planText && <PlanContent plan={planText} />}
43+
{showPlanContent && planText && (
44+
<PlanContent id={toolCall.toolCallId} plan={planText} />
45+
)}
4446

4547
{showResult && (
4648
<Flex align="center" gap="2" className="px-1">

0 commit comments

Comments
 (0)