Skip to content

Commit

Permalink
Fixes infinite loop with triggerChange
Browse files Browse the repository at this point in the history
If child is splatted, it can trigger a change on itself (e.g. parent)
  • Loading branch information
eamodio committed Dec 12, 2020
1 parent 2d73fcc commit 356f1ff
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/views/nodes/viewNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,14 @@ export abstract class ViewNode<TView extends View = View> {

refresh?(reset?: boolean): boolean | void | Promise<void> | Promise<boolean>;

@gate()
@gate<RepositoryFolderNode['triggerChange']>(
(reset: boolean = false, force: boolean = false, avoidSelf?: ViewNode) =>
JSON.stringify([reset, force, avoidSelf?.toString()]),
)
@debug()
triggerChange(reset: boolean = false, force: boolean = false): Promise<void> {
triggerChange(reset: boolean = false, force: boolean = false, avoidSelf?: ViewNode): Promise<void> {
// If this node has been splatted (e.g. not shown itself, but its children are), then delegate the change to its parent
if (this.splatted && this.parent != null) {
if (this.splatted && this.parent != null && this.parent !== avoidSelf) {
return this.parent.triggerChange(reset, force);
}

Expand Down Expand Up @@ -354,7 +357,7 @@ export abstract class RepositoryFolderNode<
@gate()
@debug()
async refresh(reset: boolean = false) {
await this.child?.triggerChange(reset);
await this.child?.triggerChange(reset, false, this);

await this.ensureSubscription();
}
Expand Down

0 comments on commit 356f1ff

Please sign in to comment.