You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 16, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Apr 16, 2026. It is now read-only.
Cannot read properties of undefined (reading 'map') #6886
As follow, i am working on changing mode when editing.
There seems this.instance.setOption("mode",mode) has no error, but then, the editor can't be focused on and Cannot read properties of undefined (reading 'map') appears.
Have you tried reducing this problem to the minimal script needed to trigger it? That might help reproduce the issue (dynamically changing the mode generally works).
Have you tried reducing this problem to the minimal script needed to trigger it? That might help reproduce the issue (dynamically changing the mode generally works).
As follow, it is just a single *.vue file(vue3). After changing mode and input again, the issue will reproduce.
I don't know a lot about Vue, but I do know that is does strange things to objects managed as part of its state, and you don't want to put complicated stateful objects like a CodeMirror instance in there. Try refactoring your code to not have the CodeMirror instance in the data object.
Reacted by Luis Perez, Rainst, Arely Viana, YangFong and wrabit
Thank you so much I was having the same issue Cannot read properties of undefined (reading 'map') occasionally and I removed codemirror instance from data object and instance just assigned it to a const.
Thank you so much @marijnh, I recently had the same problem using Vue3's composition API.
I'll put my code here and how I fixed it in case someone (or even me again) addresses the same issue in the future...
BEFORE:
constcodeEditor: Ref<any> = ref({});
onMounted(() =>{codeEditor.value=CodeMirror.fromTextArea(textAreaRef,opts);codeEditor.value.setSize('100%',props.fullHeight ? '100%' : 500);// This line was triggering the error.});
AFTER:
constcodeEditor: Ref<any> = ref({});
onMounted(() =>{// I created a local variable inside this 'onMounted' scope just to configure my CodeMirror instance.constcodeMirror=CodeMirror.fromTextArea(textAreaRef,opts);codeMirror.setSize('100%',props.fullHeight ? '100%' : 500);// After finishing the setup I assign the instance to my ref variable (because I need it outside this scope)codeEditor.value=codeMirror;});
Activity
marijnh commentedon Feb 27, 2022
Have you tried reducing this problem to the minimal script needed to trigger it? That might help reproduce the issue (dynamically changing the mode generally works).
xdewx commentedon Feb 28, 2022
As follow, it is just a single
*.vuefile(vue3). After changing mode and input again, the issue will reproduce.marijnh commentedon Feb 28, 2022
I don't know a lot about Vue, but I do know that is does strange things to objects managed as part of its state, and you don't want to put complicated stateful objects like a CodeMirror instance in there. Try refactoring your code to not have the CodeMirror instance in the
dataobject.xdewx commentedon Mar 6, 2022
Okay, thank you.
lperez22 commentedon May 25, 2022
Thank you so much I was having the same issue Cannot read properties of undefined (reading 'map') occasionally and I removed codemirror instance from data object and instance just assigned it to a const.
Rainst9 commentedon Sep 7, 2023
Thank you so much!!!
AreViana commentedon May 4, 2024
Thank you so much @marijnh, I recently had the same problem using Vue3's composition API.
I'll put my code here and how I fixed it in case someone (or even me again) addresses the same issue in the future...
BEFORE:
AFTER:
Update codemirror + fix bug with storing codemirror in vue refs codem…
Fix: handle CodeMirror race condition error gracefully
Fix: handle CodeMirror race condition error gracefully