Skip to content

Commit 796b96c

Browse files
committed
Refactor TabBar component to filter unique tabs and prevent duplicate entries in the useSandbox hook
1 parent cd2e292 commit 796b96c

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

web/src/components/file-preview-panel.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,24 @@ function TabBar({
157157
activeEl?.scrollIntoView({ behavior: "smooth", block: "nearest", inline: "nearest" });
158158
}, [activeTabPath]);
159159

160-
if (tabs.length === 0) return null;
160+
const uniqueTabs = useMemo(() => {
161+
const seen = new Set<string>();
162+
return tabs.filter((t) => {
163+
if (seen.has(t.path)) return false;
164+
seen.add(t.path);
165+
return true;
166+
});
167+
}, [tabs]);
168+
169+
if (uniqueTabs.length === 0) return null;
161170

162171
return (
163172
<div
164173
ref={scrollRef}
165174
className="flex overflow-x-auto border-b bg-muted/20 shrink-0"
166175
style={{ scrollbarWidth: "none" }}
167176
>
168-
{tabs.map((tab) => {
177+
{uniqueTabs.map((tab) => {
169178
const name = tab.path.split("/").pop() ?? tab.path;
170179
const isActive = tab.path === activeTabPath;
171180
const mode = tabModes[tab.path] ?? "view";

web/src/lib/use-sandbox.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ export function useSandbox(isActive = false) {
106106

107107
const newTab: Tab = { path, content: null, loading: true };
108108
setTabs((prev) => {
109+
if (prev.some((t) => t.path === path)) return prev;
109110
const next = [...prev, newTab];
110111
tabsRef.current = next;
111112
return next;

0 commit comments

Comments
 (0)