From bb1ec8e9cbb2873922928ec27f68f408a8ee5c68 Mon Sep 17 00:00:00 2001
From: Liam Bigelow <40188355+bglw@users.noreply.github.com>
Date: Tue, 19 Sep 2023 15:29:35 +1200
Subject: [PATCH 1/2] Fix `debouncesSearch()` when passing an options object
---
pagefind/features/debounce.feature | 33 +++++++++++++++++++++++++++
pagefind_web_js/lib/coupled_search.ts | 6 +++--
2 files changed, 37 insertions(+), 2 deletions(-)
diff --git a/pagefind/features/debounce.feature b/pagefind/features/debounce.feature
index 181033dc..fd6e5e9d 100644
--- a/pagefind/features/debounce.feature
+++ b/pagefind/features/debounce.feature
@@ -40,3 +40,36 @@ Feature: Debounced Searches
Then There should be no logs
Then The selector "[data-types]" should contain "null, null, null, null, 1"
Then The selector "[data-last]" should contain "/cat/"
+
+ Scenario: Debounce with options
+ Given I have a "public/cat/index.html" file with the body:
+ """
+
world
+ """
+ When I run my program
+ Then I should see "Running Pagefind" in stdout
+ Then I should see the file "public/pagefind/pagefind.js"
+ When I serve the "public" directory
+ When I load "/"
+ When I evaluate:
+ """
+ async function() {
+ let pagefind = await import("/pagefind/pagefind.js");
+
+ let results = await Promise.all([
+ pagefind.debouncedSearch("a", { filters: {} }),
+ pagefind.debouncedSearch("w", { filters: {} }),
+ pagefind.debouncedSearch("wo", { filters: {} }),
+ pagefind.debouncedSearch("wor", { filters: {} }),
+ pagefind.debouncedSearch("worl", { filters: {} })
+ ]);
+
+ document.querySelector('[data-types]').innerText = results.map(r => (r === null ? "null" : r.results.length)).join(', ');
+
+ let pages = await Promise.all(results[4].results.map(r => r.data()));
+ document.querySelector('[data-last]').innerText = pages.map(p => p.url).sort().join(", ");
+ }
+ """
+ Then There should be no logs
+ Then The selector "[data-types]" should contain "null, null, null, null, 1"
+ Then The selector "[data-last]" should contain "/cat/"
diff --git a/pagefind_web_js/lib/coupled_search.ts b/pagefind_web_js/lib/coupled_search.ts
index 6e28e0d6..b0450f26 100644
--- a/pagefind_web_js/lib/coupled_search.ts
+++ b/pagefind_web_js/lib/coupled_search.ts
@@ -346,8 +346,10 @@ class PagefindInstance {
}
async preload(term: string, options: PagefindSearchOptions = {}) {
- options.preload = true;
- await this.search(term, options);
+ await this.search(term, {
+ ...options,
+ preload: true
+ });
}
async search(term: string, options: PagefindSearchOptions = {}): Promise {
From 595409410882aba17d55f643147e29a60b5029aa Mon Sep 17 00:00:00 2001
From: Liam Bigelow <40188355+bglw@users.noreply.github.com>
Date: Tue, 19 Sep 2023 15:40:00 +1200
Subject: [PATCH 2/2] Tracking changelog
---
CHANGELOG.md | 2 ++
1 file changed, 2 insertions(+)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 68999be6..0d041ea0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,6 +9,8 @@
## Unreleased
+* Fixes a bug where `debouncedSearch` returns `null` if any options object is passed to it.
+
## v1.0.3 (September 16, 2023)
Hopefully the last hotfix for now — bugfixes only important for sites indexing Japanese or Chinese pages.