From fb02148fbf396d2f62345b8caaccaf5339e92ef1 Mon Sep 17 00:00:00 2001 From: Steve Goodwin Date: Fri, 1 Mar 2024 00:48:27 -0500 Subject: [PATCH] Changes to prevent editor crash with acm and mce plugins enabled. To be backported to 4.14 --- .../console-shared/src/components/editor/yaml-editor-utils.ts | 4 ++-- frontend/public/components/edit-yaml.jsx | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/frontend/packages/console-shared/src/components/editor/yaml-editor-utils.ts b/frontend/packages/console-shared/src/components/editor/yaml-editor-utils.ts index 3bf8040ef27..a787d5512fe 100644 --- a/frontend/packages/console-shared/src/components/editor/yaml-editor-utils.ts +++ b/frontend/packages/console-shared/src/components/editor/yaml-editor-utils.ts @@ -182,7 +182,7 @@ export const enableYAMLValidation = ( ) => { const pendingValidationRequests = new Map(); - const getModel = () => monaco.editor.getModels()[0]; + const getModel = () => monaco.editor?.getModels()[0]; const cleanPendingValidation = (document) => { const request = pendingValidationRequests.get(document.uri); @@ -221,7 +221,7 @@ export const enableYAMLValidation = ( tryFolding(); } - getModel().onDidChangeContent(() => { + getModel()?.onDidChangeContent(() => { tryFolding(); const document = createDocument(getModel()); diff --git a/frontend/public/components/edit-yaml.jsx b/frontend/public/components/edit-yaml.jsx index 61c3e4ab759..a045890347c 100644 --- a/frontend/public/components/edit-yaml.jsx +++ b/frontend/public/components/edit-yaml.jsx @@ -199,7 +199,7 @@ const EditYAMLInner = (props) => { const notAll = !resp.status.allowed; setNotAllowed(notAll); if (monacoRef.current) { - monacoRef.current.editor.updateOptions({ readOnly: notAll }); + monacoRef.current.editor?.updateOptions({ readOnly: notAll }); } }) .catch((e) => { @@ -638,7 +638,7 @@ const EditYAMLInner = (props) => { 'co-file-dropzone--drop-over': isOver, }); - monacoRef.current?.editor.updateOptions({ hover: showTooltips }); + monacoRef.current?.editor?.updateOptions({ hover: showTooltips }); if (displayResults) { return (