Skip to content

Commit fb7d024

Browse files
committed
fix: artifact store contamination, FileReader onerror, enhancer bugs, Artifact deps
- Add resetArtifacts() to WorkbenchStore to clear stale artifacts on chat switch - Call resetArtifacts() in Chat.client.tsx cleanup useEffect - Add onerror handlers to both FileReader instances in BaseChat.tsx - Add reader.cancel() on stream error in usePromptEnhancer.ts - Guard setTimeout with if(!_error) to prevent overwriting restored input - Fix Artifact.tsx useMemo deps to include artifact?.runner - Add early return in useChatHistory.ts restoreSnapshot on write failure
1 parent 8c34b1e commit fb7d024

6 files changed

Lines changed: 26 additions & 4 deletions

File tree

app/components/chat/Artifact.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export const Artifact = memo(({ artifactId }: ArtifactProps) => {
5353
return action.type !== 'supabase' && !(action.type === 'shell' && action.content?.includes('supabase'));
5454
});
5555
});
56-
}, [artifact]);
56+
}, [artifact, artifact?.runner]);
5757

5858
const actions = useStore(filteredActions ?? computed(workbenchStore.artifacts, () => [] as ActionState[]));
5959

app/components/chat/BaseChat.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,11 @@ export const BaseChat = React.memo(
497497
setUploadedFiles?.([...uploadedFiles, file]);
498498
setImageDataList?.([...imageDataList, base64Image]);
499499
};
500+
501+
reader.onerror = () => {
502+
logger.error('Failed to read image file:', reader.error);
503+
};
504+
500505
reader.readAsDataURL(file);
501506
}
502507
};
@@ -526,6 +531,11 @@ export const BaseChat = React.memo(
526531
setUploadedFiles?.([...uploadedFiles, file]);
527532
setImageDataList?.([...imageDataList, base64Image]);
528533
};
534+
535+
reader.onerror = () => {
536+
logger.error('Failed to read pasted image:', reader.error);
537+
};
538+
529539
reader.readAsDataURL(file);
530540
}
531541

app/components/chat/Chat.client.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ export const ChatImpl = memo(
286286
* events and pick up stale ports from the dying runtime.
287287
*/
288288
workbenchStore.showWorkbench.set(false);
289+
workbenchStore.resetArtifacts();
289290

290291
if (pollTimeoutRef.current !== null) {
291292
clearTimeout(pollTimeoutRef.current);

app/lib/hooks/usePromptEnhancer.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ export function usePromptEnhancer() {
9999
} catch (error) {
100100
_error = error;
101101
setInput(originalInput);
102+
reader.cancel().catch(() => {});
102103
} finally {
103104
if (_error) {
104105
logger.error(_error);
@@ -107,9 +108,11 @@ export function usePromptEnhancer() {
107108
setEnhancingPrompt(false);
108109
setPromptEnhanced(true);
109110

110-
enhanceTimeoutRef.current = setTimeout(() => {
111-
setInput(_input);
112-
});
111+
if (!_error) {
112+
enhanceTimeoutRef.current = setTimeout(() => {
113+
setInput(_input);
114+
}, 0);
115+
}
113116
}
114117
};
115118

app/lib/persistence/useChatHistory.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,8 @@ export function useChatHistory() {
280280
await Promise.all(filePromises);
281281
} catch (error) {
282282
logger.error('Failed to write snapshot files to runtime filesystem:', error);
283+
284+
return;
283285
}
284286

285287
/*

app/lib/stores/workbench.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,12 @@ export class WorkbenchStore {
133133
this.#previewsStore.reset();
134134
}
135135

136+
resetArtifacts() {
137+
this.artifacts.set({});
138+
this.artifactIdList = [];
139+
this.#reloadedMessages.clear();
140+
}
141+
136142
get files() {
137143
return this.#filesStore.files;
138144
}

0 commit comments

Comments
 (0)