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, 06:45 UTC
perf(web): useStableCallback compiles without manual memoization (#20556)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 16, 2026 at 22:07 UTC
7e850a03c23d5beb303c1fa73e34f688b4aaab3c
1 file changed
+10
-4
apps/web/src/hooks/useStableCallback.ts
+10
-4
@@ -1,9 +1,10 @@
1
-import { useCallback, useLayoutEffect, useRef } from "react";
1
+import { useLayoutEffect, useRef, useState } from "react";
2
3
/**
4
* Only call it from event handlers and effects; during render it would see the
5
- * previous commit's `fn`. A `useCallback` result keeps the render scope it was
6
- * created in, and V8 shares one scope between all closures of a render.
5
+ * previous commit's `fn`. The forwarder is created once so its identity does not
6
+ * depend on the React Compiler, and it keeps no render scope alive: V8 shares one
7
+ * scope between all closures of a render.
8
*/
9
export function useStableCallback<Args extends ReadonlyArray<unknown>, Result>(
10
fn: (...args: Args) => Result,
@@ -12,5 +13,10 @@ export function useStableCallback<Args extends ReadonlyArray<unknown>, Result>(
13
useLayoutEffect(() => {
14
latest.current = fn;
15
});
15
- return useCallback((...args: Args) => latest.current(...args), []);
16
+ const [stable] = useState(
17
+ () =>
18
+ (...args: Args) =>
19
+ latest.current(...args),
20
+ );
21
+ return stable;
22
}