Skip to content

Commit 402d6e4

Browse files
perf(mobile): files, review and remaining settings screens compile with the React Compiler
Covers the file tree, file viewer, markdown and source previews, attachment viewer, review sheet and its highlighting, plus the Auth, Scheduled tasks and drag-handle settings pieces. Refresh handlers use .finally(), the highlight request is a promise chain, refs read during render became state, effects or effect events, and the token offset counter left render. Their manual useMemo/useCallback/memo are gone. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 9ccf6d9 commit 402d6e4

14 files changed

Lines changed: 596 additions & 790 deletions

‎apps/mobile/src/features/files/AttachmentFileScreen.tsx‎

Lines changed: 90 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { useNavigation, type StaticScreenProps } from "@react-navigation/native"
66
import type { MenuAction } from "@react-native-menu/menu";
77
import { EnvironmentId } from "@t3tools/contracts";
88
import { formatAttachmentSize } from "@t3tools/client-runtime/state/attachments";
9-
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
9+
import { useEffect, useRef, useState } from "react";
1010
import { Platform, ScrollView, View } from "react-native";
1111

1212
import {
@@ -196,9 +196,9 @@ export function AttachmentFileScreen(props: AttachmentFileScreenProps) {
196196
);
197197
const [nativeError, setNativeError] = useState<string | null>(null);
198198
const pendingNativeError = useRef<string | null>(null);
199-
const handleBack = useCallback(() => {
199+
const handleBack = () => {
200200
if (navigation.canGoBack()) navigation.goBack();
201-
}, [navigation]);
201+
};
202202
const { uri, resource } = document;
203203
useEffect(() => {
204204
if (nativeViewer !== "pending" || !uri) return;
@@ -208,17 +208,17 @@ export function AttachmentFileScreen(props: AttachmentFileScreenProps) {
208208
}, [nativeViewer, uri]);
209209
// The viewer mints its own fresh URL from the resource, so a link that expired while this
210210
// screen sat in the background is never handed to Quick Look or ACTION_VIEW.
211-
const nativeSource = useMemo<FilePreviewSource | null>(() => {
211+
const nativeSource = ((): FilePreviewSource | null => {
212212
const kind = nativeKind ?? "document";
213213
const base = { kind, name: params.name, mimeType: params.mimeType };
214214
if (localAttachment) return { ...base, attachment: localAttachment };
215215
if (environmentId) return { ...base, environmentId, resource };
216216
return uri ? { ...base, uri } : null;
217-
}, [environmentId, localAttachment, nativeKind, params.mimeType, params.name, resource, uri]);
218-
const handleNativeOpenError = useCallback((error: unknown) => {
217+
})();
218+
const handleNativeOpenError = (error: unknown) => {
219219
pendingNativeError.current = nativeViewerErrorMessage(error);
220-
}, []);
221-
const handleNativeClose = useCallback(() => {
220+
};
221+
const handleNativeClose = () => {
222222
setNativeOpen(false);
223223
const message = pendingNativeError.current;
224224
pendingNativeError.current = null;
@@ -233,117 +233,94 @@ export function AttachmentFileScreen(props: AttachmentFileScreenProps) {
233233
return;
234234
}
235235
handleBack();
236-
}, [handleBack, nativeViewer]);
237-
const removeFromDraft = useCallback(() => {
236+
};
237+
const removeFromDraft = () => {
238238
if (!draftKey) return;
239239
removeComposerDraftAttachment(draftKey, params.attachmentId);
240240
handleBack();
241-
}, [draftKey, handleBack, params.attachmentId]);
241+
};
242242

243243
const { content, renderedMode, activeMode, setRendered, share, sharing } = document;
244-
const menuActions = useMemo(
245-
() =>
246-
[
247-
renderedMode
248-
? ({
249-
id: "preview",
250-
title: renderedMode === "table" ? "Table" : "Preview",
251-
icon: renderedMode === "table" ? "tablecells" : "eye",
252-
inline: true,
253-
onPress: () => setRendered(true),
254-
} as const)
255-
: null,
256-
renderedMode
257-
? ({
258-
id: "source",
259-
title: "Source",
260-
icon: "doc.text",
261-
inline: true,
262-
onPress: () => setRendered(false),
263-
} as const)
264-
: null,
265-
content && activeMode === "source"
266-
? ({
267-
id: "word-wrap",
268-
title: appearance.codeWordBreak ? "Disable word wrap" : "Enable word wrap",
269-
icon: "text.alignleft",
270-
inline: false,
271-
onPress: () => setCodeWordBreak(!appearance.codeWordBreak),
272-
} as const)
273-
: null,
274-
content
275-
? ({
276-
id: "copy",
277-
title: content.truncated ? "Copy preview" : "Copy contents",
278-
icon: "doc.on.doc",
279-
inline: false,
280-
onPress: () => copyTextWithHaptic(content.text),
281-
} as const)
282-
: null,
283-
uri
284-
? ({
285-
id: "share",
286-
title: sharing ? "Opening share sheet…" : "Save or share",
287-
icon: "square.and.arrow.up",
288-
inline: false,
289-
onPress: () => void share(),
290-
} as const)
291-
: null,
292-
uri
293-
? ({
294-
id: "open-viewer",
295-
title: "Open in file viewer",
296-
icon: "arrow.up.left.and.arrow.down.right",
297-
inline: false,
298-
onPress: () => {
299-
setNativeViewer((current) => (current === null ? null : "open"));
300-
setNativeOpen(true);
301-
},
302-
} as const)
303-
: null,
304-
draftKey
305-
? ({
306-
id: "remove",
307-
title: "Remove from draft",
308-
icon: "trash",
309-
inline: false,
310-
destructive: true,
311-
onPress: removeFromDraft,
312-
} as const)
313-
: null,
314-
].filter((action) => action !== null),
315-
[
316-
appearance.codeWordBreak,
317-
setCodeWordBreak,
318-
content,
319-
draftKey,
320-
removeFromDraft,
321-
activeMode,
322-
renderedMode,
323-
setRendered,
324-
share,
325-
sharing,
326-
uri,
327-
],
328-
);
244+
const menuActions = [
245+
renderedMode
246+
? ({
247+
id: "preview",
248+
title: renderedMode === "table" ? "Table" : "Preview",
249+
icon: renderedMode === "table" ? "tablecells" : "eye",
250+
inline: true,
251+
onPress: () => setRendered(true),
252+
} as const)
253+
: null,
254+
renderedMode
255+
? ({
256+
id: "source",
257+
title: "Source",
258+
icon: "doc.text",
259+
inline: true,
260+
onPress: () => setRendered(false),
261+
} as const)
262+
: null,
263+
content && activeMode === "source"
264+
? ({
265+
id: "word-wrap",
266+
title: appearance.codeWordBreak ? "Disable word wrap" : "Enable word wrap",
267+
icon: "text.alignleft",
268+
inline: false,
269+
onPress: () => setCodeWordBreak(!appearance.codeWordBreak),
270+
} as const)
271+
: null,
272+
content
273+
? ({
274+
id: "copy",
275+
title: content.truncated ? "Copy preview" : "Copy contents",
276+
icon: "doc.on.doc",
277+
inline: false,
278+
onPress: () => copyTextWithHaptic(content.text),
279+
} as const)
280+
: null,
281+
uri
282+
? ({
283+
id: "share",
284+
title: sharing ? "Opening share sheet…" : "Save or share",
285+
icon: "square.and.arrow.up",
286+
inline: false,
287+
onPress: () => void share(),
288+
} as const)
289+
: null,
290+
uri
291+
? ({
292+
id: "open-viewer",
293+
title: "Open in file viewer",
294+
icon: "arrow.up.left.and.arrow.down.right",
295+
inline: false,
296+
onPress: () => {
297+
setNativeViewer((current) => (current === null ? null : "open"));
298+
setNativeOpen(true);
299+
},
300+
} as const)
301+
: null,
302+
draftKey
303+
? ({
304+
id: "remove",
305+
title: "Remove from draft",
306+
icon: "trash",
307+
inline: false,
308+
destructive: true,
309+
onPress: removeFromDraft,
310+
} as const)
311+
: null,
312+
].filter((action) => action !== null);
329313
const selectedAction = activeMode === "source" ? "source" : "preview";
330-
const androidMenuActions = useMemo<MenuAction[]>(
331-
() =>
332-
menuActions.map((action) => ({
333-
id: action.id,
334-
title: action.title,
335-
image: action.icon,
336-
state: action.inline ? (action.id === selectedAction ? "on" : "off") : undefined,
337-
...("destructive" in action ? { attributes: { destructive: true } } : {}),
338-
})),
339-
[selectedAction, menuActions],
340-
);
341-
const handleAndroidMenuAction = useCallback(
342-
(event: { nativeEvent: { event: string } }) => {
343-
menuActions.find(({ id }) => id === event.nativeEvent.event)?.onPress();
344-
},
345-
[menuActions],
346-
);
314+
const androidMenuActions = menuActions.map((action) => ({
315+
id: action.id,
316+
title: action.title,
317+
image: action.icon,
318+
state: action.inline ? (action.id === selectedAction ? "on" : "off") : undefined,
319+
...("destructive" in action ? { attributes: { destructive: true } } : {}),
320+
})) satisfies MenuAction[];
321+
const handleAndroidMenuAction = (event: { nativeEvent: { event: string } }) => {
322+
menuActions.find(({ id }) => id === event.nativeEvent.event)?.onPress();
323+
};
347324
const subtitle = `${draftKey ? "Draft attachment" : "Attachment"}${sizeBytes > 0 ? ` · ${formatAttachmentSize(sizeBytes)}` : ""}`;
348325

349326
return (

0 commit comments

Comments
 (0)