The best way to control Claude Code, Codex and more from any computer or phone
perf(web): the right panel tabs compile with the React Compiler (#20662)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 16, 2026 at 21:56 UTC
afb8da0094cbadc5dd3f23cc4aaf921d2c885492
1 file changed
+116
-135
apps/web/src/components/RightPanelTabs.tsx
+116
-135
@@ -43,10 +43,8 @@ import {
43
type MouseEvent as ReactMouseEvent,
44
type ReactElement,
45
type ReactNode,
46
- useCallback,
46
useEffect,
47
useEffectEvent,
49
- useMemo,
48
useRef,
49
useState,
50
} from "react";
@@ -392,21 +390,18 @@ function RightPanelEmptyState(props: {
390
const highlightIndex =
391
availableActions.length === 0 ? -1 : Math.min(highlight, availableActions.length - 1);
392
395
- const shortcutActionsRef = useRef(availableActions);
396
- useEffect(() => {
397
- shortcutActionsRef.current = availableActions;
393
+ const handleShortcut = useEffectEvent((event: KeyboardEvent) => {
394
+ const action = surfaceShortcutActionForKey(availableActions, event);
395
+ if (!action) return;
396
+ if (document.querySelector(LAUNCHER_SHORTCUT_BLOCKING_LAYERS)) return;
397
+ const target = event.composedPath()[0] ?? event.target;
398
+ if (target instanceof Element && surfaceShortcutTargetsTypingContext(target)) return;
399
+ event.preventDefault();
400
+ event.stopPropagation();
401
+ action.onClick();
402
});
403
useEffect(() => {
400
- const handler = (event: KeyboardEvent) => {
401
- const action = surfaceShortcutActionForKey(shortcutActionsRef.current, event);
402
- if (!action) return;
403
- if (document.querySelector(LAUNCHER_SHORTCUT_BLOCKING_LAYERS)) return;
404
- const target = event.composedPath()[0] ?? event.target;
405
- if (target instanceof Element && surfaceShortcutTargetsTypingContext(target)) return;
406
- event.preventDefault();
407
- event.stopPropagation();
408
- action.onClick();
409
- };
404
+ const handler = (event: KeyboardEvent) => handleShortcut(event);
405
window.addEventListener("keydown", handler, true);
406
return () => window.removeEventListener("keydown", handler, true);
407
}, []);
@@ -437,12 +432,6 @@ function RightPanelEmptyState(props: {
432
}
433
};
434
440
- // Stable identity so React only runs this callback ref on mount/unmount;
441
- // an inline arrow would re-attach and re-focus on every render.
442
- const focusOnMount = useCallback((node: HTMLDivElement | null) => {
443
- node?.focus();
444
- }, []);
445
-
435
const isHighlighted = (action: SurfaceAction) =>
436
highlightIndex !== -1 && availableActions[highlightIndex] === action;
437
@@ -744,14 +733,11 @@ function PullRequestSurfaceIcon({
733
},
734
}),
735
).data;
747
- const reference = useMemo(
748
- () => ({
749
- projectId: surface.projectId as ProjectId,
750
- repository: surface.repository,
751
- number: surface.number,
752
- }),
753
- [surface.projectId, surface.repository, surface.number],
754
- );
736
+ const reference = {
737
+ projectId: surface.projectId as ProjectId,
738
+ repository: surface.repository,
739
+ number: surface.number,
740
+ };
741
const sharedSummary = useSharedPullRequestSummary(resolvedEnvironmentId, reference, null);
742
const status = linkedSnapshot ?? newestPullRequestSummary(detail, sharedSummary) ?? seed ?? null;
743
if (status === null) {
@@ -764,22 +750,25 @@ function PullRequestSurfaceIcon({
750
return <presentation.Icon className={cn("size-3 shrink-0", presentation.toneClassName)} />;
751
}
752
753
+// Module-level so React only runs this callback ref on mount and unmount;
754
+// a fresh function would re-attach and re-focus on every render.
755
+function focusOnMount(node: HTMLDivElement | null) {
756
+ node?.focus();
757
+}
758
+
759
function SortableTabList(props: {
760
surfaces: readonly RightPanelSurface[];
761
onMove: ((surfaceId: string, toIndex: number) => void) | undefined;
762
children: ReactNode;
763
}) {
764
const sensors = useSensors(useSensor(PointerSensor, { activationConstraint: { distance: 6 } }));
773
- const surfaceIds = useMemo(() => props.surfaces.map((surface) => surface.id), [props.surfaces]);
765
+ const surfaceIds = props.surfaces.map((surface) => surface.id);
766
const { onMove, surfaces } = props;
775
- const handleDragEnd = useCallback(
776
- ({ active, over }: DragEndEvent) => {
777
- if (!over || active.id === over.id) return;
778
- const toIndex = surfaces.findIndex((surface) => surface.id === over.id);
779
- if (toIndex >= 0) onMove?.(String(active.id), toIndex);
780
- },
781
- [onMove, surfaces],
782
- );
767
+ const handleDragEnd = ({ active, over }: DragEndEvent) => {
768
+ if (!over || active.id === over.id) return;
769
+ const toIndex = surfaces.findIndex((surface) => surface.id === over.id);
770
+ if (toIndex >= 0) onMove?.(String(active.id), toIndex);
771
+ };
772
return (
773
<DndContext
774
sensors={sensors}
@@ -853,7 +842,7 @@ export function RightPanelTabs(props: RightPanelTabsProps) {
842
return () => document.removeEventListener("keydown", onNewSurfaceKeyDown, true);
843
}, [props.open]);
844
856
- const updateTabScrollState = useCallback(() => {
845
+ const updateTabScrollState = () => {
846
const viewport = tabScrollViewport(tabListRef.current);
847
if (!viewport) return;
848
@@ -872,9 +861,9 @@ export function RightPanelTabs(props: RightPanelTabsProps) {
861
}
862
return { hasOverflow, canScrollLeft, canScrollRight };
863
});
875
- }, []);
864
+ };
865
877
- const scrollTabs = useCallback((direction: -1 | 1) => {
866
+ const scrollTabs = (direction: -1 | 1) => {
867
const viewport = tabScrollViewport(tabListRef.current);
868
if (!viewport) return;
869
const reduceMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
@@ -882,7 +871,7 @@ export function RightPanelTabs(props: RightPanelTabsProps) {
871
left: direction * Math.max(120, viewport.clientWidth * 0.75),
872
behavior: reduceMotion ? "auto" : "smooth",
873
});
885
- }, []);
874
+ };
875
876
const addSurfaceActions = [
877
{
@@ -952,107 +941,99 @@ export function RightPanelTabs(props: RightPanelTabsProps) {
941
action.onClick();
942
};
943
955
- const handleTabContextMenu = useCallback(
956
- async (event: ReactMouseEvent, surface: RightPanelSurface) => {
957
- event.preventDefault();
958
- event.stopPropagation();
944
+ const handleTabContextMenu = async (event: ReactMouseEvent, surface: RightPanelSurface) => {
945
+ event.preventDefault();
946
+ event.stopPropagation();
947
960
- const api = readLocalApi();
961
- if (!api) return;
948
+ const api = readLocalApi();
949
+ if (!api) return;
950
963
- const surfaceIndex = props.surfaces.findIndex((entry) => entry.id === surface.id);
964
- if (surfaceIndex < 0) return;
951
+ const surfaceIndex = props.surfaces.findIndex((entry) => entry.id === surface.id);
952
+ if (surfaceIndex < 0) return;
953
966
- const items: ContextMenuItem<TabContextMenuAction>[] = [];
967
- if (surface.kind === "device" && props.onRenameDevice)
968
- items.push({ id: "rename", label: "Rename" });
969
- if (surface.kind === "file" && surface.attachment === undefined) {
970
- items.push({ id: "copy-path", label: "Copy path" });
971
- }
972
- const menuPreviewTabId = previewTabIdOf(surface, props.previewSessions);
973
- const menuOverlay = menuPreviewTabId
974
- ? (props.desktopByTabId[menuPreviewTabId] ?? null)
975
- : null;
976
- const menuMuted = menuOverlay?.audioMuted ?? false;
977
- if (surface.kind === "preview") {
978
- items.push({
979
- id: "toggle-mute",
980
- ...tabMuteMenuItem({
981
- overlay: menuOverlay,
982
- canResolveRuntimeTabId: props.previewRuntimeTabId !== undefined,
983
- }),
984
- });
985
- }
986
- items.push(
987
- { id: "close", label: "Close" },
988
- {
989
- id: "close-others",
990
- label: "Close others",
991
- disabled: props.surfaces.length <= 1,
992
- },
993
- {
994
- id: "close-to-right",
995
- label: "Close to the right",
996
- disabled: surfaceIndex >= props.surfaces.length - 1,
997
- },
998
- {
999
- id: "close-all",
1000
- label: "Close all",
1001
- disabled: props.surfaces.length === 0,
1002
- },
1003
- );
954
+ const items: ContextMenuItem<TabContextMenuAction>[] = [];
955
+ if (surface.kind === "device" && props.onRenameDevice)
956
+ items.push({ id: "rename", label: "Rename" });
957
+ if (surface.kind === "file" && surface.attachment === undefined) {
958
+ items.push({ id: "copy-path", label: "Copy path" });
959
+ }
960
+ const menuPreviewTabId = previewTabIdOf(surface, props.previewSessions);
961
+ const menuOverlay = menuPreviewTabId ? (props.desktopByTabId[menuPreviewTabId] ?? null) : null;
962
+ const menuMuted = menuOverlay?.audioMuted ?? false;
963
+ if (surface.kind === "preview") {
964
+ items.push({
965
+ id: "toggle-mute",
966
+ ...tabMuteMenuItem({
967
+ overlay: menuOverlay,
968
+ canResolveRuntimeTabId: props.previewRuntimeTabId !== undefined,
969
+ }),
970
+ });
971
+ }
972
+ items.push(
973
+ { id: "close", label: "Close" },
974
+ {
975
+ id: "close-others",
976
+ label: "Close others",
977
+ disabled: props.surfaces.length <= 1,
978
+ },
979
+ {
980
+ id: "close-to-right",
981
+ label: "Close to the right",
982
+ disabled: surfaceIndex >= props.surfaces.length - 1,
983
+ },
984
+ {
985
+ id: "close-all",
986
+ label: "Close all",
987
+ disabled: props.surfaces.length === 0,
988
+ },
989
+ );
990
1005
- const action = await api.contextMenu.show(items, { x: event.clientX, y: event.clientY });
1006
- switch (action) {
1007
- case "rename":
1008
- setRenamingDevice(surface.id);
1009
- break;
1010
- case "copy-path":
1011
- if (surface.kind === "file" && surface.attachment === undefined) {
1012
- props.onCopyFilePath(surface.relativePath);
1013
- }
1014
- break;
1015
- case "toggle-mute": {
1016
- const runtimeTabId =
1017
- menuPreviewTabId && menuOverlay
1018
- ? (props.previewRuntimeTabId?.(menuPreviewTabId) ?? null)
1019
- : null;
1020
- if (runtimeTabId) {
1021
- void previewBridge?.setAudioMuted(runtimeTabId, !menuMuted).catch(() => undefined);
1022
- }
1023
- break;
991
+ const action = await api.contextMenu.show(items, { x: event.clientX, y: event.clientY });
992
+ switch (action) {
993
+ case "rename":
994
+ setRenamingDevice(surface.id);
995
+ break;
996
+ case "copy-path":
997
+ if (surface.kind === "file" && surface.attachment === undefined) {
998
+ props.onCopyFilePath(surface.relativePath);
999
}
1025
- case "close":
1026
- props.onCloseSurface(surface);
1027
- break;
1028
- case "close-others":
1029
- props.onCloseOtherSurfaces(surface);
1030
- break;
1031
- case "close-to-right":
1032
- props.onCloseSurfacesToRight(surface);
1033
- break;
1034
- case "close-all":
1035
- props.onCloseAllSurfaces();
1036
- break;
1037
- case null:
1038
- break;
1000
+ break;
1001
+ case "toggle-mute": {
1002
+ const runtimeTabId =
1003
+ menuPreviewTabId && menuOverlay
1004
+ ? (props.previewRuntimeTabId?.(menuPreviewTabId) ?? null)
1005
+ : null;
1006
+ if (runtimeTabId) {
1007
+ void previewBridge?.setAudioMuted(runtimeTabId, !menuMuted).catch(() => undefined);
1008
+ }
1009
+ break;
1010
}
1040
- },
1041
- [props],
1042
- );
1043
- const handleTabMouseDown = useCallback((event: ReactMouseEvent) => {
1011
+ case "close":
1012
+ props.onCloseSurface(surface);
1013
+ break;
1014
+ case "close-others":
1015
+ props.onCloseOtherSurfaces(surface);
1016
+ break;
1017
+ case "close-to-right":
1018
+ props.onCloseSurfacesToRight(surface);
1019
+ break;
1020
+ case "close-all":
1021
+ props.onCloseAllSurfaces();
1022
+ break;
1023
+ case null:
1024
+ break;
1025
+ }
1026
+ };
1027
+ const handleTabMouseDown = (event: ReactMouseEvent) => {
1028
if (event.button !== 1) return;
1029
event.preventDefault();
1046
- }, []);
1047
- const handleTabAuxClick = useCallback(
1048
- (event: ReactMouseEvent, surface: RightPanelSurface) => {
1049
- if (event.button !== 1) return;
1050
- event.preventDefault();
1051
- event.stopPropagation();
1052
- props.onCloseSurface(surface);
1053
- },
1054
- [props],
1055
- );
1030
+ };
1031
+ const handleTabAuxClick = (event: ReactMouseEvent, surface: RightPanelSurface) => {
1032
+ if (event.button !== 1) return;
1033
+ event.preventDefault();
1034
+ event.stopPropagation();
1035
+ props.onCloseSurface(surface);
1036
+ };
1037
1038
useEffect(() => {
1039
if (!props.activeSurfaceId || !tabScrollState.hasOverflow) return;