Update index.tsx

This commit is contained in:
lin onetwo 2025-11-20 00:36:39 +08:00
parent 5115116427
commit 009e4ca848

View file

@ -226,8 +226,9 @@ export default function GitHistory(): React.JSX.Element {
}, [lastChangeType, entries, setSelectedCommit]); }, [lastChangeType, entries, setSelectedCommit]);
// Maintain selection across refreshes by hash // Maintain selection across refreshes by hash
// Skip if we should select first (manual commit) or if a commit just happened (auto-selection in progress)
useEffect(() => { useEffect(() => {
if (selectedCommit && entries.length > 0) { if (selectedCommit && entries.length > 0 && !shouldSelectFirst && lastChangeType !== 'commit') {
// Try to find the same commit in the new entries // Try to find the same commit in the new entries
const stillExists = entries.find((entry) => entry.hash === selectedCommit.hash); const stillExists = entries.find((entry) => entry.hash === selectedCommit.hash);
// Only update if data actually changed (compare by serialization) // Only update if data actually changed (compare by serialization)
@ -236,7 +237,7 @@ export default function GitHistory(): React.JSX.Element {
setSelectedCommit(stillExists); setSelectedCommit(stillExists);
} }
} }
}, [entries, selectedCommit]); }, [entries, selectedCommit, shouldSelectFirst, lastChangeType]);
const handleCommitSuccess = () => { const handleCommitSuccess = () => {
// Trigger selection of first commit after data refreshes // Trigger selection of first commit after data refreshes