Skip to content

Commit 3e66d20

Browse files
committed
Addition of optional chaining to prevent crash
1 parent 8bde63c commit 3e66d20

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

frontend/packages/console-shared/src/components/editor/CodeEditor.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const CodeEditor = React.forwardRef<MonacoEditor, CodeEditorProps>((props, ref)
2424
const [usesValue] = React.useState<boolean>(value !== undefined);
2525
const editorDidMount = React.useCallback(
2626
(editor, monaco) => {
27-
const currentLanguage = editor.getModel().getModeId();
27+
const currentLanguage = editor.getModel()?.getModeId();
2828
editor.layout();
2929
editor.focus();
3030
switch (currentLanguage) {

frontend/packages/console-shared/src/components/editor/yaml-editor-utils.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ const MODEL_URI = 'inmemory://model.yaml';
1616
const MONACO_URI = monaco.Uri.parse(MODEL_URI);
1717

1818
const createDocument = (model) => {
19-
return TextDocument.create(MODEL_URI, model.getModeId(), model.getVersionId(), model.getValue());
19+
return TextDocument.create(
20+
MODEL_URI,
21+
model?.getModeId(),
22+
model?.getVersionId(),
23+
model?.getValue(),
24+
);
2025
};
2126

2227
// Unfortunately, `editor.focus()` doesn't work when hiding the shortcuts

0 commit comments

Comments
 (0)