1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Fix app crash when sometimes using MonacoEditor (#6893)

Signed-off-by: Sebastian Malton <sebastian@malton.name>

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2023-01-09 07:52:06 -08:00 committed by GitHub
parent 378d9d7d8f
commit 900a8bbda3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -19,6 +19,8 @@ import { withInjectables } from "@ogre-tools/injectable-react";
import userStoreInjectable from "../../../common/user-store/user-store.injectable";
import activeThemeInjectable from "../../themes/active.injectable";
import getEditorHeightFromLinesCountInjectable from "./get-editor-height-from-lines-number.injectable";
import type { Logger } from "../../../common/logger";
import loggerInjectable from "../../../common/logger.injectable";
export type MonacoEditorId = string;
@ -45,6 +47,7 @@ interface Dependencies {
userStore: UserStore;
activeTheme: IComputedValue<LensTheme>;
getEditorHeightFromLinesCount: (linesCount: number) => number;
logger: Logger;
}
export function createMonacoUri(id: MonacoEditorId): Uri {
@ -98,7 +101,14 @@ class NonInjectedMonacoEditor extends React.Component<MonacoEditorProps & Depend
return model; // already exists
}
const { language, value } = this.props;
const { language, value: rawValue } = this.props;
const value = typeof rawValue === "string"
? rawValue
: "";
if (typeof rawValue !== "string") {
this.props.logger.error(`[MONACO-EDITOR]: Passed a non-string default value`, { rawValue });
}
return editor.createModel(value, language, uri);
}
@ -322,6 +332,7 @@ export const MonacoEditor = withInjectables<Dependencies, MonacoEditorProps, Mon
userStore: di.inject(userStoreInjectable),
activeTheme: di.inject(activeThemeInjectable),
getEditorHeightFromLinesCount: di.inject(getEditorHeightFromLinesCountInjectable),
logger: di.inject(loggerInjectable),
}),
},
);