Skip to content

Commit afe1617

Browse files
StiensWoutclaude
andcommitted
fix(mobile): release review-comment image files on removal and dismissal
The review-comment sheet holds picked images in local state until submit copies them into the thread draft. With file-backed images, removing an attachment or dismissing the sheet dropped the state while the copied file stayed in the attachment directory. Removal and unmount now route through the reference-checked cleanup, so submitted files stay owned by the draft and abandoned ones are deleted. Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent 5a157c0 commit afe1617

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

‎apps/mobile/src/features/review/ReviewCommentComposerSheet.tsx‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useNavigation, type StaticScreenProps } from "@react-navigation/native";
22
import { TextInputWrapper } from "expo-paste-input";
33
import type { EnvironmentId, ThreadId } from "@t3tools/contracts";
4-
import { useCallback, useEffect, useMemo, useState } from "react";
4+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
55
import { Platform, Pressable, ScrollView, View, useWindowDimensions } from "react-native";
66
import { KeyboardAvoidingView, KeyboardStickyView } from "react-native-keyboard-controller";
77
import { useSafeAreaInsets } from "react-native-safe-area-context";
@@ -15,6 +15,7 @@ import { cn } from "../../lib/cn";
1515
import type { DraftComposerImageAttachment } from "../../lib/composerImages";
1616
import { convertPastedImagesToAttachments, pickComposerImages } from "../../lib/composerImages";
1717
import { useNativePaste } from "../../lib/useNativePaste";
18+
import { scheduleUnusedComposerAttachmentCleanup } from "../../state/use-composer-drafts";
1819
import { setPendingConnectionError } from "../../state/use-remote-environment-registry";
1920
import { appendReviewCommentToDraft } from "../../state/use-thread-composer-state";
2021
import {
@@ -53,6 +54,21 @@ export function ReviewCommentComposerSheet(props: ReviewCommentComposerSheetProp
5354
Record<string, ReadonlyArray<ReviewHighlightedToken>>
5455
>({});
5556
const [attachments, setAttachments] = useState<ReadonlyArray<DraftComposerImageAttachment>>([]);
57+
const attachmentsRef = useRef(attachments);
58+
attachmentsRef.current = attachments;
59+
// Attachments live in local state until submit copies them into the thread
60+
// draft, but their image bytes already live in the app-owned attachment
61+
// directory. Whatever is still here when the sheet unmounts was neither
62+
// submitted nor removed; release those copies so dismissal does not leak
63+
// storage. Cleanup is reference-checked, so submitted files stay.
64+
useEffect(
65+
() => () => {
66+
if (attachmentsRef.current.length > 0) {
67+
scheduleUnusedComposerAttachmentCleanup(attachmentsRef.current);
68+
}
69+
},
70+
[],
71+
);
5672
const [previewFile, setPreviewFile] = useState<FilePreviewSource | null>(null);
5773

5874
const selectedLines = useMemo(
@@ -275,9 +291,13 @@ export function ReviewCommentComposerSheet(props: ReviewCommentComposerSheetProp
275291
onPressPreview={setPreviewFile}
276292
removeButtonPlacement="gutter"
277293
onRemove={(imageId) => {
294+
const removed = attachments.find((image) => image.id === imageId);
278295
setAttachments((current) =>
279296
current.filter((image) => image.id !== imageId),
280297
);
298+
if (removed) {
299+
scheduleUnusedComposerAttachmentCleanup([removed]);
300+
}
281301
}}
282302
/>
283303
</View>

0 commit comments

Comments
 (0)