fix: Improve History panel performance and fix type duplications

- Remove duplicate GlobalStats interface from types (was causing conflicts)
- Only track scroll position when on Files tab (prevent unnecessary updates)
- Memoize activeSession to reduce re-render cascades
- Wrap HistoryPanel in React.memo to prevent unnecessary re-renders
This commit is contained in:
Pedram Amini
2025-11-26 17:22:58 -06:00
parent 68e319c7a7
commit 7bc1d3df01
4 changed files with 13 additions and 19 deletions

View File

@@ -782,7 +782,10 @@ export default function MaestroConsole() {
// Keyboard navigation state
const [selectedSidebarIndex, setSelectedSidebarIndex] = useState(0);
const activeSession = sessions.find(s => s.id === activeSessionId) || sessions[0] || null;
const activeSession = useMemo(() =>
sessions.find(s => s.id === activeSessionId) || sessions[0] || null,
[sessions, activeSessionId]
);
const theme = THEMES[activeThemeId];
const anyTunnelActive = sessions.some(s => s.tunnelActive);

View File

@@ -13,7 +13,7 @@ export interface HistoryPanelHandle {
focus: () => void;
}
export const HistoryPanel = forwardRef<HistoryPanelHandle, HistoryPanelProps>(function HistoryPanel({ session, theme, onJumpToClaudeSession }, ref) {
export const HistoryPanel = React.memo(forwardRef<HistoryPanelHandle, HistoryPanelProps>(function HistoryPanel({ session, theme, onJumpToClaudeSession }, ref) {
const [historyEntries, setHistoryEntries] = useState<HistoryEntry[]>([]);
const [activeFilters, setActiveFilters] = useState<Set<HistoryEntryType>>(new Set(['AUTO', 'USER']));
const [isLoading, setIsLoading] = useState(true);
@@ -392,4 +392,4 @@ export const HistoryPanel = forwardRef<HistoryPanelHandle, HistoryPanelProps>(fu
)}
</div>
);
});
}));

View File

@@ -164,10 +164,13 @@ export function RightPanel(props: RightPanelProps) {
}
}}
onScroll={(e) => {
const scrollTop = e.currentTarget.scrollTop;
setSessions(prev => prev.map(s =>
s.id === session.id ? { ...s, fileExplorerScrollPos: scrollTop } : s
));
// Only track scroll position for file explorer tab
if (activeRightTab === 'files') {
const scrollTop = e.currentTarget.scrollTop;
setSessions(prev => prev.map(s =>
s.id === session.id ? { ...s, fileExplorerScrollPos: scrollTop } : s
));
}
}}
>
{activeRightTab === 'files' && (

View File

@@ -216,15 +216,3 @@ export interface CustomAICommand {
isBuiltIn?: boolean; // If true, cannot be deleted (only edited)
}
// Persistent global stats that survive app restarts
export interface GlobalStats {
totalSessions: number;
totalMessages: number;
totalInputTokens: number;
totalOutputTokens: number;
totalCacheReadTokens: number;
totalCacheCreationTokens: number;
totalCostUsd: number;
totalActiveTimeMs: number;
lastUpdated: number; // Timestamp for tracking when stats were last updated
}