@devries-cameron20 / t3code-1 / commits / 10d4fab294
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

perf(web): branch toolbar label measuring reads its state through useEffectEvent (#20467)

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

Julius Marminge committed Oct 16, 2026 at 18:46 UTC 10d4fab2941f89707f08d441fac1b9b24f48d80c
2 files changed +22 -37
apps/web/reactCompiledFiles.ts
+1
@@ -42,4 +42,5 @@ export const REACT_COMPILED_FILES = [
42 "apps/web/src/hooks/useLiveRefresh.ts",
43 "apps/web/src/browser/useBrowserViewportResize.ts",
44 "apps/web/src/components/desktop/SnapShotCoordinator.tsx",
45 + "apps/web/src/components/BranchToolbar.tsx",
46 ] as const;
apps/web/src/components/BranchToolbar.tsx
+21 -37
@@ -16,10 +16,9 @@ import {
16 type MouseEvent as ReactMouseEvent,
17 memo,
18 useImperativeHandle,
19 - useCallback,
19 useEffect,
20 + useEffectEvent,
21 useLayoutEffect,
22 - useMemo,
22 useRef,
23 useState,
24 } from "react";
@@ -179,10 +178,8 @@ const RunContextSelector = memo(function RunContextSelector({
178 onUsePreviousWorktree,
179 }: RunContextSelectorProps) {
180 const composerFloatingLayerProps = useComposerMenuProps();
182 - const activeEnvironment = useMemo(
183 - () => availableEnvironments?.find((env) => env.environmentId === environmentId) ?? null,
184 - [availableEnvironments, environmentId],
185 - );
181 + const activeEnvironment =
182 + availableEnvironments?.find((env) => env.environmentId === environmentId) ?? null;
183 const WorkspaceIcon =
184 effectiveEnvMode === "worktree"
185 ? FolderGit2Icon
@@ -425,14 +422,9 @@ function useLabelsOverflow(element: HTMLDivElement | null): boolean {
422 const [overflows, setOverflows] = useState(false);
423 const pendingLabelRectsRef = useRef<Map<HTMLElement, DOMRect> | null>(null);
424 const labelAnimationsRef = useRef(new Map<HTMLElement, Animation>());
428 - // A render-synced mirror instead of useEffectEvent: the compiler memoizes
429 - // the event callback, which left observers reading the first render's null
430 - // element forever.
431 - const stateRef = useRef({ element, overflows });
432 - stateRef.current = { element, overflows };
433 -
434 - const measure = useCallback(() => {
435 - const { element: current, overflows: compact } = stateRef.current;
425 + const measure = useEffectEvent(() => {
426 + const current = element;
427 + const compact = overflows;
428 if (!current) return;
429 const available = current.clientWidth;
430 if (available === 0) return;
@@ -495,7 +487,7 @@ function useLabelsOverflow(element: HTMLDivElement | null): boolean {
487 );
488 }
489 setOverflows(nextOverflows);
498 - }, []);
490 + });
491
492 useLayoutEffect(() => {
493 const previousRects = pendingLabelRectsRef.current;
@@ -536,7 +528,7 @@ function useLabelsOverflow(element: HTMLDivElement | null): boolean {
528 { once: true },
529 );
530 }
539 - }, [overflows]);
531 + });
532
533 useEffect(
534 () => () => {
@@ -548,6 +540,7 @@ function useLabelsOverflow(element: HTMLDivElement | null): boolean {
540 );
541
542 useLayoutEffect(() => {
543 + // oxlint-disable-next-line react/set-state-in-effect -- The label mode comes from measuring the committed DOM, which render cannot read.
544 measure();
545 });
546
@@ -559,7 +552,7 @@ function useLabelsOverflow(element: HTMLDivElement | null): boolean {
552 stopObserving();
553 document.fonts.removeEventListener("loadingdone", measure);
554 };
562 - }, [element, measure]);
555 + }, [element]);
556
557 return overflows;
558 }
@@ -590,10 +583,7 @@ export const BranchToolbar = memo(function BranchToolbar({
583 contextStripVisible = true,
584 }: BranchToolbarProps) {
585 const branchSelectorRef = useRef<BranchToolbarBranchSelectorHandle>(null);
593 - const threadRef = useMemo(
594 - () => scopeThreadRef(environmentId, threadId),
595 - [environmentId, threadId],
596 - );
586 + const threadRef = scopeThreadRef(environmentId, threadId);
587 const draftThread = useComposerDraftStore((store) =>
588 draftId ? store.getDraftSession(draftId) : store.getDraftThreadByRef(threadRef),
589 );
@@ -614,25 +604,19 @@ export const BranchToolbar = memo(function BranchToolbar({
604
605 const canUsePreviousWorktree =
606 draftThread !== null && serverThread === null && !envModeLocked && !forceNewWorktree;
617 - const projectRefsForWorktreeLookup = useMemo(
618 - () => (canUsePreviousWorktree && activeProjectRef ? [activeProjectRef] : []),
619 - [canUsePreviousWorktree, activeProjectRef],
620 - );
607 + const projectRefsForWorktreeLookup =
608 + canUsePreviousWorktree && activeProjectRef ? [activeProjectRef] : [];
609 const projectThreads = useThreadShellsForProjectRefs(projectRefsForWorktreeLookup);
622 - const previousWorktreeSeed = useMemo(
623 - () =>
624 - canUsePreviousWorktree
625 - ? resolvePreviousWorktreeSeed({
626 - threads: projectThreads,
627 - currentWorktreePath: activeWorktreePath,
628 - })
629 - : null,
630 - [activeWorktreePath, canUsePreviousWorktree, projectThreads],
631 - );
610 + const previousWorktreeSeed = canUsePreviousWorktree
611 + ? resolvePreviousWorktreeSeed({
612 + threads: projectThreads,
613 + currentWorktreePath: activeWorktreePath,
614 + })
615 + : null;
616 const previousWorktreeLabel = previousWorktreeSeed
617 ? resolvePreviousWorktreeLabel(previousWorktreeSeed)
618 : null;
635 - const onUsePreviousWorktree = useCallback(() => {
619 + const onUsePreviousWorktree = () => {
620 if (!previousWorktreeSeed || !activeProjectRef) return;
621 setDraftThreadContext(draftId ?? threadRef, {
622 branch: previousWorktreeSeed.branch,
@@ -640,7 +624,7 @@ export const BranchToolbar = memo(function BranchToolbar({
624 envMode: "worktree",
625 projectRef: activeProjectRef,
626 });
643 - }, [activeProjectRef, draftId, previousWorktreeSeed, setDraftThreadContext, threadRef]);
627 + };
628
629 useImperativeHandle(
630 ref,