Skip to content

Commit 0fcb2be

Browse files
iHiDclaude
andauthored
Guard against empty files array in FileEditorCodeMirror (#8423)
Return null early when the files prop is empty or undefined, preventing a TypeError when accessing files[0].filename. This can occur when localStorage returns an empty array for saved files. Closes #8419 Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2d1482b commit 0fcb2be

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

app/javascript/components/editor/FileEditorCodeMirror.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ export function FileEditorCodeMirror({
4141
settings: EditorSettings
4242
files: File[]
4343
readonly: boolean
44-
}): JSX.Element {
44+
}): JSX.Element | null {
45+
if (!defaultFiles || defaultFiles.length === 0) {
46+
return null
47+
}
48+
4549
const [files, setFiles] = useState(defaultFiles)
4650
const [tab, setTab] = useState(files[0].filename)
4751
const containerRef = useRef<HTMLDivElement>(null)

0 commit comments

Comments
 (0)