fix(git-panel): improve commit expansion logic and fetch diff condition

This commit is contained in:
Haileyesus
2026-02-23 11:46:04 +03:00
parent 3a8741b32d
commit e2951b66fa

View File

@@ -24,21 +24,24 @@ export default function HistoryView({
const toggleCommitExpanded = useCallback( const toggleCommitExpanded = useCallback(
(commitHash: string) => { (commitHash: string) => {
const isExpanding = !expandedCommits.has(commitHash);
setExpandedCommits((previous) => { setExpandedCommits((previous) => {
const next = new Set(previous); const next = new Set(previous);
if (next.has(commitHash)) { if (next.has(commitHash)) {
next.delete(commitHash); next.delete(commitHash);
} else { } else {
next.add(commitHash); next.add(commitHash);
// Load commit diff lazily only the first time a commit is expanded.
if (!commitDiffs[commitHash]) {
void onFetchCommitDiff(commitHash);
}
} }
return next; return next;
}); });
// Load commit diff lazily only the first time a commit is expanded.
if (isExpanding && !commitDiffs[commitHash]) {
void onFetchCommitDiff(commitHash);
}
}, },
[commitDiffs, onFetchCommitDiff], [commitDiffs, expandedCommits, onFetchCommitDiff, setExpandedCommits],
); );
return ( return (