Skip to content

Commit add086b

Browse files
iHiDclaude
andauthored
Guard against undefined value in CodeMirror component (#8708)
When value is undefined/null, CodeMirror crashes trying to read .length on it during EditorState.create. Return an empty editor div instead. Closes #8692 Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent f5aee27 commit add086b

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

app/javascript/components/misc/CodeMirror.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ export default function CodeMirror({
5151
const [textarea, setTextarea] = useState<HTMLDivElement | null>(null)
5252
const viewRef = useRef<EditorView | null>(null)
5353

54+
if (value === undefined || value === null) {
55+
return <div className="editor" />
56+
}
57+
5458
const setValue = (text: string) => {
5559
if (!viewRef.current) {
5660
return

0 commit comments

Comments
 (0)