fix: 直接调用dispose函数清空编辑器插件,避免类型异常引起组件崩溃

This commit is contained in:
ranqirong 2024-10-12 19:14:42 +08:00
parent d49bd3bf37
commit fb46122cff

View File

@ -118,7 +118,7 @@ export class Editor extends React.Component<EditorProps, EditorState> {
container: any;
currentValue: any;
preventTriggerChangeEvent: boolean;
disposes: Array<{dispose: () => void}> = [];
disposes: Array<() => void> = [];
constructor(props: EditorProps) {
super(props);
@ -176,7 +176,7 @@ export class Editor extends React.Component<EditorProps, EditorState> {
const editorWillUnmount = this.props.editorWillUnmount;
editorWillUnmount && editorWillUnmount(this.editor, monaco);
}
this.disposes.forEach(({dispose}) => dispose());
this.disposes.forEach(dispose => dispose());
this.disposes = [];
this.editor?.dispose();
}
@ -187,7 +187,7 @@ export class Editor extends React.Component<EditorProps, EditorState> {
this.loadMonaco();
} else {
try {
this.disposes.forEach(({dispose}) => dispose());
this.disposes.forEach(dispose => dispose());
this.disposes = [];
if (this.editor) {
this.editor.getModel().dispose();