From ab7aeb302c626299ac7273e4187d92e29b2cb35a Mon Sep 17 00:00:00 2001 From: Broque Thomas <26755000+Nezreka@users.noreply.github.com> Date: Thu, 23 Apr 2026 22:17:33 -0700 Subject: [PATCH] Defer search-restore render so it survives nav-button click bubble MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The navigate-back fix from the previous commit was being immediately undone by the document outside-click handler. Race: 1. Click on sidebar nav-button → button handler runs synchronously, eventually calling _searchPageRestoreOnEnter → _renderFromState → showDropdown removes `hidden` class 2. Click event bubbles up to document 3. Document outside-click handler sees dropdown is now visible, sees the click target is a nav-button (not inside the search wrapper or the source row), calls hideDropdown → instantly hidden again Fix: defer the _renderFromState call to setTimeout(0). The macrotask runs AFTER the click event finishes propagating, so by the time the dropdown becomes visible, the document outside-click handler has already short-circuited (it saw the dropdown still hidden). User reported having to delete + retype the last character of the query to force a re-render — which worked because the input event listener fires submitQuery, which routes through the controller without going through the deferred path. --- webui/static/search.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/webui/static/search.js b/webui/static/search.js index f9c3e9d1..e8d93f52 100644 --- a/webui/static/search.js +++ b/webui/static/search.js @@ -209,9 +209,13 @@ function initializeSearchModeToggle() { searchController.init(); // Expose a re-render hook so navigate-back to /search restores cached - // results instead of leaving the dropdown hidden. + // results instead of leaving the dropdown hidden. Deferred to the next + // tick so the render happens AFTER the nav-button click finishes + // bubbling to the document outside-click handler — otherwise that + // handler sees the just-shown dropdown and immediately dismisses it. _searchPageRestoreOnEnter = () => { - if (searchController.state.query) _renderFromState(searchController.state); + if (!searchController.state.query) return; + setTimeout(() => _renderFromState(searchController.state), 0); }; // Live search with debouncing