From 6e9ae70a65a8dec382d9600bda46801c888e5ae3 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Thu, 10 Sep 2026 17:37:39 +0000 Subject: [PATCH] Show searching state immediately on trending landing URLs Start the landing-page search as soon as useSearch mounts instead of waiting for Turnstile/session bootstrap to finish. performSearch already awaits ensureApiSession internally, so the search button and skeletons appear while Turnstile runs. Co-authored-by: xenodus --- frontend/src/hooks/useSearch.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/frontend/src/hooks/useSearch.js b/frontend/src/hooks/useSearch.js index 7f79ed42..672d34a7 100644 --- a/frontend/src/hooks/useSearch.js +++ b/frontend/src/hooks/useSearch.js @@ -9,6 +9,7 @@ import { } from "../constants"; import { API_SESSION_REFRESH_INTERVAL_MS, + DEFAULT_MAINTENANCE_MESSAGE, ensureApiSession, fetchSiteStatus, formatSessionBootstrapError, @@ -124,7 +125,7 @@ export default function useSearch() { }, [searchResults]); const runLandingSearchIfNeeded = useCallback((timing) => { - if (landingSearchHandledRef.current || timing?.maintenanceMode) { + if (landingSearchHandledRef.current) { return; } @@ -134,6 +135,18 @@ export default function useSearch() { return; } + if (timing?.maintenanceMode) { + landingSearchHandledRef.current = true; + skipSuggestionsRef.current = true; + setIsSearching(false); + setSearchProgress("Search"); + setHasSearched(true); + setSearchError( + timing.maintenanceMessage?.trim() || DEFAULT_MAINTENANCE_MESSAGE, + ); + return; + } + landingSearchHandledRef.current = true; skipSuggestionsRef.current = true; @@ -152,6 +165,10 @@ export default function useSearch() { setNoticeMessage(status.noticeMessage ?? ""); }; + // Start the landing search immediately so the button shows "Searching" + // while Turnstile/session bootstrap runs inside performSearch. + runLandingSearchIfNeeded(getCachedSiteStatus()); + fetchSiteStatus() .then((status) => { if (!cancelled) { @@ -169,7 +186,6 @@ export default function useSearch() { } applySiteStatus(timing); setSessionBootstrapped(true); - runLandingSearchIfNeeded(timing); }) .catch((err) => { if (!cancelled) {