Skip to content

Commit

Permalink
fix(removeWidget): check for widgets.length on next tick
Browse files Browse the repository at this point in the history
  • Loading branch information
iam4x committed Mar 20, 2018
1 parent 1f75d6a commit 1d344f1
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/lib/InstantSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,16 @@ Usage: instantsearch({
}
});

// no need to trigger a search if we don't have any widgets left
if (this.widgets.length > 0) {
this.helper.search();
}
// If there's multiple call to `removeWidget()` let's wait until they are all made
// and then check for widgets.length & make a search on next tick
//
// This solves an issue where you unmount a page and removing widget by widget
setTimeout(() => {
// no need to trigger a search if we don't have any widgets left
if (this.widgets.length > 0) {
this.helper.search();
}
}, 0);
}

/**
Expand Down

0 comments on commit 1d344f1

Please sign in to comment.