diff --git a/src/apps/chat/components/message/fragments-attachment-doc/livefile-sync/useLiveFileSync.tsx b/src/apps/chat/components/message/fragments-attachment-doc/livefile-sync/useLiveFileSync.tsx
index dfa6462d2..1a4e5240e 100644
--- a/src/apps/chat/components/message/fragments-attachment-doc/livefile-sync/useLiveFileSync.tsx
+++ b/src/apps/chat/components/message/fragments-attachment-doc/livefile-sync/useLiveFileSync.tsx
@@ -48,8 +48,8 @@ export function useLiveFileSync(
workspaceId: DWorkspaceId | null,
isMobile: boolean,
bufferText: string,
- onReplaceLiveFileId: (liveFileId: LiveFileId) => void,
- onSetBufferText: (text: string) => void,
+ onReplaceLiveFileId?: (liveFileId: LiveFileId) => void,
+ onSetBufferText?: (text: string) => void,
) {
// state
@@ -140,7 +140,7 @@ export function useLiveFileSync(
console.warn('[DEV] No workspaceId to pair the file with.');
else
workspaceActions().liveFileAssign(workspaceId, liveFileId);
- onReplaceLiveFileId(liveFileId);
+ onReplaceLiveFileId?.(liveFileId);
// Immediately load the preview on this ID
await _handleReloadFileContent(liveFileId);
} catch (error: any) {
@@ -166,7 +166,7 @@ export function useLiveFileSync(
if (fileContent === undefined)
setStatus({ message: 'No file content loaded. Please preview changes first.', mtype: 'info' });
else
- onSetBufferText(fileContent);
+ onSetBufferText?.(fileContent);
}, [fileContent, onSetBufferText]);
const handleSaveToDisk = React.useCallback(async (event: React.MouseEvent) => {
@@ -196,7 +196,7 @@ export function useLiveFileSync(
// Memoed components code
- const liveFileControlButton = React.useMemo(() => !isLiveFileSupported() ? null : (
+ const liveFileControlButton = React.useMemo(() => (!isLiveFileSupported() || !onReplaceLiveFileId) ? null : (
- ), [fileHasContent, handlePairNewFSFHandle, handlePairNewFileWithPicker, _handleReloadFileContent, isPairingValid, isSavingFile]);
+ ), [_handleReloadFileContent, fileHasContent, handlePairNewFSFHandle, handlePairNewFileWithPicker, isPairingValid, isSavingFile, onReplaceLiveFileId]);
const liveFileActions = React.useMemo(() => {
if (!isLiveFileSupported() || (!status && !fileHasContent))
@@ -244,7 +244,7 @@ export function useLiveFileSync(
{/* Load from file */}
- {fileIsDifferent && !isError && (
+ {fileIsDifferent && !isError && !!onSetBufferText && (
);
- }, [fileHasContent, fileIsDifferent, handleStopLiveFile, handleLoadFromDisk, handlePairNewFileWithPicker, handleSaveToDisk, _handleReloadFileContent, isMobile, isPairingValid, isSavingFile, status]);
+ }, [_handleReloadFileContent, fileHasContent, fileIsDifferent, handleLoadFromDisk, handlePairNewFileWithPicker, handleSaveToDisk, handleStopLiveFile, isMobile, isPairingValid, isSavingFile, onReplaceLiveFileId, onSetBufferText, status]);
// Auto-click on 'refresh' on window focus