@devries-cameron20 / t3code Mirror · read-only / commits / 724f54c2c1
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 25, 07:30 UTC

fix: clean up timeout in PlanSidebar to prevent memory leaks (#949)

Co-authored-by: hobostay <hobostay@users.noreply.github.com>

Qiaochu Hu committed Mar 13, 2026 at 03:32 UTC 724f54c2c1f4a1efcd7423a5ff0e3db625629815
1 file changed +18 -2
apps/web/src/components/PlanSidebar.tsx
+18 -2
@@ -1,4 +1,4 @@
1 -import { memo, useState, useCallback } from "react";
1 +import { memo, useState, useCallback, useRef, useEffect } from "react";
2 import { Badge } from "./ui/badge";
3 import { Button } from "./ui/button";
4 import { ScrollArea } from "./ui/scroll-area";
@@ -66,6 +66,7 @@ const PlanSidebar = memo(function PlanSidebar({
66 const [proposedPlanExpanded, setProposedPlanExpanded] = useState(false);
67 const [isSavingToWorkspace, setIsSavingToWorkspace] = useState(false);
68 const [copied, setCopied] = useState(false);
69 + const copiedTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
70
71 const planMarkdown = activeProposedPlan?.planMarkdown ?? null;
72 const displayedPlanMarkdown = planMarkdown ? stripDisplayedPlanMarkdown(planMarkdown) : null;
@@ -74,8 +75,15 @@ const PlanSidebar = memo(function PlanSidebar({
75 const handleCopyPlan = useCallback(() => {
76 if (!planMarkdown) return;
77 void navigator.clipboard.writeText(planMarkdown);
78 + if (copiedTimerRef.current != null) {
79 + clearTimeout(copiedTimerRef.current);
80 + }
81 +
82 setCopied(true);
78 - setTimeout(() => setCopied(false), 2000);
83 + copiedTimerRef.current = setTimeout(() => {
84 + setCopied(false);
85 + copiedTimerRef.current = null;
86 + }, 2000);
87 }, [planMarkdown]);
88
89 const handleDownload = useCallback(() => {
@@ -120,6 +128,14 @@ const PlanSidebar = memo(function PlanSidebar({
128 {/* Header */}
129 <div className="flex h-12 shrink-0 items-center justify-between border-b border-border/60 px-3">
130 <div className="flex items-center gap-2">
131 + // Cleanup timeout on unmount
132 + useEffect(() => {
133 + return () => {
134 + if (copiedTimerRef.current \!= null) {
135 + clearTimeout(copiedTimerRef.current);
136 + }
137 + };
138 + }, []);
139 <Badge
140 variant="secondary"
141 className="rounded-md bg-blue-500/10 px-1.5 py-0 text-[10px] font-semibold tracking-wide text-blue-400 uppercase"