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:
Marc-André Bombeck committed 2026-10-08 22:57:47 +02:00
1 parent dd76b434c4
commit b4e3e22d43
5 files changed
+64 -17

No files matched your search

+2 -5
View File
@@ -1,3 +1,4 @@
import { settleWithin } from "@/lib/async/settle-within";
import { prisma } from "@/lib/db";
import { lookupIpGeo } from "@/lib/geo";
import { getEvent } from "@/lib/logging/context";
@@ -80,11 +81,7 @@ export async function auditLog(
// provider can't stall the audit write.
if (opts.ipAddress && action.startsWith("auth.")) {
const ipAddress = opts.ipAddress;
const timeout = new Promise<null>((resolve) =>
setTimeout(() => resolve(null), 3000),
);
Promise.race([lookupIpGeo(ipAddress), timeout])
settleWithin(lookupIpGeo(ipAddress), 3000, null)
.then((result) => {
if (!result) return;
const { location, asn, carrier } = result;