Defer search-restore render so it survives nav-button click bubble

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.
This commit is contained in:
Broque Thomas 2026-04-23 22:17:33 -07:00
parent 258644fd9f
commit ab7aeb302c

View file

@ -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