Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

address review: move previewUrl cleanup to useOpenClawAttachments, add default params to hooks

[._.]/ Adam Eivye6b134386966
diff --git a/client/src/hooks/useOpenClawAttachments.js b/client/src/hooks/useOpenClawAttachments.js
index cf538536c4..c12575984b 100644
--- a/client/src/hooks/useOpenClawAttachments.js
+++ b/client/src/hooks/useOpenClawAttachments.js
@@ -1,4 +1,4 @@
-import { useCallback, useRef, useState } from 'react';
+import { useCallback, useEffect, useRef, useState } from 'react';
import { readFileAsBase64 } from '../utils/fileUpload';
const MAX_ATTACHMENTS = 8;
@@ -55,11 +55,24 @@ async function filesToAttachments(files) {
}
}
-export function useOpenClawAttachments({ sending, onError }) {
+export function useOpenClawAttachments({ sending, onError = () => {} } = {}) {
const [attachments, setAttachments] = useState([]);
const [isDragActive, setIsDragActive] = useState(false);
const dragCounterRef = useRef(0);
const fileInputRef = useRef(null);
+ const attachmentsRef = useRef(attachments);
+
+ useEffect(() => {
+ attachmentsRef.current = attachments;
+ }, [attachments]);
+
+ // Revoke any remaining object URLs when the hook unmounts — owned here since
+ // previewUrls are created by this hook.
+ useEffect(() => {
+ return () => {
+ attachmentsRef.current.forEach(a => { if (a.previewUrl) URL.revokeObjectURL(a.previewUrl); });
+ };
+ }, []);
const appendFiles = useCallback(async (files) => {
if (!files || files.length === 0) return;
diff --git a/client/src/hooks/useOpenClawStream.js b/client/src/hooks/useOpenClawStream.js
index dc3528f266..3878f56294 100644
--- a/client/src/hooks/useOpenClawStream.js
+++ b/client/src/hooks/useOpenClawStream.js
@@ -18,25 +18,13 @@ function normalizeContent(content) {
// the messagesError state and passes setMessagesError as onError.
// onSendComplete is called after a successful send with { sessionId } so the component
// can update session metadata (e.g. lastMessageAt) without the hook owning sessions state.
-export function useOpenClawStream({ selectedSessionId, attachments, setAttachments, composer, setComposer, context, apps, sending, setSending, onError, onSendComplete }) {
+export function useOpenClawStream({ selectedSessionId, attachments, setAttachments, composer, setComposer, context, apps, sending, setSending, onError = () => {}, onSendComplete = () => {} } = {}) {
const [messages, setMessages] = useState([]);
const [activityLabel, setActivityLabel] = useState('');
const [messagesLoading, setMessagesLoading] = useState(false);
const abortControllerRef = useRef(null);
const scrollAnimationFrameRef = useRef(null);
const messagesEndRef = useRef(null);
- const attachmentsRef = useRef(attachments);
-
- useEffect(() => {
- attachmentsRef.current = attachments;
- }, [attachments]);
-
- // Revoke any remaining object URLs when the hook unmounts
- useEffect(() => {
- return () => {
- attachmentsRef.current.forEach(a => { if (a.previewUrl) URL.revokeObjectURL(a.previewUrl); });
- };
- }, []);
useEffect(() => {
if (!messagesEndRef.current) return;