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): resize handles compile with the React Compiler (#20524)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 16, 2026 at 19:09 UTC
f0474d37d7d4986bbef7835745e04d5a4c9e717f
2 files changed
+31
-30
apps/web/reactCompiledFiles.ts
+1
@@ -91,4 +91,5 @@ export const REACT_COMPILED_FILES = [
91
"apps/web/src/components/settings/ThemeImportDialog.tsx",
92
"apps/web/src/components/settings/SnapShotSettings.tsx",
93
"apps/web/src/components/settings/ConnectionsSettings.tsx",
94
+ "apps/web/src/hooks/useResizeDrag.ts",
95
] as const;
apps/web/src/hooks/useResizeDrag.ts
+30
-30
@@ -1,4 +1,4 @@
1
-import { type PointerEvent, useCallback, useEffect, useLayoutEffect, useRef } from "react";
1
+import { type PointerEvent, useEffect, useEffectEvent, useLayoutEffect, useRef } from "react";
2
3
interface ResizeSession {
4
width: number;
@@ -23,51 +23,51 @@ export function useResizeDrag<T extends HTMLElement>(
23
frame: number | null;
24
} | null>(null);
25
26
- const flush = useCallback(() => {
26
+ const flush = () => {
27
const active = drag.current;
28
if (!active) return;
29
const delta = (active.pendingX - active.startX) * (active.session.edge === "left" ? -1 : 1);
30
- active.moved ||= Math.abs(delta) > 2;
30
+ if (Math.abs(delta) > 2) active.moved = true;
31
active.width = active.session.resize(active.session.width + delta);
32
- }, []);
32
+ };
33
34
- const finish = useCallback(
35
- (commit = true) => {
36
- const active = drag.current;
37
- if (!active) return;
38
- if (active.frame !== null) cancelAnimationFrame(active.frame);
39
- if (commit) flush();
40
- // Release can synchronously dispatch lostpointercapture.
41
- drag.current = null;
42
- try {
43
- if (active.target.hasPointerCapture(active.pointerId)) {
44
- active.target.releasePointerCapture(active.pointerId);
45
- }
46
- } catch {}
47
- document.body.style.removeProperty("cursor");
48
- document.body.style.removeProperty("user-select");
49
- active.session.cleanup?.(commit);
50
- if (commit) active.session.finish(active.width, active.moved);
51
- },
52
- [flush],
53
- );
34
+ const finish = (commit = true) => {
35
+ const active = drag.current;
36
+ if (!active) return;
37
+ if (active.frame !== null) cancelAnimationFrame(active.frame);
38
+ if (commit) flush();
39
+ // Release can synchronously dispatch lostpointercapture.
40
+ drag.current = null;
41
+ try {
42
+ if (active.target.hasPointerCapture(active.pointerId)) {
43
+ active.target.releasePointerCapture(active.pointerId);
44
+ }
45
+ } catch {}
46
+ document.body.style.removeProperty("cursor");
47
+ document.body.style.removeProperty("user-select");
48
+ active.session.cleanup?.(commit);
49
+ if (commit) active.session.finish(active.width, active.moved);
50
+ };
51
+
52
+ // The effects must not rerun while a drag is live: their cleanup cancels it.
53
+ const finishDrag = useEffectEvent((commit: boolean) => finish(commit));
54
55
const previousResetKey = useRef(resetKey);
56
useLayoutEffect(() => {
57
if (previousResetKey.current !== resetKey) {
58
- finish(false);
58
+ finishDrag(false);
59
previousResetKey.current = resetKey;
60
}
61
- }, [finish, resetKey]);
61
+ }, [resetKey]);
62
63
useEffect(() => {
64
- const onBlur = () => finish();
64
+ const onBlur = () => finishDrag(true);
65
window.addEventListener("blur", onBlur);
66
return () => {
67
window.removeEventListener("blur", onBlur);
68
- finish(false);
68
+ finishDrag(false);
69
};
70
- }, [finish]);
70
+ }, []);
71
72
const end = (event: PointerEvent<T>, usePosition: boolean) => {
73
const active = drag.current;
@@ -109,7 +109,7 @@ export function useResizeDrag<T extends HTMLElement>(
109
if (!active || active.pointerId !== event.pointerId) return;
110
event.preventDefault();
111
active.pendingX = event.clientX;
112
- active.moved ||= Math.abs(event.clientX - active.startX) > 2;
112
+ if (Math.abs(event.clientX - active.startX) > 2) active.moved = true;
113
if (active.frame !== null) return;
114
active.frame = requestAnimationFrame(() => {
115
active.frame = null;