Skip to content

Commit 98b7191

Browse files
perf(mobile): composer attachments, connections, add project and shared state compile with the React Compiler
The composer editor and context attachment, both video preview modals, the new connection sheet, add project, attachment documents, attachment uploads, media actions, queries and git action progress. try/finally became .finally() on the async body, a ref write moved into a layout effect, and git action progress keeps its clock in state the interval advances instead of reading Date.now() during render, which the compiler would freeze. Manual useMemo/useCallback/memo are gone. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 7a76b00 commit 98b7191

12 files changed

Lines changed: 303 additions & 403 deletions

‎apps/mobile/src/components/ComposerContextAttachment.tsx‎

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as Dialog from "./ui/Dialog";
22
import type { ComposerContextRecord, EnvironmentId } from "@t3tools/contracts";
33
import { Pressable, View } from "react-native";
44
import { Image } from "expo-image";
5-
import { useEffect, useId, useMemo, useState } from "react";
5+
import { useEffect, useId, useState } from "react";
66
import type { DraftComposerAttachment } from "../lib/composerImages";
77
import { composerAttachmentInlineUri, isFileBackedComposerAttachment } from "../lib/composerImages";
88
import { loadLocalAttachmentPreview } from "../lib/localAttachmentPreview";
@@ -20,14 +20,11 @@ export function ComposerContextAttachment(props: {
2020
}) {
2121
const { record, attachment } = props;
2222
const shareSourceIdentifier = useId();
23-
const resource = useMemo(
24-
() => ({
25-
_tag: "attachment" as const,
26-
attachmentId: record.attachmentId,
27-
fileName: record.name,
28-
}),
29-
[record.attachmentId, record.name],
30-
);
23+
const resource = {
24+
_tag: "attachment" as const,
25+
attachmentId: record.attachmentId,
26+
fileName: record.name,
27+
};
3128
const local = attachment?.fileUri
3229
? (attachment as DraftComposerAttachment & { fileUri: string })
3330
: undefined;
@@ -64,14 +61,12 @@ export function ComposerContextAttachment(props: {
6461
if (sharing) return;
6562
setSharing(true);
6663
const controller = new AbortController();
67-
try {
64+
await (async () => {
6865
if (local) {
6966
const preview = await loadLocalAttachmentPreview(local, controller.signal);
70-
try {
71-
await preview?.share(controller.signal, shareSourceIdentifier);
72-
} finally {
73-
preview?.dispose();
74-
}
67+
await preview?.share(controller.signal, shareSourceIdentifier).finally(() => {
68+
preview.dispose();
69+
});
7570
} else {
7671
const url = await refresh();
7772
if (!url) throw new Error("Reconnect to the environment and try again.");
@@ -82,14 +77,16 @@ export function ComposerContextAttachment(props: {
8277
sourceIdentifier: shareSourceIdentifier,
8378
});
8479
}
85-
} catch (cause) {
86-
Dialog.alert(
87-
"Could not open attachment",
88-
cause instanceof Error ? cause.message : "Try again.",
89-
);
90-
} finally {
91-
setSharing(false);
92-
}
80+
})()
81+
.catch((cause: unknown) => {
82+
Dialog.alert(
83+
"Could not open attachment",
84+
cause instanceof Error ? cause.message : "Try again.",
85+
);
86+
})
87+
.finally(() => {
88+
setSharing(false);
89+
});
9390
};
9491
return (
9592
<View className="gap-3">

‎apps/mobile/src/components/ComposerEditor.tsx‎

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { ComposerContextId } from "@t3tools/contracts";
33
import { useAtomValue } from "@effect/atom-react";
44
import { AsyncResult } from "effect/reactivity";
55
import { useNavigation } from "@react-navigation/native";
6-
import { useEffect, useMemo, useRef, useState } from "react";
6+
import { useEffect, useRef, useState } from "react";
77
import type { EnvironmentId } from "@t3tools/contracts";
88
import { encodeComposerContextFragment } from "@t3tools/shared/composerContextClipboard";
99
import { collectComposerContextReferences } from "@t3tools/shared/composerContextReferences";
@@ -54,7 +54,7 @@ export function ComposerEditor({
5454
const preferredEnterBehavior = AsyncResult.isSuccess(preferencesResult)
5555
? preferencesResult.value.composerEnterBehavior
5656
: undefined;
57-
const contextHistory = useMemo(() => createComposerDraftContextHistory(), [draftKey]);
57+
const contextHistory = createComposerDraftContextHistory();
5858
useEffect(() => () => contextHistory.dispose(), [contextHistory]);
5959
const changeText = (text: string) => {
6060
const restored = contextHistory.restore(
@@ -87,7 +87,7 @@ export function ComposerEditor({
8787
importRef.current = controller;
8888
setImporting(true);
8989
setComposerContextImporting(draftKey, true);
90-
try {
90+
return await (async () => {
9191
const retained = getComposerDraftAfterSelection(draftKey, insertion);
9292
const result = await importComposerContextClipboard(
9393
clipboard,
@@ -111,41 +111,38 @@ export function ComposerEditor({
111111
"Some attachments could not be copied",
112112
"Reconnect to the source environment and copy them again. References without their files are marked unavailable.",
113113
);
114-
} catch (error) {
115-
if (!controller.signal.aborted)
116-
Dialog.alert(
117-
"Could not paste context",
118-
error instanceof Error ? error.message : "Try copying again.",
119-
);
120-
} finally {
121-
setComposerContextImporting(draftKey, false);
122-
importRef.current = null;
123-
setImporting(false);
124-
}
114+
})()
115+
.catch((error: unknown) => {
116+
if (!controller.signal.aborted)
117+
Dialog.alert(
118+
"Could not paste context",
119+
error instanceof Error ? error.message : "Try copying again.",
120+
);
121+
})
122+
.finally(() => {
123+
setComposerContextImporting(draftKey, false);
124+
importRef.current = null;
125+
setImporting(false);
126+
});
125127
};
126-
const clipboardFragment = useMemo(
127-
() =>
128-
environmentId && draft.context
129-
? encodeComposerContextFragment({
130-
version: 1,
131-
source: { environmentId },
132-
records: draft.context.records.map((record) => {
133-
if (!("attachmentId" in record)) return record;
134-
const attachment = draft.attachments.find(
135-
(entry) => entry.id === record.attachmentId,
136-
);
137-
return {
138-
...record,
139-
attachmentId:
140-
attachment?.uploadEnvironmentId === environmentId
141-
? (attachment.uploadedAttachmentId ?? record.attachmentId)
142-
: record.attachmentId,
143-
};
144-
}),
145-
})
146-
: "",
147-
[environmentId, draft.context, draft.attachments],
148-
);
128+
const clipboardFragment =
129+
environmentId && draft.context
130+
? encodeComposerContextFragment({
131+
version: 1,
132+
source: { environmentId },
133+
records: draft.context.records.map((record) => {
134+
if (!("attachmentId" in record)) return record;
135+
const attachment = draft.attachments.find((entry) => entry.id === record.attachmentId);
136+
return {
137+
...record,
138+
attachmentId:
139+
attachment?.uploadEnvironmentId === environmentId
140+
? (attachment.uploadedAttachmentId ?? record.attachmentId)
141+
: record.attachmentId,
142+
};
143+
}),
144+
})
145+
: "";
149146
const navigation = useNavigation();
150147
const selectedReference = selected
151148
? collectComposerContextReferences(selected.source)[0]

‎apps/mobile/src/components/VideoPreviewModal.ios.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ function NativeVideoPreview(props: {
7676
? await loadLocalAttachmentPreview(localAttachment, controller.signal)
7777
: null;
7878
if (localAttachment !== null && !file) return;
79-
try {
79+
return await (async () => {
8080
if (controller.signal.aborted) return;
8181
ready = true;
8282
await NativeControls.presentVideo(
@@ -86,10 +86,10 @@ function NativeVideoPreview(props: {
8686
identifier,
8787
);
8888
if (!controller.signal.aborted) onRequestClose();
89-
} finally {
89+
})().finally(() => {
9090
// Native completion follows dismissal, so local playback keeps its file lease.
9191
file?.dispose();
92-
}
92+
});
9393
})().catch((error: unknown) => {
9494
if (controller.signal.aborted) return;
9595
// AVKit gives no retry, so re-mint now; the cached URL may simply have expired.

‎apps/mobile/src/components/VideoPreviewModal.tsx‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useIsFocused } from "@react-navigation/native";
22
import { videoMimeType } from "@t3tools/shared/video";
3-
import { useEffect, useRef, useState } from "react";
3+
import { useEffect, useLayoutEffect, useRef, useState } from "react";
44
import { Keyboard, Modal, Pressable, View } from "react-native";
55
import { useSafeAreaInsets } from "react-native-safe-area-context";
66

@@ -61,7 +61,9 @@ function useLocalPlayback(source: LocalVideoPreviewSource): PlaybackState {
6161
// Only a different file needs a new lease; a metadata update on the same
6262
// draft must not dispose the file Android is still playing.
6363
const attachmentRef = useRef(attachment);
64-
attachmentRef.current = attachment;
64+
useLayoutEffect(() => {
65+
attachmentRef.current = attachment;
66+
});
6567
const { id: attachmentId, fileUri } = attachment;
6668
useEffect(() => {
6769
setUri(null);

‎apps/mobile/src/features/connection/ConnectionsNewRouteScreen.tsx‎

Lines changed: 53 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
} from "@react-navigation/native";
1313
import type { EnvironmentId } from "@t3tools/contracts";
1414
import { AsyncResult } from "effect/reactivity";
15-
import { useCallback, useEffect, useRef, useState } from "react";
15+
import { useEffect, useRef, useState } from "react";
1616
import { Linking, Pressable, StyleSheet, View } from "react-native";
1717
import Svg, { Defs, RadialGradient, Rect, Stop } from "react-native-svg";
1818
import { useSafeAreaInsets } from "react-native-safe-area-context";
@@ -95,19 +95,19 @@ export function ConnectionsNewRouteScreen({
9595
}
9696
}, [pairingConnectionError]);
9797

98-
const handleHostChange = useCallback((value: string) => {
98+
const handleHostChange = (value: string) => {
9999
setHostInput(value);
100100
setPendingConnectionError(null);
101-
}, []);
101+
};
102102

103-
const handleCodeChange = useCallback((value: string) => {
103+
const handleCodeChange = (value: string) => {
104104
setCodeInput(value);
105105
setPendingConnectionError(null);
106-
}, []);
106+
};
107107

108108
useEffect(() => () => setPendingConnectionError(null), []);
109109

110-
const handleScanPress = useCallback(async () => {
110+
const handleScanPress = async () => {
111111
const permission = await requestCameraPermission();
112112
if (permission.granted) {
113113
setScanComplete(false);
@@ -122,68 +122,62 @@ export function ConnectionsNewRouteScreen({
122122
{ text: "Open Settings", onPress: () => void Linking.openSettings() },
123123
],
124124
);
125-
}, [requestCameraPermission]);
125+
};
126126

127-
const handleQrScan = useCallback(
128-
({ data }: { readonly data: string }) => {
129-
if (scannerLocked) {
130-
return;
131-
}
127+
const handleQrScan = ({ data }: { readonly data: string }) => {
128+
if (scannerLocked) {
129+
return;
130+
}
132131

133-
setScannerLocked(true);
132+
setScannerLocked(true);
134133

135-
try {
136-
const pairingUrl = extractPairingUrlFromQrPayload(data);
137-
const { host, code } = parsePairingUrl(pairingUrl);
138-
setHostInput(host);
139-
setCodeInput(code);
140-
onChangeConnectionPairingUrl(pairingUrl);
141-
setScanComplete(true);
134+
try {
135+
const pairingUrl = extractPairingUrlFromQrPayload(data);
136+
const { host, code } = parsePairingUrl(pairingUrl);
137+
setHostInput(host);
138+
setCodeInput(code);
139+
onChangeConnectionPairingUrl(pairingUrl);
140+
setScanComplete(true);
141+
setScannerLocked(false);
142+
} catch (error) {
143+
void Haptics.notificationAsync(Haptics.NotificationFeedbackType.Error);
144+
Dialog.alert(
145+
"Invalid QR code",
146+
error instanceof Error ? error.message : "Scanned QR code was not recognized.",
147+
);
148+
setTimeout(() => {
142149
setScannerLocked(false);
143-
} catch (error) {
144-
void Haptics.notificationAsync(Haptics.NotificationFeedbackType.Error);
145-
Dialog.alert(
146-
"Invalid QR code",
147-
error instanceof Error ? error.message : "Scanned QR code was not recognized.",
148-
);
149-
setTimeout(() => {
150-
setScannerLocked(false);
151-
}, 600);
152-
}
153-
},
154-
[onChangeConnectionPairingUrl, scannerLocked],
155-
);
150+
}, 600);
151+
}
152+
};
156153

157-
const connectAndClose = useCallback(
158-
async (pairingUrl: string) => {
159-
setIsSubmitting(true);
160-
onChangeConnectionPairingUrl(pairingUrl);
161-
try {
162-
const result = await onConnectPress(pairingUrl, params.routeFor);
163-
void Haptics.notificationAsync(
164-
AsyncResult.isSuccess(result)
165-
? Haptics.NotificationFeedbackType.Success
166-
: Haptics.NotificationFeedbackType.Error,
167-
);
168-
if (AsyncResult.isSuccess(result)) {
169-
// Return to whatever opened the sheet. Replacing it with Home would
170-
// nest Home inside any sheet still below it.
171-
if (!navigation.canGoBack()) {
172-
navigation.dispatch(StackActions.replace("Home"));
173-
} else {
174-
navigation.goBack();
175-
}
154+
const connectAndClose = async (pairingUrl: string) => {
155+
setIsSubmitting(true);
156+
onChangeConnectionPairingUrl(pairingUrl);
157+
await (async () => {
158+
const result = await onConnectPress(pairingUrl, params.routeFor);
159+
void Haptics.notificationAsync(
160+
AsyncResult.isSuccess(result)
161+
? Haptics.NotificationFeedbackType.Success
162+
: Haptics.NotificationFeedbackType.Error,
163+
);
164+
if (AsyncResult.isSuccess(result)) {
165+
// Return to whatever opened the sheet. Replacing it with Home would
166+
// nest Home inside any sheet still below it.
167+
if (!navigation.canGoBack()) {
168+
navigation.dispatch(StackActions.replace("Home"));
169+
} else {
170+
navigation.goBack();
176171
}
177-
} finally {
178-
setIsSubmitting(false);
179172
}
180-
},
181-
[navigation, onChangeConnectionPairingUrl, onConnectPress, params.routeFor],
182-
);
173+
})().finally(() => {
174+
setIsSubmitting(false);
175+
});
176+
};
183177

184-
const handleSubmit = useCallback(async () => {
178+
const handleSubmit = async () => {
185179
await connectAndClose(buildPairingUrl(hostInput, codeInput));
186-
}, [codeInput, connectAndClose, hostInput]);
180+
};
187181

188182
useEffect(() => {
189183
if (!shouldAutoConnect || attemptedAutoConnectRef.current === routePairingUrl) {

0 commit comments

Comments
 (0)