From ba69b10071599707746fff208f45c39e8ed835f4 Mon Sep 17 00:00:00 2001 From: Aprillion Date: Sat, 16 Sep 2023 08:49:46 +0200 Subject: [PATCH 1/2] cache debug hopefully not needed anymore --- app/server-utils/kv-cache.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/server-utils/kv-cache.ts b/app/server-utils/kv-cache.ts index cd3b82bb..abfc8ff8 100644 --- a/app/server-utils/kv-cache.ts +++ b/app/server-utils/kv-cache.ts @@ -36,8 +36,6 @@ export function withCache Promise>( export async function reloadInBackgroundIfNeeded(url: string, timestamp: string) { const ageInMilliseconds = new Date().getTime() - new Date(timestamp).getTime() - // TODO: #228 keep debug for a few day after fixing cache invalidation, can be deleted later - console.debug('Reload needed', ageInMilliseconds > 10 * 60 * 1000, url || '/', timestamp) if (ageInMilliseconds > 10 * 60 * 1000) { const text = await (await fetch(`${url}${url.includes('?') ? '&' : '?'}reload`)).text() try { From 0ccdcec03950d23aaaea2c143394d9a2bc3509ca Mon Sep 17 00:00:00 2001 From: Aprillion Date: Sat, 16 Sep 2023 09:55:23 +0200 Subject: [PATCH 2/2] fix search * use state for re-render * use ref for current query detection in closure functions from previous render * queue wasn't enough, change to manual debounce of searchLater * add console debug to check after deployment --- app/components/search.tsx | 8 ++--- app/hooks/search.tsx | 74 +++++++++++++++------------------------ 2 files changed, 33 insertions(+), 49 deletions(-) diff --git a/app/components/search.tsx b/app/components/search.tsx index 1d79f7b9..de6e9112 100644 --- a/app/components/search.tsx +++ b/app/components/search.tsx @@ -37,7 +37,7 @@ export default function Search({ const [urlSearchParams] = useSearchParams() const placeholder = urlSearchParams.get('placeholder') ?? 'Search for more questions here...' - const {search, arePendingSearches, results} = useSearch(onSiteAnswersRef, limitFromUrl) + const {search, isPendingSearch, results} = useSearch(onSiteAnswersRef, limitFromUrl) const searchFn = (rawValue: string) => { const value = rawValue.trim() @@ -108,8 +108,8 @@ export default function Search({ /> -
- {arePendingSearches && results.length == 0 && ( +
+ {isPendingSearch && results.length == 0 && (
Searching for questions...
)} @@ -135,7 +135,7 @@ export default function Search({ }} /> ))} - {showResults && results.length === 0 && !arePendingSearches && (no results)} + {showResults && results.length === 0 && !isPendingSearch && (no results)} {!queryFromUrl && (