Skip to content

Commit f121ad7

Browse files
fix(web): keep device workspace compatible with React Compiler
1 parent c17d4c2 commit f121ad7

3 files changed

Lines changed: 47 additions & 42 deletions

File tree

‎apps/web/src/components/device/DevicePhoneViewport.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { createPhoneInteraction } from "@t3tools/client-runtime/device/phone-int
44
import type { DeviceScreenSize, DeviceStreamClient } from "@t3tools/client-runtime/device/stream";
55
import { bindPhoneTrackpad } from "./phoneTrackpad";
66

7+
const loadPhoneViewer = () => import("@t3tools/client-runtime/device/phone-viewer");
8+
79
/** Web shell for the framework-independent viewer. The decoded screen and input connection remain owned by DeviceStreamView. */
810
export function DevicePhoneViewport(props: {
911
readonly contentOffset: number;
@@ -47,7 +49,7 @@ export function DevicePhoneViewport(props: {
4749
};
4850
onInputCancel(blur);
4951
window.addEventListener("blur", blur);
50-
void import("@t3tools/client-runtime/device/phone-viewer")
52+
void loadPhoneViewer()
5153
.then(({ createPhoneViewer }) => {
5254
if (disposed) return;
5355
const viewer = createPhoneViewer({ canvas, source: decoded, onUnavailable });

‎apps/web/src/components/device/DeviceWorkspace.tsx‎

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -38,41 +38,43 @@ export function DeviceWorkspace(props: {
3838
downloadRef.current = null;
3939
};
4040
}, [access, props.visible]);
41-
const saveScreenshot = async () => {
41+
const saveScreenshot = () => {
4242
if (!access || captureRef.current || !props.visible) return;
4343
const controller = new AbortController();
4444
captureRef.current = controller;
4545
setScreenshotPending(true);
4646
setScreenshotError(null);
47-
try {
48-
const image = await captureDeviceScreenshot(
49-
{ access, platform: props.device.platform, deviceId: props.device.id },
50-
controller.signal,
51-
);
52-
if (controller.signal.aborted) return;
53-
if (downloadRef.current) URL.revokeObjectURL(downloadRef.current);
54-
const url = URL.createObjectURL(image);
55-
downloadRef.current = url;
56-
const link = document.createElement("a");
57-
link.href = url;
58-
link.download = `${props.device.name.replace(/[^a-z0-9-]/gi, "-")}-${Date.now()}.png`;
59-
document.body.append(link);
60-
link.click();
61-
link.remove();
62-
} catch (cause) {
63-
if (!controller.signal.aborted) {
64-
if (cause instanceof DeviceScreenshotError && cause.status === 401)
65-
refreshDeviceHubAccess(props.environmentId);
66-
setScreenshotError(
67-
cause instanceof Error ? cause.message : "Screenshot capture failed. Try again.",
68-
);
69-
}
70-
} finally {
71-
if (captureRef.current === controller) {
72-
captureRef.current = null;
73-
setScreenshotPending(false);
74-
}
75-
}
47+
return captureDeviceScreenshot(
48+
{ access, platform: props.device.platform, deviceId: props.device.id },
49+
controller.signal,
50+
)
51+
.then((image) => {
52+
if (controller.signal.aborted) return;
53+
if (downloadRef.current) URL.revokeObjectURL(downloadRef.current);
54+
const url = URL.createObjectURL(image);
55+
downloadRef.current = url;
56+
const link = document.createElement("a");
57+
link.href = url;
58+
link.download = `${props.device.name.replace(/[^a-z0-9-]/gi, "-")}-${Date.now()}.png`;
59+
document.body.append(link);
60+
link.click();
61+
link.remove();
62+
})
63+
.catch((cause: unknown) => {
64+
if (!controller.signal.aborted) {
65+
if (cause instanceof DeviceScreenshotError && cause.status === 401)
66+
refreshDeviceHubAccess(props.environmentId);
67+
setScreenshotError(
68+
cause instanceof Error ? cause.message : "Screenshot capture failed. Try again.",
69+
);
70+
}
71+
})
72+
.finally(() => {
73+
if (captureRef.current === controller) {
74+
captureRef.current = null;
75+
setScreenshotPending(false);
76+
}
77+
});
7678
};
7779
return (
7880
<>

‎apps/web/src/components/device/useDeviceControls.ts‎

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,19 @@ export function useDeviceControls(options: {
6969
const revision = ++generation.current;
7070
setPending(true);
7171
setError(null);
72-
try {
73-
const result = await runAction({
74-
environmentId,
75-
input: { ...target, ...body } as DeviceActionInput,
72+
return runAction({
73+
environmentId,
74+
input: { ...target, ...body } as DeviceActionInput,
75+
})
76+
.then((result) => {
77+
if (generation.current !== revision) return;
78+
if (result._tag === "Success") setDetail(result.value);
79+
else setError(formatEnvironmentQueryError(result.cause));
80+
})
81+
.finally(() => {
82+
busy.current = false;
83+
setPending(false);
7684
});
77-
if (generation.current !== revision) return;
78-
if (result._tag === "Success") setDetail(result.value);
79-
else setError(formatEnvironmentQueryError(result.cause));
80-
} finally {
81-
busy.current = false;
82-
setPending(false);
83-
}
8485
};
8586

8687
return {

0 commit comments

Comments
 (0)