mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-15 23:12:04 +00:00
fix(ssr): clear the budget timer once a raced read answers
The mood and dashboard prefetches and the sign-in location lookup raced their work against a bare setTimeout that was never cleared, leaving one live timer behind per render or sign-in after the work had already answered. A shared helper races the work and clears the timer.
This commit is contained in:
1 parent
dd76b434c4
commit
b4e3e22d43
5 files changed
+64
-17
No files matched your search
@@ -18,6 +18,7 @@ import {
|
||||
type MoodAggregates,
|
||||
} from "@/lib/insights/mood-aggregates";
|
||||
import type { MoodDailySeries } from "@/lib/analytics/mood-series";
|
||||
import { settleWithin } from "@/lib/async/settle-within";
|
||||
import { resolveModuleMap } from "@/lib/modules/gate";
|
||||
import { queryKeys } from "@/lib/query-keys";
|
||||
|
||||
@@ -32,12 +33,7 @@ import InsightsMoodPageClient from "./page-client";
|
||||
const PREFETCH_BUDGET_MS = 1_500;
|
||||
|
||||
function withinBudget<T>(work: Promise<T>): Promise<T | null> {
|
||||
return Promise.race([
|
||||
work,
|
||||
new Promise<null>((resolve) =>
|
||||
setTimeout(() => resolve(null), PREFETCH_BUDGET_MS),
|
||||
),
|
||||
]).catch(() => null);
|
||||
return settleWithin(work, PREFETCH_BUDGET_MS, null).catch(() => null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user