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 app sidebar layout compiles with the React Compiler (#20569)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 16, 2026 at 22:06 UTC
8e6ace61666054e367d985a4bec60e8441092afc
1 file changed
+42
-23
apps/web/src/components/AppSidebarLayout.tsx
+42
-23
@@ -68,6 +68,44 @@ function readViewportWidth(): number {
68
return window.innerWidth;
69
}
70
71
+// getWindowFullscreenState is a synchronous IPC round trip, so the snapshot is cached
72
+// and only re-read when a subscription starts.
73
+let windowFullscreenSnapshot: boolean | null = null;
74
+
75
+function macosDesktopBridge() {
76
+ if (!isElectron || !isMacPlatform(navigator.platform)) return null;
77
+ return window.desktopBridge ?? null;
78
+}
79
+
80
+function subscribeToWindowFullscreen(onChange: () => void): () => void {
81
+ const bridge = macosDesktopBridge();
82
+ if (
83
+ typeof bridge?.getWindowFullscreenState !== "function" ||
84
+ typeof bridge.onWindowFullscreenStateChange !== "function"
85
+ ) {
86
+ return () => {};
87
+ }
88
+ const unsubscribe = bridge.onWindowFullscreenStateChange((fullscreen) => {
89
+ windowFullscreenSnapshot = fullscreen;
90
+ onChange();
91
+ });
92
+ // The window may have changed state between the first render and this subscription.
93
+ windowFullscreenSnapshot = bridge.getWindowFullscreenState();
94
+ return () => {
95
+ unsubscribe();
96
+ windowFullscreenSnapshot = null;
97
+ };
98
+}
99
+
100
+function readWindowFullscreen(): boolean {
101
+ if (windowFullscreenSnapshot === null) {
102
+ const getWindowFullscreenState = macosDesktopBridge()?.getWindowFullscreenState;
103
+ windowFullscreenSnapshot =
104
+ typeof getWindowFullscreenState === "function" ? getWindowFullscreenState() : false;
105
+ }
106
+ return windowFullscreenSnapshot;
107
+}
108
+
109
function readInitialThreadSidebarWidth(): number {
110
try {
111
return resolveInitialThreadSidebarWidth(
@@ -245,12 +283,10 @@ export function AppSidebarLayout({ children }: { children: ReactNode }) {
283
}
284
setSidebarWidth(resolveInitialThreadSidebarWidth(null, viewportWidth));
285
};
248
- const [isWindowFullscreen, setIsWindowFullscreen] = useState(() => {
249
- const getWindowFullscreenState = window.desktopBridge?.getWindowFullscreenState;
250
- return isMacosDesktop && typeof getWindowFullscreenState === "function"
251
- ? getWindowFullscreenState()
252
- : false;
253
- });
286
+ const isWindowFullscreen = useSyncExternalStore(
287
+ subscribeToWindowFullscreen,
288
+ readWindowFullscreen,
289
+ );
290
const windowControlsInsetStyle = (
291
isMacosDesktop && !isWindowFullscreen
292
? { "--workspace-controls-left": MACOS_TRAFFIC_LIGHTS_LEFT_INSET }
@@ -262,23 +298,6 @@ export function AppSidebarLayout({ children }: { children: ReactNode }) {
298
...windowControlsInsetStyle,
299
} as CSSProperties;
300
265
- useEffect(() => {
266
- if (!isMacosDesktop) return;
267
- const bridge = window.desktopBridge;
268
- if (!bridge) return;
269
- const { getWindowFullscreenState, onWindowFullscreenStateChange } = bridge;
270
- if (
271
- typeof getWindowFullscreenState !== "function" ||
272
- typeof onWindowFullscreenStateChange !== "function"
273
- ) {
274
- return;
275
- }
276
-
277
- const unsubscribe = onWindowFullscreenStateChange(setIsWindowFullscreen);
278
- setIsWindowFullscreen(getWindowFullscreenState());
279
- return unsubscribe;
280
- }, [isMacosDesktop]);
281
-
301
useEffect(() => {
302
const onMenuAction = window.desktopBridge?.onMenuAction;
303
if (typeof onMenuAction !== "function") {