Skip to content

Commit

Permalink
⚡️ refactor(search): reduce search lag on mobile
Browse files Browse the repository at this point in the history
Should reduce perceived lag when opening the search modal
and scrolling through results.
  • Loading branch information
welpo committed Sep 24, 2024
1 parent 17694ba commit 7ceada9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions static/js/searchElasticlunr.js
Original file line number Diff line number Diff line change
Expand Up @@ -2686,7 +2686,7 @@ window.onload = function () {
event.stopPropagation(); // Prevents tapping through the modal.
}
searchModal.addEventListener('click', handleModalInteraction);
searchModal.addEventListener('touchend', handleModalInteraction);
searchModal.addEventListener('touchend', handleModalInteraction, { passive: true });

// Close modal when pressing escape.
document.addEventListener('keydown', function (event) {
Expand All @@ -2711,7 +2711,7 @@ window.onload = function () {
// Clicking/tapping the search button opens the modal.
searchButton.addEventListener('mouseover', loadSearchIndex);
searchButton.addEventListener('click', openSearchModal);
searchButton.addEventListener('touchstart', openSearchModal);
searchButton.addEventListener('touchstart', openSearchModal, { passive: true });

let searchIndexPromise = null;
function loadSearchIndex() {
Expand Down Expand Up @@ -3109,7 +3109,7 @@ window.onload = function () {
resultDivs.forEach((div) => {
// Remove existing listener to avoid duplicates.
div.removeEventListener('touchstart', handleTouchStart);
div.addEventListener('touchstart', handleTouchStart);
div.addEventListener('touchstart', handleTouchStart, { passive: true });
});
}

Expand Down
Loading

0 comments on commit 7ceada9

Please sign in to comment.