Skip to content

Commit b09d754

Browse files
committed
Fixes #3146 avoids timing issue adding results
1 parent 11ee8e7 commit b09d754

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
2020

2121
### Fixed
2222

23+
- Fixes [#3146](https://github.com/gitkraken/vscode-gitlens/issues/3146) - Search & Compare fails to remember items after restart
2324
- Fixes [#3152](https://github.com/gitkraken/vscode-gitlens/issues/3152) - Fixes double encoding of redirect URLs during account sign-in which affects certain environments
2425
- Fixes [#3153](https://github.com/gitkraken/vscode-gitlens/issues/3153) - `gitlens.defaultDateStyle` not working in Commit Details view
2526
- Fixes the _Open Pull Request Changes_ & _Compare Pull Request_ commands to scope the changes only to the pull request

src/views/searchAndCompareView.ts

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -375,16 +375,15 @@ export class SearchAndCompareView extends ViewBase<
375375
ref2: string | StoredNamedRef,
376376
options?: { reveal?: boolean },
377377
): Promise<CompareResultsNode> {
378-
return this.addResults(
379-
new CompareResultsNode(
380-
this,
381-
this.ensureRoot(),
382-
repoPath,
383-
typeof ref1 === 'string' ? { ref: ref1 } : ref1,
384-
typeof ref2 === 'string' ? { ref: ref2 } : ref2,
385-
// Provide a timestamp so we won't try to add it to our storage prematurely (and end up with a duplicate)
386-
Date.now(),
387-
),
378+
return this.addResultsNode(
379+
() =>
380+
new CompareResultsNode(
381+
this,
382+
this.ensureRoot(),
383+
repoPath,
384+
typeof ref1 === 'string' ? { ref: ref1 } : ref1,
385+
typeof ref2 === 'string' ? { ref: ref2 } : ref2,
386+
),
388387
options?.reveal === false ? false : undefined,
389388
);
390389
}
@@ -433,7 +432,10 @@ export class SearchAndCompareView extends ViewBase<
433432
return;
434433
}
435434

436-
await this.addResults(new SearchResultsNode(this, this.root!, repoPath, search, labels, results), reveal);
435+
await this.addResultsNode(
436+
() => new SearchResultsNode(this, this.root!, repoPath, search, labels, results),
437+
reveal,
438+
);
437439
}
438440

439441
getStoredNodes() {
@@ -502,8 +504,8 @@ export class SearchAndCompareView extends ViewBase<
502504
return node;
503505
}
504506

505-
private async addResults<T extends CompareResultsNode | SearchResultsNode>(
506-
results: T,
507+
private async addResultsNode<T extends CompareResultsNode | SearchResultsNode>(
508+
resultsNodeFn: () => T,
507509
reveal:
508510
| {
509511
expand?: boolean | number;
@@ -517,13 +519,16 @@ export class SearchAndCompareView extends ViewBase<
517519
}
518520

519521
const root = this.ensureRoot();
520-
root.addOrReplace(results);
522+
523+
// Deferred creating the results node until the view is visible (otherwise we will hit a duplicate timing issue when storing the new node, but then loading it from storage during the view's initialization)
524+
const resultsNode = resultsNodeFn();
525+
root.addOrReplace(resultsNode);
521526

522527
if (reveal !== false) {
523-
queueMicrotask(() => this.reveal(results, reveal));
528+
queueMicrotask(() => this.reveal(resultsNode, reveal));
524529
}
525530

526-
return results;
531+
return resultsNode;
527532
}
528533

529534
private setFilesLayout(layout: ViewFilesLayout) {

0 commit comments

Comments
 (0)