@devries-cameron20 / t3code Mirror · read-only / commits / 4a9516d3d5
Fork 0

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 header compiles with the React Compiler (#20656)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Oct 16, 2026 at 21:56 UTC 4a9516d3d5e73869fc9d33b744b31ef2f26ba404
1 file changed +93 -104
apps/web/src/components/chat/ChatHeader.tsx
+93 -104
@@ -12,9 +12,7 @@ import {
12 import { ChevronDownIcon } from "lucide-react";
13 import {
14 memo,
15 - useCallback,
15 useEffect,
17 - useMemo,
16 useRef,
17 useState,
18 type KeyboardEvent as ReactKeyboardEvent,
@@ -26,7 +24,6 @@ import { toastManager } from "../ui/toast";
24 import { useThreadActionMenu } from "~/hooks/useThreadActionMenu";
25 import { readLocalApi } from "~/localApi";
26 import { threadEnvironment } from "../../state/threads";
29 -import { useAtomCommand } from "../../state/use-atom-command";
27 import { useOrchestrationCommand } from "../../state/use-orchestration-command";
28 import { readEnvironmentScope, useEnvironmentScope } from "../../state/session";
29 import { ProjectFavicon } from "../ProjectFavicon";
@@ -85,10 +82,7 @@ export const ChatHeader = memo(function ChatHeader({
82 const interfaceFont = useClientSettings((settings) => settings.fontFamilySans);
83 const breadcrumbContainerRef = useRef<HTMLDivElement>(null);
84 const [collapseParentTitle, setCollapseParentTitle] = useState(false);
88 - const activeThreadRef = useMemo(
89 - () => scopeThreadRef(activeThreadEnvironmentId, activeThreadId),
90 - [activeThreadEnvironmentId, activeThreadId],
91 - );
85 + const activeThreadRef = scopeThreadRef(activeThreadEnvironmentId, activeThreadId);
86 const canOperateThread = useEnvironmentScope(
87 activeThreadEnvironmentId,
88 AuthOrchestrationOperateScope,
@@ -147,9 +141,16 @@ export const ChatHeader = memo(function ChatHeader({
141 document.fonts.removeEventListener("loadingdone", measure);
142 stopObserving();
143 };
150 - }, [activeProjectName, activeThreadTitle, parentThreadLink, interfaceFont, isRenamingTitle]);
144 + }, [
145 + // oxlint-disable-next-line react/exhaustive-effect-dependencies -- Title, font and rename changes resize the breadcrumb text without resizing the list, so it re-measures.
146 + activeProjectName,
147 + activeThreadTitle,
148 + parentThreadLink,
149 + interfaceFont,
150 + isRenamingTitle,
151 + ]);
152 const renameCommittedRef = useRef(false);
152 - const startRename = useCallback(() => {
153 + const startRename = () => {
154 if (
155 !isServerThread ||
156 !readEnvironmentScope(activeThreadEnvironmentId, AuthOrchestrationOperateScope)
@@ -161,33 +162,30 @@ export const ChatHeader = memo(function ChatHeader({
162 threadId: activeThreadId,
163 title: activeThreadTitle,
164 });
164 - }, [activeThreadEnvironmentId, activeThreadId, activeThreadTitle, isServerThread]);
165 - const commitRename = useCallback(
166 - (title: string) => {
167 - setRenaming(null);
168 - if (!readEnvironmentScope(activeThreadEnvironmentId, AuthOrchestrationOperateScope)) return;
169 - const resolution = resolveRenameCommit({ title, originalTitle: activeThreadTitle });
170 - if (resolution.action === "reject-empty") {
171 - toastManager.add({ type: "warning", title: "Thread title cannot be empty" });
172 - return;
165 + };
166 + const commitRename = (title: string) => {
167 + setRenaming(null);
168 + if (!readEnvironmentScope(activeThreadEnvironmentId, AuthOrchestrationOperateScope)) return;
169 + const resolution = resolveRenameCommit({ title, originalTitle: activeThreadTitle });
170 + if (resolution.action === "reject-empty") {
171 + toastManager.add({ type: "warning", title: "Thread title cannot be empty" });
172 + return;
173 + }
174 + if (resolution.action === "noop") return;
175 + void updateThreadMetadata({
176 + environmentId: activeThreadEnvironmentId,
177 + input: { threadId: activeThreadId, title: resolution.title },
178 + }).then((result) => {
179 + if (result._tag === "Failure" && !isAtomCommandInterrupted(result)) {
180 + const error = squashAtomCommandFailure(result);
181 + toastManager.add({
182 + type: "error",
183 + title: "Failed to rename thread",
184 + description: error instanceof Error ? error.message : "An error occurred.",
185 + });
186 }
174 - if (resolution.action === "noop") return;
175 - void updateThreadMetadata({
176 - environmentId: activeThreadEnvironmentId,
177 - input: { threadId: activeThreadId, title: resolution.title },
178 - }).then((result) => {
179 - if (result._tag === "Failure" && !isAtomCommandInterrupted(result)) {
180 - const error = squashAtomCommandFailure(result);
181 - toastManager.add({
182 - type: "error",
183 - title: "Failed to rename thread",
184 - description: error instanceof Error ? error.message : "An error occurred.",
185 - });
186 - }
187 - });
188 - },
189 - [activeThreadEnvironmentId, activeThreadId, activeThreadTitle, updateThreadMetadata],
190 - );
187 + });
188 + };
189 const { openMenu, closeMenu } = useThreadActionMenu({
190 threadRef: isServerThread ? activeThreadRef : null,
191 projectCwd: activeProjectCwd,
@@ -195,86 +193,77 @@ export const ChatHeader = memo(function ChatHeader({
193 });
194 const titleButtonRef = useRef<HTMLButtonElement | null>(null);
195 const titleMenuTimerRef = useRef<number | null>(null);
198 - const cancelPendingTitleMenu = useCallback(() => {
196 + const cancelPendingTitleMenu = () => {
197 if (titleMenuTimerRef.current === null) return;
198 clearTimeout(titleMenuTimerRef.current);
199 titleMenuTimerRef.current = null;
202 - }, []);
200 + };
201 useEffect(
202 () => () => {
205 - cancelPendingTitleMenu();
203 + if (titleMenuTimerRef.current === null) return;
204 + clearTimeout(titleMenuTimerRef.current);
205 + titleMenuTimerRef.current = null;
206 },
207 - [activeThreadEnvironmentId, activeThreadId, cancelPendingTitleMenu],
207 + // oxlint-disable-next-line react/exhaustive-effect-dependencies -- A pending title menu belongs to the thread that was clicked, so switching threads drops it.
208 + [activeThreadEnvironmentId, activeThreadId],
209 );
209 - const openTitleMenuNow = useCallback(() => {
210 + const openTitleMenuNow = () => {
211 cancelPendingTitleMenu();
212 const rect = titleButtonRef.current?.getBoundingClientRect();
213 if (!rect) return;
214 openMenu({ x: rect.left, y: rect.bottom + 4 });
214 - }, [cancelPendingTitleMenu, openMenu]);
215 - const openMenuFromTitle = useCallback(
216 - (event: ReactMouseEvent<HTMLButtonElement>) => {
217 - if (isTrailingDoubleClick(event.detail)) return;
218 - const clickedChevron =
219 - (event.target as HTMLElement).closest("[data-thread-title-chevron]") !== null;
220 - if (event.detail === 0 || clickedChevron || window.desktopBridge === undefined) {
221 - openTitleMenuNow();
222 - return;
223 - }
224 - cancelPendingTitleMenu();
225 - titleMenuTimerRef.current = window.setTimeout(() => {
226 - titleMenuTimerRef.current = null;
227 - openTitleMenuNow();
228 - }, TITLE_MENU_OPEN_DELAY_MS);
229 - },
230 - [cancelPendingTitleMenu, openTitleMenuNow],
231 - );
232 - const handleTitleDoubleClick = useCallback(
233 - (event: ReactMouseEvent) => {
234 - if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return;
235 - if ((event.target as HTMLElement).closest("[data-thread-title-chevron]") !== null) return;
236 - cancelPendingTitleMenu();
237 - closeMenu();
238 - startRename();
239 - },
240 - [cancelPendingTitleMenu, closeMenu, startRename],
241 - );
242 - const handleHeaderContextMenu = useCallback(
243 - (event: ReactMouseEvent) => {
244 - if (renamingTitle !== null) return;
245 - if (!isServerThread && onOpenProjectSettings === undefined) return;
246 - cancelPendingTitleMenu();
247 - event.preventDefault();
248 - if (!isServerThread) {
249 - const api = readLocalApi();
250 - if (!api) return;
251 - void api.contextMenu
252 - .show([{ id: "project-settings", label: "Project settings", icon: "settings" }], {
253 - x: event.clientX,
254 - y: event.clientY,
255 - })
256 - .then((action) => {
257 - if (action === "project-settings") onOpenProjectSettings?.();
258 - });
259 - return;
260 - }
261 - openMenu({ x: event.clientX, y: event.clientY });
262 - },
263 - [cancelPendingTitleMenu, isServerThread, onOpenProjectSettings, openMenu, renamingTitle],
264 - );
265 - const handleRenameKeyDown = useCallback(
266 - (event: ReactKeyboardEvent<HTMLInputElement>) => {
267 - if (event.nativeEvent.isComposing || event.keyCode === 229) return;
268 - if (event.key === "Enter") {
269 - renameCommittedRef.current = true;
270 - commitRename(event.currentTarget.value);
271 - } else if (event.key === "Escape") {
272 - renameCommittedRef.current = true;
273 - setRenaming(null);
274 - }
275 - },
276 - [commitRename],
277 - );
215 + };
216 + const openMenuFromTitle = (event: ReactMouseEvent<HTMLButtonElement>) => {
217 + if (isTrailingDoubleClick(event.detail)) return;
218 + const clickedChevron =
219 + (event.target as HTMLElement).closest("[data-thread-title-chevron]") !== null;
220 + if (event.detail === 0 || clickedChevron || window.desktopBridge === undefined) {
221 + openTitleMenuNow();
222 + return;
223 + }
224 + cancelPendingTitleMenu();
225 + titleMenuTimerRef.current = window.setTimeout(() => {
226 + titleMenuTimerRef.current = null;
227 + openTitleMenuNow();
228 + }, TITLE_MENU_OPEN_DELAY_MS);
229 + };
230 + const handleTitleDoubleClick = (event: ReactMouseEvent) => {
231 + if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return;
232 + if ((event.target as HTMLElement).closest("[data-thread-title-chevron]") !== null) return;
233 + cancelPendingTitleMenu();
234 + closeMenu();
235 + startRename();
236 + };
237 + const handleHeaderContextMenu = (event: ReactMouseEvent) => {
238 + if (renamingTitle !== null) return;
239 + if (!isServerThread && onOpenProjectSettings === undefined) return;
240 + cancelPendingTitleMenu();
241 + event.preventDefault();
242 + if (!isServerThread) {
243 + const api = readLocalApi();
244 + if (!api) return;
245 + void api.contextMenu
246 + .show([{ id: "project-settings", label: "Project settings", icon: "settings" }], {
247 + x: event.clientX,
248 + y: event.clientY,
249 + })
250 + .then((action) => {
251 + if (action === "project-settings") onOpenProjectSettings?.();
252 + });
253 + return;
254 + }
255 + openMenu({ x: event.clientX, y: event.clientY });
256 + };
257 + const handleRenameKeyDown = (event: ReactKeyboardEvent<HTMLInputElement>) => {
258 + if (event.nativeEvent.isComposing || event.keyCode === 229) return;
259 + if (event.key === "Enter") {
260 + renameCommittedRef.current = true;
261 + commitRename(event.currentTarget.value);
262 + } else if (event.key === "Escape") {
263 + renameCommittedRef.current = true;
264 + setRenaming(null);
265 + }
266 + };
267 return (
268 <div
269 ref={breadcrumbContainerRef}