@devries-cameron20 / t3code-1 / commits / 26438213b5
Fork 0

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

perf(web): the Electron browser host compiles with the React Compiler (#20548)

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

Julius Marminge committed Oct 16, 2026 at 21:53 UTC 26438213b50946fc02d58065f8886924dc13c166
1 file changed +39 -50
apps/web/src/browser/ElectronBrowserHost.tsx
+39 -50
@@ -1,15 +1,18 @@
1 "use client";
2
3 import { parseScopedThreadKey } from "@t3tools/client-runtime/environment";
4 -import { AuthPreviewOperateScope, FILL_PREVIEW_VIEWPORT } from "@t3tools/contracts";
4 +import {
5 + AuthPreviewOperateScope,
6 + type DesktopPreviewOpenLinkEvent,
7 + FILL_PREVIEW_VIEWPORT,
8 +} from "@t3tools/contracts";
9 import { useAtomValue } from "@effect/atom-react";
6 -import { type ComponentProps, useEffect, useMemo, useRef, useState } from "react";
10 +import { type ComponentProps, useEffect, useEffectEvent, useState } from "react";
11
12 import { primaryEnvironmentIdAtom } from "~/state/primaryEnvironment";
13
14 import { isElectron } from "~/env";
15 import { useClientSettingsHydrated } from "~/hooks/useSettings";
12 -import { useTheme } from "~/hooks/useTheme";
16 import { useActivePreviewSessions } from "~/previewStateStore";
17 import { previewEnvironment } from "~/state/preview";
18 import { useEnvironmentScope } from "~/state/session";
@@ -24,36 +27,27 @@ import { rendersServerTabNatively } from "./previewRuntime";
27 import { previewRuntimeTabId } from "./previewRuntimeTabId";
28
29 export function ElectronBrowserHost() {
27 - const { resolvedTheme } = useTheme();
30 const previewByThreadKey = useActivePreviewSessions();
31 const primaryEnvironmentId = useAtomValue(primaryEnvironmentIdAtom);
30 - const sessions = useMemo(
31 - () =>
32 - Object.entries(previewByThreadKey).flatMap(([threadKey, previewState]) => {
33 - const threadRef = parseScopedThreadKey(threadKey);
34 - return threadRef
35 - ? Object.values(previewState.sessions)
36 - .filter(
37 - (snapshot) =>
38 - snapshot.runtime !== "server" ||
39 - rendersServerTabNatively(threadRef.environmentId, primaryEnvironmentId, snapshot),
40 - )
41 - .map((snapshot) => ({
42 - threadRef,
43 - snapshot,
44 - runtimeTabId: previewRuntimeTabId(
45 - threadRef,
46 - previewState.serverEpoch,
47 - snapshot.tabId,
48 - ),
49 - pictureInPicture:
50 - previewState.desktopByTabId[snapshot.tabId]?.pictureInPicture ?? false,
51 - zoomFactor: previewState.desktopByTabId[snapshot.tabId]?.zoomFactor ?? 1,
52 - }))
53 - : [];
54 - }),
55 - [previewByThreadKey, primaryEnvironmentId],
56 - );
32 + const sessions = Object.entries(previewByThreadKey).flatMap(([threadKey, previewState]) => {
33 + const threadRef = parseScopedThreadKey(threadKey);
34 + return threadRef
35 + ? Object.values(previewState.sessions)
36 + .filter(
37 + (snapshot) =>
38 + snapshot.runtime !== "server" ||
39 + rendersServerTabNatively(threadRef.environmentId, primaryEnvironmentId, snapshot),
40 + )
41 + .map((snapshot) => ({
42 + threadRef,
43 + snapshot,
44 + runtimeTabId: previewRuntimeTabId(threadRef, previewState.serverEpoch, snapshot.tabId),
45 + pictureInPicture:
46 + previewState.desktopByTabId[snapshot.tabId]?.pictureInPicture ?? false,
47 + zoomFactor: previewState.desktopByTabId[snapshot.tabId]?.zoomFactor ?? 1,
48 + }))
49 + : [];
50 + });
51
52 useEffect(() => {
53 const preview = window.desktopBridge?.preview;
@@ -86,7 +80,7 @@ export function ElectronBrowserHost() {
80 observer.disconnect();
81 headObserver.disconnect();
82 };
89 - }, [resolvedTheme]);
83 + }, []);
84
85 useEffect(() => {
86 const preview = window.desktopBridge?.preview;
@@ -97,27 +91,22 @@ export function ElectronBrowserHost() {
91 }, []);
92
93 const openPreview = useAtomCommand(previewEnvironment.open, { reportFailure: true });
100 - const sessionByRuntimeTabId = useRef(new Map<string, (typeof sessions)[number]>());
101 - useEffect(() => {
102 - sessionByRuntimeTabId.current = new Map(
103 - sessions.map((session) => [session.runtimeTabId, session]),
104 - );
105 - }, [sessions]);
94 + const onOpenLink = useEffectEvent(({ tabId, url, background }: DesktopPreviewOpenLinkEvent) => {
95 + const source = sessions.find((session) => session.runtimeTabId === tabId);
96 + if (!source) return;
97 + void openUrlInPreview({
98 + threadRef: source.threadRef,
99 + url,
100 + openPreview,
101 + profileId: source.snapshot.profileId,
102 + background,
103 + });
104 + });
105 useEffect(() => {
106 const preview = window.desktopBridge?.preview;
107 if (!preview) return;
109 - return preview.onOpenLink(({ tabId, url, background }) => {
110 - const source = sessionByRuntimeTabId.current.get(tabId);
111 - if (!source) return;
112 - void openUrlInPreview({
113 - threadRef: source.threadRef,
114 - url,
115 - openPreview,
116 - profileId: source.snapshot.profileId,
117 - background,
118 - });
119 - });
120 - }, [openPreview]);
108 + return preview.onOpenLink(onOpenLink);
109 + }, []);
110
111 if (!isElectron) return null;
112 return (