Skip to content

Commit b4559ea

Browse files
Copilotalexr00
andauthored
Fix race condition in branch picker when creating PR
Register onDidAccept/onDidHide handlers before async updateItems to avoid missing early user interactions. Fall back to activeItems when selectedItems is empty due to items being replaced during debounced refresh. Agent-Logs-Url: https://github.com/microsoft/vscode-pull-request-github/sessions/f9f9a4fa-befb-4089-968f-721dfd44e120 Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
1 parent 06913ff commit b4559ea

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

src/github/createPRViewProvider.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,19 +1161,14 @@ Don't forget to commit your template file to the repository so that it can be us
11611161
const activeItem = message.args.currentBranch ? quickPick.items.find(item => item.branch === message.args.currentBranch) : undefined;
11621162
quickPick.activeItems = activeItem ? [activeItem] : [];
11631163
}
1164-
await updateItems(githubRepository, undefined);
1165-
} else {
1166-
quickPick.items = await this.remotePicks(isBase);
11671164
}
1168-
const activeItem = message.args.currentBranch ? quickPick.items.find(item => item.branch === message.args.currentBranch) : undefined;
1169-
quickPick.activeItems = activeItem ? [activeItem] : [];
1170-
quickPick.busy = false;
1165+
// Register event handlers before awaiting async operations to avoid missing early user interactions
11711166
const remoteAndBranch: Promise<{ remote: RemoteInfo, branch: string } | undefined> = new Promise((resolve) => {
11721167
quickPick.onDidAccept(async () => {
1173-
if (quickPick.selectedItems.length === 0) {
1168+
const selectedPick = quickPick.selectedItems[0] ?? quickPick.activeItems[0];
1169+
if (!selectedPick) {
11741170
return;
11751171
}
1176-
const selectedPick = quickPick.selectedItems[0];
11771172
if (selectedPick.label === chooseDifferentRemote) {
11781173
quickPick.busy = true;
11791174
quickPick.items = await this.remotePicks(isBase);
@@ -1194,6 +1189,14 @@ Don't forget to commit your template file to the repository so that it can be us
11941189
});
11951190
});
11961191
const hidePromise = new Promise<void>((resolve) => quickPick.onDidHide(() => resolve()));
1192+
if (githubRepository) {
1193+
await updateItems(githubRepository, undefined);
1194+
} else {
1195+
quickPick.items = await this.remotePicks(isBase);
1196+
}
1197+
const activeItem = message.args.currentBranch ? quickPick.items.find(item => item.branch === message.args.currentBranch) : undefined;
1198+
quickPick.activeItems = activeItem ? [activeItem] : [];
1199+
quickPick.busy = false;
11971200
const result = await Promise.race([remoteAndBranch, hidePromise]);
11981201
if (!result || !githubRepository) {
11991202
quickPick.hide();

src/github/pullRequestOverview.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,13 +1136,14 @@ export class PullRequestOverviewPanel extends IssueOverviewPanel<PullRequestMode
11361136
quickPick.canSelectMany = false;
11371137
quickPick.placeholder = vscode.l10n.t('Select a new base branch');
11381138
quickPick.show();
1139-
await updateItems(undefined);
1140-
1141-
quickPick.busy = false;
1139+
// Register event handlers before awaiting async operations to avoid missing early user interactions
11421140
const acceptPromise = asPromise<void>(quickPick.onDidAccept).then(() => {
1143-
return quickPick.selectedItems[0]?.branch;
1141+
return (quickPick.selectedItems[0] ?? quickPick.activeItems[0])?.branch;
11441142
});
11451143
const hidePromise = asPromise<void>(quickPick.onDidHide);
1144+
await updateItems(undefined);
1145+
1146+
quickPick.busy = false;
11461147
const selectedBranch = await Promise.race<string | void>([acceptPromise, hidePromise]);
11471148
quickPick.busy = true;
11481149
quickPick.enabled = false;

0 commit comments

Comments
 (0)