From 82456ff62e8d7fcbc564dd7e30afc4306e5719d8 Mon Sep 17 00:00:00 2001 From: Jake Howell Date: Fri, 10 Apr 2026 20:45:18 +1000 Subject: [PATCH] feat: resolve `useTime()` `thunk()` error (#24234) Fixes a regression introduced in #24060 that could crash the frontend. `thunk` is created by `useEffectEvent()`, and React 19.2 enforces that effect-event functions are not invoked during render. The previous code called `thunk()` inside a `setState` updater function, and React executes updater functions during render, so this became an illegal render-phase call. The fix computes `next` in the interval callback (`const next = thunk()`) and then stores it via `setComputedValue(() => next)`. This keeps the `useEffectEvent` call outside render and also preserves correct behavior when `func` returns a function value, because React stores `next` instead of treating it as a functional updater. --- site/src/hooks/useTime.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/site/src/hooks/useTime.ts b/site/src/hooks/useTime.ts index 3c431af3d4..f1547b01be 100644 --- a/site/src/hooks/useTime.ts +++ b/site/src/hooks/useTime.ts @@ -30,7 +30,8 @@ export function useTime(func: () => T, options: UseTimeOptions = {}): T { } const handle = setInterval(() => { - setComputedValue(() => thunk()); + const next = thunk(); + setComputedValue(() => next); }, interval); return () => {