Skip to content

Commit 8cb4354

Browse files
author
Theodore Li
committed
Fix chat switch selection
1 parent d272d54 commit 8cb4354

File tree

1 file changed

+18
-3
lines changed
  • apps/sim/app/workspace/[workspaceId]/home/components/mothership-view/components/resource-tabs

1 file changed

+18
-3
lines changed

apps/sim/app/workspace/[workspaceId]/home/components/mothership-view/components/resource-tabs/resource-tabs.tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,15 @@ export function ResourceTabs({
185185
const dragStartIdx = useRef<number | null>(null)
186186
const autoScrollRaf = useRef<number | null>(null)
187187
const anchorIdRef = useRef<string | null>(null)
188+
const prevChatIdRef = useRef(chatId)
189+
190+
// Reset selection when switching chats — component instance persists across
191+
// chat switches so stale IDs would otherwise carry over.
192+
if (prevChatIdRef.current !== chatId) {
193+
prevChatIdRef.current = chatId
194+
setSelectedIds(new Set())
195+
anchorIdRef.current = null
196+
}
188197

189198
const existingKeys = useMemo(
190199
() => new Set(resources.map((r) => `${r.type}:${r.id}`)),
@@ -261,9 +270,15 @@ export function ResourceTabs({
261270
for (const r of targets) {
262271
onRemoveResource(r.type, r.id)
263272
}
264-
if (isMulti) {
265-
setSelectedIds(new Set())
266-
anchorIdRef.current = null
273+
// Clear stale selection and anchor for all removed targets
274+
const removedIds = new Set(targets.map((r) => r.id))
275+
setSelectedIds((prev) => {
276+
const next = new Set(prev)
277+
for (const id of removedIds) next.delete(id)
278+
return next
279+
})
280+
if (anchorIdRef.current && removedIds.has(anchorIdRef.current)) {
281+
anchorIdRef.current = activeId
267282
}
268283
// Serialize mutations so each onMutate sees the cache updated by the prior
269284
// one. Continue on individual failures so remaining removals still fire.

0 commit comments

Comments
 (0)