mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
fix: app-crash with multiple usages of monaco-editor component (#5479)
how to reproduce: open one pod on monaco editor (ie edit), and then try to open another pod details (or try to edit it as well)
This commit is contained in:
parent
41d4daded7
commit
938d34739f
@ -16,7 +16,6 @@ import { UserStore } from "../../../common/user-store";
|
|||||||
import type { ThemeStore } from "../../themes/store";
|
import type { ThemeStore } from "../../themes/store";
|
||||||
import { withInjectables } from "@ogre-tools/injectable-react";
|
import { withInjectables } from "@ogre-tools/injectable-react";
|
||||||
import themeStoreInjectable from "../../themes/store.injectable";
|
import themeStoreInjectable from "../../themes/store.injectable";
|
||||||
import logger from "../../../main/logger";
|
|
||||||
|
|
||||||
export type MonacoEditorId = string;
|
export type MonacoEditorId = string;
|
||||||
|
|
||||||
@ -66,6 +65,11 @@ class NonInjectedMonacoEditor extends React.Component<MonacoEditorProps & Depend
|
|||||||
@observable readonly dimensions: { width?: number; height?: number } = {};
|
@observable readonly dimensions: { width?: number; height?: number } = {};
|
||||||
@observable unmounting = false;
|
@observable unmounting = false;
|
||||||
|
|
||||||
|
// TODO: investigate how to replace with "common/logger"
|
||||||
|
// currently leads for stucking UI forever & infinite loop.
|
||||||
|
// e.g. happens on tab change/create, maybe some other cases too.
|
||||||
|
private logger = console;
|
||||||
|
|
||||||
constructor(props: MonacoEditorProps & Dependencies) {
|
constructor(props: MonacoEditorProps & Dependencies) {
|
||||||
super(props);
|
super(props);
|
||||||
makeObservable(this);
|
makeObservable(this);
|
||||||
@ -129,7 +133,7 @@ class NonInjectedMonacoEditor extends React.Component<MonacoEditorProps & Depend
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected onModelChange(model: editor.ITextModel, oldModel?: editor.ITextModel) {
|
protected onModelChange(model: editor.ITextModel, oldModel?: editor.ITextModel) {
|
||||||
logger.info("[MONACO]: model change", { model, oldModel }, this.logMetadata);
|
this.logger.info("[MONACO]: model change", { model, oldModel }, this.logMetadata);
|
||||||
|
|
||||||
if (oldModel) {
|
if (oldModel) {
|
||||||
this.saveViewState(oldModel);
|
this.saveViewState(oldModel);
|
||||||
@ -166,9 +170,9 @@ class NonInjectedMonacoEditor extends React.Component<MonacoEditorProps & Depend
|
|||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
try {
|
try {
|
||||||
this.createEditor();
|
this.createEditor();
|
||||||
logger.info(`[MONACO]: editor did mount`, this.logMetadata);
|
this.logger.info(`[MONACO]: editor did mount`, this.logMetadata);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`[MONACO]: mounting failed: ${error}`, this.logMetadata);
|
this.logger.error(`[MONACO]: mounting failed: ${error}`, this.logMetadata);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,7 +204,7 @@ class NonInjectedMonacoEditor extends React.Component<MonacoEditorProps & Depend
|
|||||||
...this.options,
|
...this.options,
|
||||||
});
|
});
|
||||||
|
|
||||||
logger.info(`[MONACO]: editor created for language=${language}, theme=${theme}`, this.logMetadata);
|
this.logger.info(`[MONACO]: editor created for language=${language}, theme=${theme}`, this.logMetadata);
|
||||||
this.validateLazy(); // validate initial value
|
this.validateLazy(); // validate initial value
|
||||||
this.restoreViewState(this.model); // restore previous state if any
|
this.restoreViewState(this.model); // restore previous state if any
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user