Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion apps/web/src/components/ChatView.tsx
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium

setOptimisticUserMessages((existing) =>

When onSubmitPlanFollowUp catches an error at line 2951, it removes the optimistic message but never revokes the blob URLs from optimisticAttachments, leaking memory. The main onSend function properly calls revokeUserMessagePreviewUrls on its error path, but onSubmitPlanFollowUp does not. Add the same cleanup call before filtering the optimistic message to prevent the leak.

🤖 Copy this AI Prompt to have your agent fix this:
In file apps/web/src/components/ChatView.tsx around line 2951:

When `onSubmitPlanFollowUp` catches an error at line 2951, it removes the optimistic message but never revokes the blob URLs from `optimisticAttachments`, leaking memory. The main `onSend` function properly calls `revokeUserMessagePreviewUrls` on its error path, but `onSubmitPlanFollowUp` does not. Add the same cleanup call before filtering the optimistic message to prevent the leak.

Evidence trail:
apps/web/src/components/ChatView.tsx lines 2807-2962 (onSubmitPlanFollowUp function)
apps/web/src/components/ChatView.tsx lines 2866-2872 (optimisticAttachments creation with previewUrl)
apps/web/src/components/ChatView.tsx line 2893 (attachments added to optimistic message)
apps/web/src/components/ChatView.tsx lines 2951-2959 (catch block filters message without revoking URLs)
apps/web/src/components/ChatView.tsx lines 2595-2608 (onSend error handler properly calls revokeUserMessagePreviewUrls at line 2605)
apps/web/src/components/ChatView.logic.ts lines 105-122 (revokeUserMessagePreviewUrls and revokeBlobPreviewUrl functions)

Original file line number Diff line number Diff line change
Expand Up @@ -2368,12 +2368,14 @@ export default function ChatView(props: ChatViewProps) {
draftText: trimmed,
planMarkdown: activeProposedPlan.planMarkdown,
});
const planFollowUpImages = [...composerImages];
promptRef.current = "";
clearComposerDraftContent(composerDraftTarget);
composerRef.current?.resetCursorState();
await onSubmitPlanFollowUp({
text: followUp.text,
interactionMode: followUp.interactionMode,
images: planFollowUpImages,
});
return;
}
Expand Down Expand Up @@ -2806,9 +2808,11 @@ export default function ChatView(props: ChatViewProps) {
async ({
text,
interactionMode: nextInteractionMode,
images = [],
}: {
text: string;
interactionMode: "default" | "plan";
images?: ReadonlyArray<ComposerImageAttachment>;
}) => {
const api = readEnvironmentApi(environmentId);
if (
Expand Down Expand Up @@ -2850,6 +2854,27 @@ export default function ChatView(props: ChatViewProps) {
text: trimmed,
});

const turnAttachmentsPromise =
images.length > 0
? Promise.all(
images.map(async (image) => ({
type: "image" as const,
name: image.name,
mimeType: image.mimeType,
sizeBytes: image.sizeBytes,
dataUrl: await readFileAsDataUrl(image.file),
})),
)
: Promise.resolve([]);
const optimisticAttachments = images.map((image) => ({
type: "image" as const,
id: image.id,
name: image.name,
mimeType: image.mimeType,
sizeBytes: image.sizeBytes,
previewUrl: image.previewUrl,
}));

sendInFlightRef.current = true;
beginLocalDispatch({ preparingWorktree: false });
setThreadError(threadIdForSend, null);
Expand All @@ -2866,12 +2891,15 @@ export default function ChatView(props: ChatViewProps) {
id: messageIdForSend,
role: "user",
text: outgoingMessageText,
...(optimisticAttachments.length > 0 ? { attachments: optimisticAttachments } : {}),
createdAt: messageCreatedAt,
streaming: false,
},
]);

try {
const turnAttachments = await turnAttachmentsPromise;

await persistThreadSettingsForNextTurn({
threadId: threadIdForSend,
createdAt: messageCreatedAt,
Expand All @@ -2895,7 +2923,7 @@ export default function ChatView(props: ChatViewProps) {
messageId: messageIdForSend,
role: "user",
text: outgoingMessageText,
attachments: [],
attachments: turnAttachments,
},
modelSelection: ctxSelectedModelSelection,
titleSeed: activeThread.title,
Expand Down
Loading