From db9fb58bcaa15aaaa7a2fe9321a0a581132245b9 Mon Sep 17 00:00:00 2001 From: Kamil Sijko Date: Tue, 5 May 2026 11:50:28 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20race=20condition=20in=20s?= =?UTF-8?q?earch=20query=20execution?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- assets/js/search.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/assets/js/search.js b/assets/js/search.js index e71e8c31..18a65e65 100644 --- a/assets/js/search.js +++ b/assets/js/search.js @@ -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; }