Skip to content

Commit 7e639d6

Browse files
Maxime Jantonbobylito
authored andcommitted
fix(removeWidget): check for widgets.length on next tick (#2831)
1 parent b7875e9 commit 7e639d6

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/lib/InstantSearch.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,16 @@ Usage: instantsearch({
193193
}
194194
});
195195

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

202208
/**

0 commit comments

Comments
 (0)