Skip to content
Merged
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
3 changes: 2 additions & 1 deletion src/components/ai-elements/custom/code-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,10 @@ export const CodeEditor = ({
await navigator.clipboard.writeText(activeFile.content);
setCopied(true);
setTimeout(() => setCopied(false), 2000);
Comment on lines 184 to 186
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

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

The handleCopy function should include a null check for activeFile similar to handleDownload. Line 149 shows that activeFile uses a fallback to editorFiles[0], but if editorFiles is empty, activeFile could be undefined, causing a runtime error when accessing activeFile.content.

Suggested change
await navigator.clipboard.writeText(activeFile.content);
setCopied(true);
setTimeout(() => setCopied(false), 2000);
if (!activeFile) { return; }
await navigator.clipboard.writeText(activeFile.content);
setCopied(true);
setTimeout(() => setCopied(false), 2000);

Copilot uses AI. Check for mistakes.
}, []);
}, [activeFile]);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue (bug_risk): Guard activeFile in the clipboard handler to avoid potential runtime errors.

handleDownload now guards against a falsy activeFile, which confirms it can be unset. The clipboard handler still accesses activeFile.content without a check, so it can throw when no file is active. Add a similar guard there or disable the copy action when !activeFile to keep behavior safe and consistent.


const handleDownload = useCallback(() => {
if (!activeFile) {return;}
const blob = new Blob([activeFile.content], { type: "text/plain" });
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
Expand Down
Loading