fix(app): ignore stale repository open responses
This commit is contained in:
@@ -288,6 +288,7 @@
|
|||||||
let fileHistoryLoading = false;
|
let fileHistoryLoading = false;
|
||||||
let fileHistoryRequestId = 0;
|
let fileHistoryRequestId = 0;
|
||||||
let activeFileHistoryRequestId = "";
|
let activeFileHistoryRequestId = "";
|
||||||
|
let repoOpenRequestId = 0;
|
||||||
let lastFileHistoryHeadHash = "";
|
let lastFileHistoryHeadHash = "";
|
||||||
let commitMessage = "";
|
let commitMessage = "";
|
||||||
let amendMode = false;
|
let amendMode = false;
|
||||||
@@ -2031,6 +2032,7 @@
|
|||||||
async function openRepo(pathOverride?: string) {
|
async function openRepo(pathOverride?: string) {
|
||||||
const path = (pathOverride ?? repoPath).trim();
|
const path = (pathOverride ?? repoPath).trim();
|
||||||
if (!path) { errorMessage = "Enter a repository path."; return; }
|
if (!path) { errorMessage = "Enter a repository path."; return; }
|
||||||
|
const requestId = ++repoOpenRequestId;
|
||||||
repoPath = path;
|
repoPath = path;
|
||||||
|
|
||||||
await runOperation("Opening repository", async () => {
|
await runOperation("Opening repository", async () => {
|
||||||
@@ -2042,6 +2044,7 @@
|
|||||||
// Single backend round-trip: resolves the repo and reads status, branches,
|
// Single backend round-trip: resolves the repo and reads status, branches,
|
||||||
// commits and files in one pass instead of four sequential git calls.
|
// commits and files in one pass instead of four sequential git calls.
|
||||||
const bundle = await openRepositoryBundle(path, 100);
|
const bundle = await openRepositoryBundle(path, 100);
|
||||||
|
if (requestId !== repoOpenRequestId) return;
|
||||||
resetRepositoryState(false);
|
resetRepositoryState(false);
|
||||||
applyStatus(bundle.status);
|
applyStatus(bundle.status);
|
||||||
if (globalSearchBusy) void cancelGlobalSearch();
|
if (globalSearchBusy) void cancelGlobalSearch();
|
||||||
@@ -2235,8 +2238,18 @@
|
|||||||
|
|
||||||
if (!wasActive) return;
|
if (!wasActive) return;
|
||||||
if (next) {
|
if (next) {
|
||||||
|
// Switch identity immediately. Otherwise a status/fetch request for the
|
||||||
|
// just-closed repository can still finish while it remains active and
|
||||||
|
// reinsert its tab through applyStatus().
|
||||||
|
repoOpenRequestId += 1;
|
||||||
|
activeRepoPath = next.path;
|
||||||
|
repoPath = next.path;
|
||||||
|
status = null;
|
||||||
|
lastStatusFingerprint = "";
|
||||||
|
resetRepositoryState(false);
|
||||||
await openRepo(next.path);
|
await openRepo(next.path);
|
||||||
} else {
|
} else {
|
||||||
|
repoOpenRequestId += 1;
|
||||||
resetRepositoryState(true);
|
resetRepositoryState(true);
|
||||||
activeView = "management";
|
activeView = "management";
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user