The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 23, 08:00 UTC
perf(web): useLiveRefresh reads its callback through useEffectEvent (#20464)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 16, 2026 at 18:46 UTC
de89a7a76dfae79c1defbd7baa9cd7abd5154a6f
2 files changed
+9
-9
apps/web/reactCompiledFiles.ts
+1
@@ -39,4 +39,5 @@ export const REACT_COMPILED_FILES = [
39
"apps/web/src/components/auth/PairingRouteSurface.tsx",
40
"apps/web/src/components/Sidebar.logic.ts",
41
"apps/web/src/components/pullRequest/usePullRequestFilesViewed.ts",
42
+ "apps/web/src/hooks/useLiveRefresh.ts",
43
] as const;
apps/web/src/hooks/useLiveRefresh.ts
+8
-9
@@ -1,4 +1,4 @@
1
-import { useEffect, useId, useRef } from "react";
1
+import { useEffect, useEffectEvent, useId } from "react";
2
3
export const LIVE_REFRESH_MIN_INTERVAL_MS = 10_000;
4
@@ -83,20 +83,19 @@ export function useLiveRefresh(
83
} = {},
84
): void {
85
const { enabled = true, key, intervalMs = LIVE_REFRESH_INTERVAL_MS } = options;
86
- // Held in a ref so a caller can pass a fresh closure every render without re-arming the
86
+ // An effect event so a caller can pass a fresh closure every render without re-arming the
87
// listeners, which would otherwise refresh on every render that changed anything at all.
88
- const latest = useRef(refresh);
89
- latest.current = refresh;
88
+ const runRefresh = useEffectEvent((viewId: string, now: number) => {
89
+ if (refresh === null) return;
90
+ lastRefreshedAtByView.set(viewId, now);
91
+ refresh();
92
+ });
93
const fallbackViewId = useId();
94
const viewId = key ?? fallbackViewId;
95
96
useEffect(() => {
97
if (!enabled) return;
95
- const read = (now: number) => {
96
- if (latest.current === null) return;
97
- lastRefreshedAtByView.set(viewId, now);
98
- latest.current();
99
- };
98
+ const read = (now: number) => runRefresh(viewId, now);
99
const visible = () => document.visibilityState === "visible";
100
const onArrival = () => {
101
const now = Date.now();