From e330dbd533ceb0150511b3aa780bfa9a586adb6a Mon Sep 17 00:00:00 2001 From: David Nguyen Date: Sun, 22 Nov 2026 02:05:59 +0700 Subject: [PATCH 1/3] fix(search): track successful empty index loads --- utils/search-index-load-state.mjs | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 utils/search-index-load-state.mjs diff --git a/utils/search-index-load-state.mjs b/utils/search-index-load-state.mjs new file mode 100644 index 00000000..562fa537 --- /dev/null +++ b/utils/search-index-load-state.mjs @@ -0,0 +1,8 @@ +/** Distinguish a successfully loaded empty catalog from one not yet loaded. */ +export function createSearchIndexLoadState() { + let loaded = false; + return { + isLoaded: () => loaded, + markLoaded: () => { loaded = true; }, + }; +} From 0f6f260683ff90a661e52ef67d4076b1090f2d8a Mon Sep 17 00:00:00 2001 From: David Nguyen Date: Sun, 22 Nov 2026 02:06:04 +0700 Subject: [PATCH 2/3] fix(search): avoid repeated loading state for cached empty index --- composables/useStationSearchIndex.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/composables/useStationSearchIndex.ts b/composables/useStationSearchIndex.ts index 982bcd62..158d3024 100644 --- a/composables/useStationSearchIndex.ts +++ b/composables/useStationSearchIndex.ts @@ -1,4 +1,5 @@ import { createCachedLoader } from '~/utils/cached-loader.mjs'; +import { createSearchIndexLoadState } from '~/utils/search-index-load-state.mjs'; export interface StationSearchItem { objectID: string; @@ -36,6 +37,7 @@ export function useStationSearchIndex() { const index = shallowRef([]); const loading = ref(false); const error = ref(false); + const loadState = createSearchIndexLoadState(); let disposed = false; let requested: Promise | undefined; @@ -43,12 +45,12 @@ export function useStationSearchIndex() { // Load on search focus/open; the cached loader deduplicates across mobile // modal and desktop header, and failed requests remain retryable. const load = (): Promise => { - if (index.value.length) return Promise.resolve(); + if (loadState.isLoaded()) return Promise.resolve(); if (requested) return requested; loading.value = true; error.value = false; requested = loaderFor(searchUrl)() - .then(items => { if (!disposed) index.value = items; }) + .then(items => { if (!disposed) { index.value = items; loadState.markLoaded(); } }) .catch(() => { if (!disposed) error.value = true; }) .finally(() => { requested = undefined; From 53234c7be65daed112bdd9cfa0fff033b8e76731 Mon Sep 17 00:00:00 2001 From: David Nguyen Date: Sun, 22 Nov 2026 02:06:08 +0700 Subject: [PATCH 3/3] test(search): cover successful empty index and retry state --- tests/search-index-load-state.test.mjs | 27 ++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 tests/search-index-load-state.test.mjs diff --git a/tests/search-index-load-state.test.mjs b/tests/search-index-load-state.test.mjs new file mode 100644 index 00000000..da5eda43 --- /dev/null +++ b/tests/search-index-load-state.test.mjs @@ -0,0 +1,27 @@ +import test from 'node:test'; +import assert from 'node:assert/strict'; +import { createSearchIndexLoadState } from '../utils/search-index-load-state.mjs'; + +test('empty successful search index is still considered loaded', () => { + const state = createSearchIndexLoadState(); + assert.equal(state.isLoaded(), false); + const items = []; + assert.equal(items.length, 0); + state.markLoaded(); + assert.equal(state.isLoaded(), true); +}); + +test('failed search index load stays retryable', () => { + const state = createSearchIndexLoadState(); + assert.equal(state.isLoaded(), false); + // A rejected request must not call markLoaded(). + assert.equal(state.isLoaded(), false); +}); + +test('search index load state is isolated per component instance', () => { + const first = createSearchIndexLoadState(); + const second = createSearchIndexLoadState(); + first.markLoaded(); + assert.equal(first.isLoaded(), true); + assert.equal(second.isLoaded(), false); +});