diff --git a/nextjs-app/components/ComparisonView.tsx b/nextjs-app/components/ComparisonView.tsx index 5f5b163..b3973af 100644 --- a/nextjs-app/components/ComparisonView.tsx +++ b/nextjs-app/components/ComparisonView.tsx @@ -133,15 +133,16 @@ export function ComparisonView({ // Guard against out-of-order responses: while the basket hydrates from // localStorage it can transiently hold a DIFFERENT school set than the // URL, firing a fetch for schools the user is no longer comparing. That - // stale response must not replace data for the current set — replacing - // it blanked every section until a hard refresh. We (a) drop responses - // from superseded effect runs and (b) merge rather than replace, so data - // for the current schools always survives. + // stale response must not replace data for the current set — it blanked + // every section until a hard refresh. Cleanup marks the run cancelled + // when urnKey moves on, so only the current selection's response is + // applied (replacing the map keeps it bounded and guarantees a re-added + // school is refetched fresh rather than served a lingering old entry). let cancelled = false; fetchComparison(urnKey, { cache: 'no-store' }) .then((data) => { if (cancelled) return; - setComparisonData((prev) => ({ ...(prev ?? {}), ...data.comparison })); + setComparisonData(data.comparison); setNationalAverages(data.national_averages); setBenchmarks(data.benchmarks); })