@@ -647,6 +647,13 @@ export default class ContentWrap extends Component {
647647 const baseTranspilerPath = 'lib/transpilers' ;
648648 // Exit if already loaded
649649 var d = deferred ( ) ;
650+
651+ // Add null check for modes[mode]
652+ if ( ! mode || ! modes [ mode ] ) {
653+ d . resolve ( ) ;
654+ return d . promise ;
655+ }
656+
650657 if ( modes [ mode ] . hasLoaded ) {
651658 d . resolve ( ) ;
652659 return d . promise ;
@@ -688,36 +695,57 @@ export default class ContentWrap extends Component {
688695 updateHtmlMode ( value ) {
689696 this . props . onCodeModeChange ( 'html' , value ) ;
690697 this . props . currentItem . htmlMode = value ;
691- CodeMirror . autoLoadMode (
692- this . cm . html ,
693- modes [ value ] . cmPath || modes [ value ] . cmMode ,
694- ) ;
698+
699+ // Add null check to prevent "Cannot read properties of undefined (reading 'cmPath')" error
700+ if ( this . cm && this . cm . html && modes [ value ] ) {
701+ CodeMirror . autoLoadMode (
702+ this . cm . html ,
703+ modes [ value ] . cmPath || modes [ value ] . cmMode ,
704+ ) ;
705+ }
706+
695707 return this . handleModeRequirements ( value ) ;
696708 }
697709
698710 updateCssMode ( value ) {
699711 this . props . onCodeModeChange ( 'css' , value ) ;
700712 this . props . currentItem . cssMode = value ;
701- this . cm . css . setOption ( 'mode' , modes [ value ] . cmMode ) ;
702- this . cm . css . setOption ( 'readOnly' , modes [ value ] . cmDisable ) ;
703- window . cssSettingsBtn . classList [
704- modes [ value ] . hasSettings ? 'remove' : 'add'
705- ] ( 'hide' ) ;
706- CodeMirror . autoLoadMode (
707- this . cm . css ,
708- modes [ value ] . cmPath || modes [ value ] . cmMode ,
709- ) ;
713+
714+ // Add null check to prevent "Cannot read properties of undefined" error
715+ if ( this . cm && this . cm . css && modes [ value ] ) {
716+ this . cm . css . setOption ( 'mode' , modes [ value ] . cmMode ) ;
717+ this . cm . css . setOption ( 'readOnly' , modes [ value ] . cmDisable ) ;
718+
719+ CodeMirror . autoLoadMode (
720+ this . cm . css ,
721+ modes [ value ] . cmPath || modes [ value ] . cmMode ,
722+ ) ;
723+ }
724+
725+ // Only modify DOM if the element exists
726+ if ( window . cssSettingsBtn && modes [ value ] ) {
727+ window . cssSettingsBtn . classList [
728+ modes [ value ] . hasSettings ? 'remove' : 'add'
729+ ] ( 'hide' ) ;
730+ }
731+
710732 return this . handleModeRequirements ( value ) ;
711733 }
712734
713735 updateJsMode ( value ) {
714736 this . props . onCodeModeChange ( 'js' , value ) ;
715737 this . props . currentItem . jsMode = value ;
716- this . cm . js . setOption ( 'mode' , modes [ value ] . cmMode ) ;
717- CodeMirror . autoLoadMode (
718- this . cm . js ,
719- modes [ value ] . cmPath || modes [ value ] . cmMode ,
720- ) ;
738+
739+ // Add null check to prevent "Cannot read properties of undefined" error
740+ if ( this . cm && this . cm . js && modes [ value ] ) {
741+ this . cm . js . setOption ( 'mode' , modes [ value ] . cmMode ) ;
742+
743+ CodeMirror . autoLoadMode (
744+ this . cm . js ,
745+ modes [ value ] . cmPath || modes [ value ] . cmMode ,
746+ ) ;
747+ }
748+
721749 return this . handleModeRequirements ( value ) ;
722750 }
723751
@@ -988,17 +1016,15 @@ export default class ContentWrap extends Component {
9881016 < UserCodeMirror
9891017 ref = { ( dslEditor ) => ( this . dslEditor = dslEditor ) }
9901018 options = { {
991- mode : 'htmlmixed' ,
992- profile : 'xhtml' ,
1019+ mode : 'javascript' ,
9931020 gutters : [
9941021 'CodeMirror-linenumbers' ,
9951022 'CodeMirror-foldgutter' ,
9961023 ] ,
9971024 noAutocomplete : true ,
998- matchTags : { bothTags : true } ,
9991025 prettier : true ,
1000- prettierParser : 'html ' ,
1001- emmet : true ,
1026+ prettierParser : 'babel ' ,
1027+ emmet : false ,
10021028 } }
10031029 prefs = { this . props . prefs }
10041030 autoComplete = { this . props . prefs . autoComplete }
0 commit comments