fix(web): show an outage as an outage, and drop superseded fetches

The home page caught every fetch failure and rendered its empty state,
so a backend outage looked like a site with no schools in it. School
pages turned any error into notFound(), which told visitors — and
crawlers — that a real school had ceased to exist. Place fetches did the
same by returning [] and null. Failures now reach a retryable error
boundary; only a genuine 404 still calls notFound().

"Load more" and the map fetch resolved against whatever state existed
when they returned, so results from an abandoned search appended
themselves to the new ones. Each fetch now carries an AbortController
and checks that its search scope is still current before touching state.
The map only records its cache key on success, so a failed load retries
instead of pinning the stale marker set.

Jest ignored .next/, whose build output otherwise shadowed real suites.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
TudorandClaude Opus 5 committed 2026-09-15 10:17:18 +01:00
1 parent 9b75f54206
commit 7b41218e6e
8 files changed
+231 -80

No files matched your search

+34 -8
View File
@@ -213,6 +213,16 @@ export function HomeView({ initialSchools, filters, totalSchools, howItWorks, ed
const [isLoadingMap, setIsLoadingMap] = useState(false);
const prevSearchParamsRef = useRef(searchParams.toString());
const mapParamsRef = useRef<string>('');
const loadMoreController = useRef<AbortController | null>(null);
// Identity changes even for A → B → A, so an old A response stays stale.
const searchScope = useRef({ key: searchParams.toString() });
if (searchScope.current.key !== searchParams.toString()) {
searchScope.current = { key: searchParams.toString() };
}
useEffect(() => {
setIsLoadingMore(false);
return () => { loadMoreController.current?.abort(); };
}, [searchParams]);
const [geoState, setGeoState] = useState<'idle' | 'requesting' | 'error'>('idle');
const [geoError, setGeoError] = useState<string | null>(null);
/*
@@ -274,17 +284,27 @@ export function HomeView({ initialSchools, filters, totalSchools, howItWorks, ed
if (resultsView !== 'map' || !isLocationSearch) return;
const paramsKey = searchParams.toString();
if (paramsKey === mapParamsRef.current) return;
mapParamsRef.current = paramsKey;
const controller = new AbortController();
const scope = searchScope.current;
const current = () => !controller.signal.aborted && searchScope.current === scope;
setIsLoadingMap(true);
const params: Record<string, any> = {};
searchParams.forEach((value, key) => { params[key] = value; });
params.page = 1;
params.page_size = 500;
fetchSchools(params, { cache: 'no-store' })
.then(r => setMapSchools(r.schools))
.catch(() => setMapSchools(initialSchools.schools))
.finally(() => setIsLoadingMap(false));
}, [resultsView, searchParams]);
fetchSchools(params, { cache: 'no-store', signal: controller.signal })
.then(r => {
if (!current()) return;
mapParamsRef.current = paramsKey;
setMapSchools(r.schools);
})
.catch(() => {
if (current()) setMapSchools(initialSchools.schools);
// No cache marker on failure: opening the map again retries.
})
.finally(() => { if (current()) setIsLoadingMap(false); });
return () => controller.abort();
}, [resultsView, searchParams, initialSchools.schools]);
// Fetch LA averages when secondary or mixed schools are visible
useEffect(() => {
@@ -305,19 +325,25 @@ export function HomeView({ initialSchools, filters, totalSchools, howItWorks, ed
if (isLoadingMore || !hasMore) return;
track('results_load_more', { next_page: currentPage + 1 });
setIsLoadingMore(true);
const scope = searchScope.current;
const controller = new AbortController();
loadMoreController.current?.abort();
loadMoreController.current = controller;
const current = () => !controller.signal.aborted && searchScope.current === scope;
try {
const params: Record<string, any> = {};
searchParams.forEach((value, key) => { params[key] = value; });
params.page = currentPage + 1;
params.page_size = initialSchools.page_size;
const response = await fetchSchools(params, { cache: 'no-store' });
const response = await fetchSchools(params, { cache: 'no-store', signal: controller.signal });
if (!current()) return;
setAllSchools(prev => [...prev, ...response.schools]);
setCurrentPage(response.page);
setHasMore(response.page < response.total_pages);
} catch {
// silently ignore
} finally {
setIsLoadingMore(false);
if (current()) setIsLoadingMore(false);
}
};