Skip to content

Commit 2aa9623

Browse files
perf(mobile): device preview compiles with the React Compiler
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent e620e9c commit 2aa9623

3 files changed

Lines changed: 21 additions & 36 deletions

File tree

‎apps/mobile/src/features/devices/DevicePreviewRouteScreen.tsx‎

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
import { useIsFocused, useNavigation, type StaticScreenProps } from "@react-navigation/native";
88
import { EnvironmentId, ThreadId } from "@t3tools/contracts";
99
import * as Cause from "effect/Cause";
10-
import { useCallback, useEffect, useMemo, useRef, useState, type RefObject } from "react";
10+
import { useEffect, useRef, useState, type RefObject } from "react";
1111
import * as Haptics from "expo-haptics";
1212
import { Accelerometer } from "expo-sensors";
1313
import { AppState, BackHandler, Pressable, StatusBar, View } from "react-native";
@@ -47,7 +47,7 @@ type DevicePreviewRouteScreenProps = StaticScreenProps<{
4747

4848
export function DevicePreviewRouteScreen({ route }: DevicePreviewRouteScreenProps) {
4949
const navigation = useNavigation();
50-
const onClose = useCallback(() => navigation.goBack(), [navigation]);
50+
const onClose = () => navigation.goBack();
5151
const { environmentId, threadId } = route.params;
5252
const isBlankLink = environmentId.trim().length === 0 || threadId.trim().length === 0;
5353
useEffect(() => {
@@ -85,15 +85,12 @@ function DevicePreviewScreen({
8585
const shutdown = useAtomCommand(deviceEnvironment.shutdown, { reportFailure: false });
8686
const streamRef = useRef<DeviceStreamRef>(null);
8787
const state = useEnvironmentQuery(deviceEnvironment.state({ environmentId, input: {} }));
88-
const previews = useMemo(
89-
() => threadDevicePreviews(state.data, threadId),
90-
[state.data, threadId],
91-
);
88+
const previews = threadDevicePreviews(state.data, threadId);
9289
const preview = selectedThreadDevicePreview(previews, selectedKey);
93-
const onInputConnected = useCallback(async (connected: boolean) => {
90+
const onInputConnected = async (connected: boolean) => {
9491
setInputConnected(connected);
9592
if (connected) setControlsVisible(false);
96-
}, []);
93+
};
9794
useEffect(() => {
9895
const subscription = AppState.addEventListener("change", (state) =>
9996
setForeground(state !== "background"),
@@ -126,20 +123,16 @@ function DevicePreviewScreen({
126123
const shutDownDevice = async () => {
127124
if (!preview || shuttingDown) return;
128125
setShuttingDown(true);
129-
try {
130-
const result = await shutdown({
131-
environmentId,
132-
input: {
133-
hostId: preview.session.hostId,
134-
deviceId: preview.session.deviceId,
135-
platform: preview.session.platform,
136-
},
137-
});
138-
if (result._tag === "Failure") {
139-
Dialog.alert("Could not shut down device", String(Cause.squash(result.cause)));
140-
}
141-
} finally {
142-
setShuttingDown(false);
126+
const result = await shutdown({
127+
environmentId,
128+
input: {
129+
hostId: preview.session.hostId,
130+
deviceId: preview.session.deviceId,
131+
platform: preview.session.platform,
132+
},
133+
}).finally(() => setShuttingDown(false));
134+
if (result._tag === "Failure") {
135+
Dialog.alert("Could not shut down device", String(Cause.squash(result.cause)));
143136
}
144137
};
145138

@@ -377,10 +370,7 @@ function OpenDevicePreview({
377370
const { session } = preview;
378371
const { themeVariables } = useAppearancePreferences();
379372
const { access, error, refresh } = useDeviceHubAccess(environmentId, session.hostId);
380-
const onUnauthorized = useCallback(
381-
async () => refreshDeviceHubAccess(environmentId),
382-
[environmentId],
383-
);
373+
const onUnauthorized = async () => refreshDeviceHubAccess(environmentId);
384374
useEffect(() => {
385375
refreshDeviceHubAccess(environmentId);
386376
return () => void onInputConnected(false);

‎apps/mobile/src/features/devices/DeviceStreamWebView.tsx‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
useEffectEvent,
55
useImperativeHandle,
66
useLayoutEffect,
7-
useMemo,
87
useRef,
98
useState,
109
type Ref,
@@ -112,14 +111,11 @@ function DeviceStreamDocumentView({
112111
const timer = setTimeout(bootstrapTimedOut, 15_000);
113112
return () => clearTimeout(timer);
114113
}, [started]);
115-
const source = useMemo(
116-
() => ({
117-
html: deviceStreamDocument(configuration, deviceStreamScript),
118-
// Android WebCodecs needs a secure document; streams still use the environment's URLs.
119-
baseUrl: Platform.OS === "android" ? "https://localhost/" : "file:///",
120-
}),
121-
[configuration],
122-
);
114+
const source = {
115+
html: deviceStreamDocument(configuration, deviceStreamScript),
116+
// Android WebCodecs needs a secure document; streams still use the environment's URLs.
117+
baseUrl: Platform.OS === "android" ? "https://localhost/" : "file:///",
118+
};
123119
const command = (button: keyof DeviceStreamRef) => {
124120
webView.current?.injectJavaScript(
125121
`window.T3DeviceStream?.command(${JSON.stringify(button)}); true;`,

‎apps/mobile/src/reactCompilerCoverage.test.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ const KNOWN_BAILOUTS: Record<string, string> = {
2626
"src/components/ui/Menu.tsx": "ref read during render",
2727
"src/components/ui/OverlayPortal.tsx": "unsupported syntax",
2828
"src/features/connection/ConnectionsNewRouteScreen.tsx": "try without catch",
29-
"src/features/devices/DevicePreviewRouteScreen.tsx": "try without catch",
3029
"src/features/diffs/nativeReviewDiffSurface.ts": "ref read during render",
3130
"src/features/files/AttachmentFileScreen.tsx": "manual memo not preserved",
3231
"src/features/files/FileMarkdownPreview.tsx": "try without catch",

0 commit comments

Comments
 (0)