Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions frontend/src/hooks/useSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from "../constants";
import {
API_SESSION_REFRESH_INTERVAL_MS,
DEFAULT_MAINTENANCE_MESSAGE,
ensureApiSession,
fetchSiteStatus,
formatSessionBootstrapError,
Expand Down Expand Up @@ -124,7 +125,7 @@ export default function useSearch() {
}, [searchResults]);

const runLandingSearchIfNeeded = useCallback((timing) => {
if (landingSearchHandledRef.current || timing?.maintenanceMode) {
if (landingSearchHandledRef.current) {
return;
}

Expand All @@ -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;

Expand All @@ -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) {
Expand All @@ -169,7 +186,6 @@ export default function useSearch() {
}
applySiteStatus(timing);
setSessionBootstrapped(true);
runLandingSearchIfNeeded(timing);
})
.catch((err) => {
if (!cancelled) {
Expand Down
Loading