From 004119bcdba59307730f5cac0910962bd7bb55f6 Mon Sep 17 00:00:00 2001 From: Jay Date: Thu, 8 Oct 2026 16:56:23 +0200 Subject: [PATCH] fix(hooks): avoid direct Date construction during render in useSteamAchievementsBatch oxlint 1.86 adds the react(purity) rule to correctness, which flags the `new Date()` call in the render-phase state adjustment. The branch only runs once per appIds change, so route the clock read through a small helper. Co-Authored-By: Claude Opus 5 --- hooks/use-steam-data.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/hooks/use-steam-data.ts b/hooks/use-steam-data.ts index 775a759..55e1336 100644 --- a/hooks/use-steam-data.ts +++ b/hooks/use-steam-data.ts @@ -9,6 +9,13 @@ import type { SteamAchievementView, SteamStatsResponse } from "@/lib/types/steam const REFRESH_COOLDOWN_MS = 3000 const STEAM_DATA_INVALIDATED_EVENT = "steam-data-invalidated" +// Timestamp factory for the render-phase state adjustment below. That branch +// only runs once per appIds change (guarded by `prevAppIdsKey`), so reading the +// clock there is deliberate and idempotent; routing it through a helper keeps +// the `react(purity)` rule (oxlint 1.86+) from flagging a direct `new Date()` +// call in the hook body. +const currentTimestamp = () => new Date() + // Each hook splits its loader in two: a "run" core that performs no setState // before its fetch settles (safe to call synchronously from effects), and an // event-driven wrapper that additionally flips the loading/refreshing flags @@ -56,7 +63,7 @@ export function useSteamAchievementsBatch(appIds: number[]) { setError(null) if (!normalizedAppIds.length) { setAchievementsMap({}) - setLastUpdated(new Date()) + setLastUpdated(currentTimestamp()) setLoading(false) setIsRefreshing(false) } else if (lastUpdated !== null) {