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): the chat canvas compiles without manual memoization (#20654)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 16, 2026 at 21:56 UTC
4e8c01c1bc251bf948adb0c0484b8b4b9aba8c74
1 file changed
+29
-49
apps/web/src/components/chat/ChatCanvas.tsx
+29
-49
@@ -1,12 +1,4 @@
1
-import {
2
- useCallback,
3
- useLayoutEffect,
4
- useMemo,
5
- useRef,
6
- useState,
7
- type ComponentProps,
8
- type CSSProperties,
9
-} from "react";
1
+import { useLayoutEffect, useRef, useState, type ComponentProps, type CSSProperties } from "react";
2
import { ChatCanvasContext } from "./ChatCanvasContext";
3
import { resolveChatCanvasLayout, type ChatCanvasPreview } from "./chatCanvasLayout";
4
import type { PreviewMiniPlayerObstacles } from "../preview/previewMiniPlayerLayout";
@@ -26,7 +18,7 @@ export function ChatCanvas({
18
const [timelineElement, registerTimeline] = useState<HTMLElement | null>(null);
19
const [preview, setPreview] = useState<ChatCanvasPreview | null>(null);
20
const [detailsCard, setDetailsCard] = useState<PreviewMiniPlayerObstacles["detailsCard"]>(null);
29
- const reportDetailsCard = useCallback((next: PreviewMiniPlayerObstacles["detailsCard"]) => {
21
+ const reportDetailsCard = (next: PreviewMiniPlayerObstacles["detailsCard"]) => {
22
setDetailsCard((current) =>
23
current?.left === next?.left &&
24
current?.right === next?.right &&
@@ -34,7 +26,7 @@ export function ChatCanvas({
26
? current
27
: next,
28
);
37
- }, []);
29
+ };
30
const [measurements, setMeasurements] = useState({
31
width: 0,
32
height: 0,
@@ -47,7 +39,7 @@ export function ChatCanvas({
39
findBarRight: 0,
40
findBarBottom: 0,
41
});
50
- const reportPreview = useCallback((next: ChatCanvasPreview) => {
42
+ const reportPreview = (next: ChatCanvasPreview) => {
43
setPreview((current) =>
44
current?.key === next.key &&
45
current.width === next.width &&
@@ -59,11 +51,9 @@ export function ChatCanvas({
51
? current
52
: next,
53
);
62
- }, []);
63
- const clearPreview = useCallback(
64
- (key: string) => setPreview((current) => (current?.key === key ? null : current)),
65
- [],
66
- );
54
+ };
55
+ const clearPreview = (key: string) =>
56
+ setPreview((current) => (current?.key === key ? null : current));
57
useLayoutEffect(() => {
58
const element = elementRef.current;
59
const probe = widthProbeRef.current;
@@ -103,42 +93,32 @@ export function ChatCanvas({
93
if (timelineElement) observed.push(timelineElement);
94
return observeResize(observed, measure);
95
}, [composerOverlayElement, timelineElement, detailsCardTopInset]);
106
- const context = useMemo(() => {
107
- const container = { width: measurements.width, height: measurements.height };
108
- const findBar =
109
- detailsCardTopInset > 0
110
- ? {
111
- left: measurements.findBarLeft,
112
- right: measurements.findBarRight,
113
- bottom: measurements.findBarBottom,
114
- }
115
- : null;
116
- return {
96
+ const container = { width: measurements.width, height: measurements.height };
97
+ const findBar =
98
+ detailsCardTopInset > 0
99
+ ? {
100
+ left: measurements.findBarLeft,
101
+ right: measurements.findBarRight,
102
+ bottom: measurements.findBarBottom,
103
+ }
104
+ : null;
105
+ const context = {
106
+ container,
107
+ lane: { padding: measurements.padding, minChatWidth: measurements.minChatWidth },
108
+ layout: resolveChatCanvasLayout({
109
+ ...measurements,
110
container,
118
- lane: { padding: measurements.padding, minChatWidth: measurements.minChatWidth },
119
- layout: resolveChatCanvasLayout({
120
- ...measurements,
121
- container,
122
- preview,
123
- detailsCard,
124
- findBar,
125
- }),
126
- previewKey: preview?.key ?? null,
127
- reportPreview,
128
- clearPreview,
129
- registerTimeline,
130
- reportDetailsCard,
131
- detailsCardTopInset: findBar?.bottom ?? 0,
132
- };
133
- }, [
134
- measurements,
135
- preview,
136
- detailsCard,
111
+ preview,
112
+ detailsCard,
113
+ findBar,
114
+ }),
115
+ previewKey: preview?.key ?? null,
116
reportPreview,
117
clearPreview,
118
+ registerTimeline,
119
reportDetailsCard,
140
- detailsCardTopInset,
141
- ]);
120
+ detailsCardTopInset: findBar?.bottom ?? 0,
121
+ };
122
const { layout } = context;
123
return (
124
<ChatCanvasContext value={context}>