- Deduplicate terminal IDs and favorite model slugs with trim-aware iteration - Use effect-based filtering for local branch and built-in model lists - Switch stable array handling to non-mutating `toSorted`
Showing the changes to apps/web/src/components/ThreadTerminalDrawer.tsx (1 of 8 files). Show all
Unified · Split
| @@ -870,7 +870,15 @@ export default function ThreadTerminalDrawer({ · 869 unmodified lines | ||
| 870 | 870 | const didResizeDuringDragRef = useRef(false); |
| 871 | 871 | |
| 872 | 872 | const normalizedTerminalIds = useMemo(() => { |
| 873 | − return [...new Set(terminalIds.map((id) => id.trim()).filter((id) => id.length > 0))]; | |
| 873 | + const normalizedIds: string[] = []; | |
| 874 | + const seen = new Set<string>(); | |
| 875 | + for (const id of terminalIds) { | |
| 876 | + const trimmedId = id.trim(); | |
| 877 | + if (trimmedId.length === 0 || seen.has(trimmedId)) continue; | |
| 878 | + seen.add(trimmedId); | |
| 879 | + normalizedIds.push(trimmedId); | |
| 880 | + } | |
| 881 | + return normalizedIds; | |
| 874 | 882 | }, [terminalIds]); |
| 875 | 883 | |
| 876 | 884 | const resolvedActiveTerminalId = |
| @@ -904,13 +912,17 @@ export default function ThreadTerminalDrawer({ · 27 unmodified lines | ||
| 904 | 912 | }; |
| 905 | 913 | |
| 906 | 914 | for (const terminalGroup of terminalGroups) { |
| 907 | − const nextTerminalIds = [ | |
| 908 | − ...new Set(terminalGroup.terminalIds.map((id) => id.trim()).filter((id) => id.length > 0)), | |
| 909 | − ].filter((terminalId) => { | |
| 910 | − if (!validTerminalIdSet.has(terminalId)) return false; | |
| 911 | − if (assignedTerminalIds.has(terminalId)) return false; | |
| 912 | − return true; | |
| 913 | − }); | |
| 915 | + const nextTerminalIds: string[] = []; | |
| 916 | + const seenGroupTerminalIds = new Set<string>(); | |
| 917 | + for (const id of terminalGroup.terminalIds) { | |
| 918 | + const terminalId = id.trim(); | |
| 919 | + if (terminalId.length === 0) continue; | |
| 920 | + if (seenGroupTerminalIds.has(terminalId)) continue; | |
| 921 | + seenGroupTerminalIds.add(terminalId); | |
| 922 | + if (!validTerminalIdSet.has(terminalId)) continue; | |
| 923 | + if (assignedTerminalIds.has(terminalId)) continue; | |
| 924 | + nextTerminalIds.push(terminalId); | |
| 925 | + } | |
| 914 | 926 | if (nextTerminalIds.length === 0) continue; |
| 915 | 927 | |
| 916 | 928 | for (const terminalId of nextTerminalIds) { |