mirror of
https://github.com/nunocoracao/blowfish.git
synced 2026-10-10 22:09:31 +00:00
🐛 fix: race condition in search query execution
When a user opens the search modal and starts typing immediately, executeQuery() is triggered. Since buildIndex() is asynchronous, the fuse variable might still be undefined when .search() is called. Added safety checks for fuse initialization.
This commit is contained in:
1 parent
da8ca782aa
commit
db9fb58bca
1 file changed
+7
-1
+7
-1
@@ -151,6 +151,12 @@ function buildIndex() {
|
||||
}
|
||||
|
||||
function executeQuery(term) {
|
||||
if (!indexed) {
|
||||
buildIndex();
|
||||
}
|
||||
if (!fuse) {
|
||||
return;
|
||||
}
|
||||
let results = fuse.search(term);
|
||||
let resultsHTML = "";
|
||||
|
||||
@@ -193,7 +199,7 @@ function executeQuery(term) {
|
||||
}
|
||||
|
||||
output.innerHTML = resultsHTML;
|
||||
if (results.length > 0) {
|
||||
if (results.length > 0 && output.firstChild) {
|
||||
first = output.firstChild.firstElementChild;
|
||||
last = output.lastChild.firstElementChild;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user