@typefox/monaco-editor-react 7.3.0-next.0 → 7.3.0-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +3 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +45 -35
- package/lib/index.js.map +1 -1
- package/package.json +2 -2
- package/src/index.tsx +45 -38
package/CHANGELOG.md
CHANGED
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to npm module [@typefox/monaco-editor-react](https://www.npmjs.com/package/@typefox/monaco-editor-react) are documented in this file.
|
|
4
4
|
|
|
5
|
-
## [7.3.0-next.
|
|
5
|
+
## [7.3.0-next.1] - 2025-11-05
|
|
6
6
|
|
|
7
|
-
-
|
|
7
|
+
- Fixed re-rendering issues with React StrictMode [#986](https://github.com/TypeFox/monaco-languageclient/pull/986).
|
|
8
|
+
- Updated to `monaco-languageclient@10.3.0-next.1`.
|
|
8
9
|
- Updated all `@codingame/monaco-vscode` packages to `22.1.4`.
|
|
9
10
|
|
|
10
11
|
## [7.2.0] - 2025-10-20
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAAE,KAAK,eAAe,EAAE,KAAK,YAAY,EAAE,MAAM,iCAAiC,CAAC;AACrG,OAAO,EAAE,KAAK,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AACnG,OAAO,EAAgC,KAAK,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,wCAAwC,CAAC;AAC1I,OAAO,KAAK,EAAE,EAAE,KAAK,aAAa,EAAqB,MAAM,OAAO,CAAC;AAErE,MAAM,MAAM,SAAS,GAAG,CAAC,KAAK,EAAE,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC;AAElE,MAAM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,IAAI,CAAC,KAAK,IAAI,CAAC;AAElE,MAAM,MAAM,iBAAiB,GAAG;IAC5B,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,qBAAqB,CAAC;IACvC,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,oBAAoB,CAAC,EAAE,oBAAoB,CAAC;IAC5C,4BAA4B,CAAC,EAAE,OAAO,CAAC;IACvC,mBAAmB,CAAC,EAAE,CAAC,sBAAsB,EAAE,sBAAsB,KAAK,IAAI,CAAC;IAC/E,iBAAiB,CAAC,EAAE,CAAC,SAAS,CAAC,EAAE,SAAS,KAAK,IAAI,CAAC;IACpD,0BAA0B,CAAC,EAAE,CAAC,UAAU,CAAC,EAAE,qBAAqB,KAAK,IAAI,CAAC;IAC1E,aAAa,CAAC,EAAE,CAAC,WAAW,EAAE,YAAY,KAAK,IAAI,CAAC;IACpD,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC,eAAe,CAAC,EAAE,MAAM,IAAI,CAAC;IAC7B,uBAAuB,CAAC,EAAE,MAAM,IAAI,CAAC;IACrC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC9B,CAAA;AAaD,eAAO,MAAM,qBAAqB,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CAkQ7D,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -6,25 +6,27 @@ import { EditorApp } from 'monaco-languageclient/editorApp';
|
|
|
6
6
|
import { LanguageClientManager } from 'monaco-languageclient/lcwrapper';
|
|
7
7
|
import { getEnhancedMonacoEnvironment, MonacoVscodeApiWrapper } from 'monaco-languageclient/vscodeApiWrapper';
|
|
8
8
|
import React, { useEffect, useRef } from 'react';
|
|
9
|
-
//
|
|
9
|
+
// All must be outside of the component as they ars valid across all instances and should not be re-created
|
|
10
|
+
let apiWrapper;
|
|
10
11
|
const lcsManager = new LanguageClientManager();
|
|
12
|
+
const haveEditorService = () => {
|
|
13
|
+
return apiWrapper?.getMonacoVscodeApiConfig().viewsConfig.$type === 'EditorService';
|
|
14
|
+
};
|
|
15
|
+
const runQueue = [];
|
|
16
|
+
let queueAwait = undefined;
|
|
17
|
+
let queueResolve = undefined;
|
|
11
18
|
export const MonacoEditorReactComp = (props) => {
|
|
12
19
|
const { style, className, vscodeApiConfig, editorAppConfig, languageClientConfig, enforceDisposeLanguageClient, onVscodeApiInitDone, onEditorStartDone, onLanguageClientsStartDone, onTextChanged, onError, onDisposeEditor, onDisposeLanguageClient, modifiedTextValue, originalTextValue } = props;
|
|
13
|
-
const apiWrapperRef = useRef(new MonacoVscodeApiWrapper(vscodeApiConfig));
|
|
14
|
-
const haveEditorService = useRef(true);
|
|
15
20
|
const currentEditorConfig = useRef(undefined);
|
|
16
|
-
const editorAppRef = useRef(
|
|
21
|
+
const editorAppRef = useRef(undefined);
|
|
17
22
|
const containerRef = useRef(null);
|
|
18
23
|
const onTextChangedRef = useRef(onTextChanged);
|
|
19
24
|
const modifiedCode = useRef(modifiedTextValue);
|
|
20
25
|
const originalCode = useRef(originalTextValue);
|
|
21
|
-
const runQueue = useRef([]);
|
|
22
|
-
let queueAwait = undefined;
|
|
23
|
-
let queueResolve = undefined;
|
|
24
26
|
const addQueue = (id, func) => {
|
|
25
27
|
debugLogging(`Adding to queue: ${id}`);
|
|
26
|
-
debugLogging(`QUEUE SIZE before: ${runQueue.
|
|
27
|
-
runQueue.
|
|
28
|
+
debugLogging(`QUEUE SIZE before: ${runQueue.length}`);
|
|
29
|
+
runQueue.push({ id, func });
|
|
28
30
|
};
|
|
29
31
|
const triggerQueue = () => {
|
|
30
32
|
setInterval(() => {
|
|
@@ -37,12 +39,13 @@ export const MonacoEditorReactComp = (props) => {
|
|
|
37
39
|
}, 50);
|
|
38
40
|
};
|
|
39
41
|
const executeQueue = async () => {
|
|
40
|
-
while (runQueue.
|
|
41
|
-
const queueObj = runQueue.
|
|
42
|
+
while (runQueue.length > 0) {
|
|
43
|
+
const queueObj = runQueue.shift();
|
|
42
44
|
if (queueObj !== undefined) {
|
|
45
|
+
debugLogging(`QUEUE ${queueObj.id} SIZE before: ${runQueue.length}`);
|
|
43
46
|
debugLogging(`QUEUE ${queueObj.id} start`, true);
|
|
44
47
|
await queueObj.func();
|
|
45
|
-
debugLogging(`QUEUE ${queueObj.id} SIZE after: ${runQueue.
|
|
48
|
+
debugLogging(`QUEUE ${queueObj.id} SIZE after: ${runQueue.length}`);
|
|
46
49
|
debugLogging(`QUEUE ${queueObj.id} end`);
|
|
47
50
|
}
|
|
48
51
|
}
|
|
@@ -52,10 +55,10 @@ export const MonacoEditorReactComp = (props) => {
|
|
|
52
55
|
};
|
|
53
56
|
const debugLogging = (id, useTime) => {
|
|
54
57
|
if (useTime === true) {
|
|
55
|
-
|
|
58
|
+
apiWrapper?.getLogger().debug(`${id}: ${Date.now()}`);
|
|
56
59
|
}
|
|
57
60
|
else {
|
|
58
|
-
|
|
61
|
+
apiWrapper?.getLogger().debug(id);
|
|
59
62
|
}
|
|
60
63
|
};
|
|
61
64
|
const performErrorHandling = (error) => {
|
|
@@ -68,14 +71,14 @@ export const MonacoEditorReactComp = (props) => {
|
|
|
68
71
|
};
|
|
69
72
|
useEffect(() => {
|
|
70
73
|
// this is only available if EditorService is configured
|
|
71
|
-
if (modifiedTextValue !== undefined
|
|
74
|
+
if (haveEditorService() && modifiedTextValue !== undefined) {
|
|
72
75
|
modifiedCode.current = modifiedTextValue;
|
|
73
76
|
editorAppRef.current?.updateCode({ modified: modifiedTextValue });
|
|
74
77
|
}
|
|
75
78
|
}, [modifiedTextValue]);
|
|
76
79
|
useEffect(() => {
|
|
77
80
|
// this is only available if EditorService is configured
|
|
78
|
-
if (originalTextValue !== undefined
|
|
81
|
+
if (haveEditorService() && originalTextValue !== undefined) {
|
|
79
82
|
originalCode.current = originalTextValue;
|
|
80
83
|
editorAppRef.current?.updateCode({ original: originalTextValue });
|
|
81
84
|
}
|
|
@@ -87,19 +90,27 @@ export const MonacoEditorReactComp = (props) => {
|
|
|
87
90
|
const envEnhanced = getEnhancedMonacoEnvironment();
|
|
88
91
|
// init will only performed once
|
|
89
92
|
if (envEnhanced.vscodeApiInitialising !== true) {
|
|
93
|
+
apiWrapper = new MonacoVscodeApiWrapper(vscodeApiConfig);
|
|
90
94
|
const globalInitFunc = async () => {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
95
|
+
try {
|
|
96
|
+
debugLogging('GLOBAL INIT', true);
|
|
97
|
+
if (apiWrapper === undefined)
|
|
98
|
+
throw new Error('Unexpected error occurred: apiWrapper is not available! Aborting...');
|
|
99
|
+
if (haveEditorService()) {
|
|
100
|
+
apiWrapper.overrideViewsConfig({
|
|
101
|
+
$type: 'EditorService',
|
|
102
|
+
htmlContainer: containerRef.current
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
await apiWrapper.start();
|
|
106
|
+
lcsManager.setLogger(apiWrapper.getLogger());
|
|
107
|
+
onVscodeApiInitDone?.(apiWrapper);
|
|
108
|
+
triggerQueue();
|
|
109
|
+
debugLogging('GLOBAL INIT DONE', true);
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
performErrorHandling(error);
|
|
113
|
+
}
|
|
103
114
|
};
|
|
104
115
|
globalInitFunc();
|
|
105
116
|
}
|
|
@@ -113,15 +124,14 @@ export const MonacoEditorReactComp = (props) => {
|
|
|
113
124
|
return;
|
|
114
125
|
// always try to perform global init. Reason: we cannot ensure order
|
|
115
126
|
performGlobalInit();
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
createEditor = currentEditorConfig.current === undefined || JSON.stringify(editorAppConfig) !== JSON.stringify(currentEditorConfig.current);
|
|
120
|
-
}
|
|
127
|
+
// re-create editor if config changed
|
|
128
|
+
const recreateEditor = editorAppRef.current === undefined || currentEditorConfig.current === undefined ||
|
|
129
|
+
JSON.stringify(editorAppConfig) !== JSON.stringify(currentEditorConfig.current);
|
|
121
130
|
const editorInitFunc = async () => {
|
|
122
131
|
try {
|
|
123
132
|
debugLogging('INIT', true);
|
|
124
|
-
|
|
133
|
+
// it is possible to run without an editorApp, for example when using the ViewsService
|
|
134
|
+
if (recreateEditor && haveEditorService()) {
|
|
125
135
|
debugLogging('INIT: Creating editor', true);
|
|
126
136
|
editorAppRef.current?.dispose();
|
|
127
137
|
currentEditorConfig.current = editorAppConfig;
|
|
@@ -184,8 +194,8 @@ export const MonacoEditorReactComp = (props) => {
|
|
|
184
194
|
// dispose editor if used
|
|
185
195
|
debugLogging('DISPOSE', true);
|
|
186
196
|
await editorAppRef.current?.dispose();
|
|
197
|
+
editorAppRef.current = undefined;
|
|
187
198
|
onDisposeEditor?.();
|
|
188
|
-
editorAppRef.current = null;
|
|
189
199
|
debugLogging('DISPOSE DONE', true);
|
|
190
200
|
};
|
|
191
201
|
addQueue('dispose', disposeFunc);
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F,OAAO,EAAE,SAAS,EAA2C,MAAM,iCAAiC,CAAC;AACrG,OAAO,EAA6B,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AACnG,OAAO,EAAE,4BAA4B,EAA8B,sBAAsB,EAAE,MAAM,wCAAwC,CAAC;AAC1I,OAAO,KAAK,EAAE,EAAsB,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAsBrE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F,OAAO,EAAE,SAAS,EAA2C,MAAM,iCAAiC,C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;QAC1C,CAAC;IAAA,CACJ,EAAE,CAAC,4BAA4B,CAAC,CAAC,CAAC;IAEnC,OAAO,CACH,6BACI,GAAG,EAAE,YAAY,EACjB,KAAK,EAAE,KAAK,EACZ,SAAS,EAAE,SAAS,GACtB,CACL,CAAC;AAAA,CACL,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typefox/monaco-editor-react",
|
|
3
|
-
"version": "7.3.0-next.
|
|
3
|
+
"version": "7.3.0-next.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "React component for Monaco-Editor and Monaco Languageclient",
|
|
6
6
|
"keywords": [
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"npm": "10.9.3"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@codingame/monaco-vscode-editor-api": "^22.1.
|
|
49
|
+
"@codingame/monaco-vscode-editor-api": "^22.1.4",
|
|
50
50
|
"react": ">=18.0.0 || <20.0.0"
|
|
51
51
|
},
|
|
52
52
|
"repository": {
|
package/src/index.tsx
CHANGED
|
@@ -28,8 +28,16 @@ export type MonacoEditorProps = {
|
|
|
28
28
|
originalTextValue?: string;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
//
|
|
31
|
+
// All must be outside of the component as they ars valid across all instances and should not be re-created
|
|
32
|
+
let apiWrapper: MonacoVscodeApiWrapper | undefined;
|
|
32
33
|
const lcsManager = new LanguageClientManager();
|
|
34
|
+
const haveEditorService = () => {
|
|
35
|
+
return apiWrapper?.getMonacoVscodeApiConfig().viewsConfig.$type === 'EditorService';
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const runQueue: Array<{id: string, func: () => Promise<void>}> = [];
|
|
39
|
+
let queueAwait: Promise<void> | undefined = undefined;
|
|
40
|
+
let queueResolve: ((value: void | PromiseLike<void>) => void) | undefined = undefined;
|
|
33
41
|
|
|
34
42
|
export const MonacoEditorReactComp: React.FC<MonacoEditorProps> = (props) => {
|
|
35
43
|
const {
|
|
@@ -50,23 +58,17 @@ export const MonacoEditorReactComp: React.FC<MonacoEditorProps> = (props) => {
|
|
|
50
58
|
originalTextValue
|
|
51
59
|
} = props;
|
|
52
60
|
|
|
53
|
-
const apiWrapperRef = useRef<MonacoVscodeApiWrapper>(new MonacoVscodeApiWrapper(vscodeApiConfig));
|
|
54
|
-
const haveEditorService = useRef(true);
|
|
55
61
|
const currentEditorConfig = useRef<EditorAppConfig | undefined>(undefined);
|
|
56
|
-
const editorAppRef = useRef<EditorApp>(
|
|
62
|
+
const editorAppRef = useRef<EditorApp>(undefined);
|
|
57
63
|
const containerRef = useRef<HTMLDivElement>(null);
|
|
58
64
|
const onTextChangedRef = useRef(onTextChanged);
|
|
59
65
|
const modifiedCode = useRef<string>(modifiedTextValue);
|
|
60
66
|
const originalCode = useRef<string>(originalTextValue);
|
|
61
67
|
|
|
62
|
-
const runQueue = useRef<Array<{id: string, func: () => Promise<void>}>>([]);
|
|
63
|
-
let queueAwait: Promise<void> | undefined = undefined;
|
|
64
|
-
let queueResolve: ((value: void | PromiseLike<void>) => void) | undefined = undefined;
|
|
65
|
-
|
|
66
68
|
const addQueue = (id: string, func: () => Promise<void>) => {
|
|
67
69
|
debugLogging(`Adding to queue: ${id}`);
|
|
68
|
-
debugLogging(`QUEUE SIZE before: ${runQueue.
|
|
69
|
-
runQueue.
|
|
70
|
+
debugLogging(`QUEUE SIZE before: ${runQueue.length}`);
|
|
71
|
+
runQueue.push({id, func});
|
|
70
72
|
};
|
|
71
73
|
|
|
72
74
|
const triggerQueue = () => {
|
|
@@ -81,12 +83,13 @@ export const MonacoEditorReactComp: React.FC<MonacoEditorProps> = (props) => {
|
|
|
81
83
|
};
|
|
82
84
|
|
|
83
85
|
const executeQueue = async () => {
|
|
84
|
-
while (runQueue.
|
|
85
|
-
const queueObj = runQueue.
|
|
86
|
+
while (runQueue.length > 0) {
|
|
87
|
+
const queueObj = runQueue.shift();
|
|
86
88
|
if (queueObj !== undefined) {
|
|
89
|
+
debugLogging(`QUEUE ${queueObj.id} SIZE before: ${runQueue.length}`);
|
|
87
90
|
debugLogging(`QUEUE ${queueObj.id} start`, true);
|
|
88
91
|
await queueObj.func();
|
|
89
|
-
debugLogging(`QUEUE ${queueObj.id} SIZE after: ${runQueue.
|
|
92
|
+
debugLogging(`QUEUE ${queueObj.id} SIZE after: ${runQueue.length}`);
|
|
90
93
|
debugLogging(`QUEUE ${queueObj.id} end`);
|
|
91
94
|
}
|
|
92
95
|
}
|
|
@@ -97,9 +100,9 @@ export const MonacoEditorReactComp: React.FC<MonacoEditorProps> = (props) => {
|
|
|
97
100
|
|
|
98
101
|
const debugLogging = (id: string, useTime?: boolean) => {
|
|
99
102
|
if (useTime === true) {
|
|
100
|
-
|
|
103
|
+
apiWrapper?.getLogger().debug(`${id}: ${Date.now()}`);
|
|
101
104
|
} else {
|
|
102
|
-
|
|
105
|
+
apiWrapper?.getLogger().debug(id);
|
|
103
106
|
}
|
|
104
107
|
};
|
|
105
108
|
|
|
@@ -113,7 +116,7 @@ export const MonacoEditorReactComp: React.FC<MonacoEditorProps> = (props) => {
|
|
|
113
116
|
|
|
114
117
|
useEffect(() => {
|
|
115
118
|
// this is only available if EditorService is configured
|
|
116
|
-
if (modifiedTextValue !== undefined
|
|
119
|
+
if (haveEditorService() && modifiedTextValue !== undefined) {
|
|
117
120
|
modifiedCode.current = modifiedTextValue;
|
|
118
121
|
editorAppRef.current?.updateCode({modified: modifiedTextValue});
|
|
119
122
|
}
|
|
@@ -121,7 +124,7 @@ export const MonacoEditorReactComp: React.FC<MonacoEditorProps> = (props) => {
|
|
|
121
124
|
|
|
122
125
|
useEffect(() => {
|
|
123
126
|
// this is only available if EditorService is configured
|
|
124
|
-
if (originalTextValue !== undefined
|
|
127
|
+
if (haveEditorService() && originalTextValue !== undefined) {
|
|
125
128
|
originalCode.current = originalTextValue;
|
|
126
129
|
editorAppRef.current?.updateCode({original: originalTextValue});
|
|
127
130
|
}
|
|
@@ -136,22 +139,28 @@ export const MonacoEditorReactComp: React.FC<MonacoEditorProps> = (props) => {
|
|
|
136
139
|
// init will only performed once
|
|
137
140
|
if (envEnhanced.vscodeApiInitialising !== true) {
|
|
138
141
|
|
|
142
|
+
apiWrapper = new MonacoVscodeApiWrapper(vscodeApiConfig);
|
|
139
143
|
const globalInitFunc = async () => {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
144
|
+
try {
|
|
145
|
+
debugLogging('GLOBAL INIT', true);
|
|
146
|
+
if (apiWrapper === undefined) throw new Error('Unexpected error occurred: apiWrapper is not available! Aborting...');
|
|
147
|
+
|
|
148
|
+
if (haveEditorService()) {
|
|
149
|
+
apiWrapper.overrideViewsConfig({
|
|
150
|
+
$type: 'EditorService',
|
|
151
|
+
htmlContainer: containerRef.current!
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
await apiWrapper.start();
|
|
147
155
|
|
|
148
|
-
|
|
149
|
-
haveEditorService.current = envEnhanced.viewServiceType === 'EditorService';
|
|
150
|
-
lcsManager.setLogger(apiWrapperRef.current.getLogger());
|
|
156
|
+
lcsManager.setLogger(apiWrapper.getLogger());
|
|
151
157
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
158
|
+
onVscodeApiInitDone?.(apiWrapper);
|
|
159
|
+
triggerQueue();
|
|
160
|
+
debugLogging('GLOBAL INIT DONE', true);
|
|
161
|
+
} catch (error) {
|
|
162
|
+
performErrorHandling(error as Error);
|
|
163
|
+
}
|
|
155
164
|
};
|
|
156
165
|
globalInitFunc();
|
|
157
166
|
} else if (envEnhanced.vscodeApiInitialised === true) {
|
|
@@ -166,17 +175,15 @@ export const MonacoEditorReactComp: React.FC<MonacoEditorProps> = (props) => {
|
|
|
166
175
|
// always try to perform global init. Reason: we cannot ensure order
|
|
167
176
|
performGlobalInit();
|
|
168
177
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
createEditor = currentEditorConfig.current === undefined || JSON.stringify(editorAppConfig) !== JSON.stringify(currentEditorConfig.current);
|
|
173
|
-
}
|
|
174
|
-
|
|
178
|
+
// re-create editor if config changed
|
|
179
|
+
const recreateEditor = editorAppRef.current === undefined || currentEditorConfig.current === undefined ||
|
|
180
|
+
JSON.stringify(editorAppConfig) !== JSON.stringify(currentEditorConfig.current);
|
|
175
181
|
const editorInitFunc = async () => {
|
|
176
182
|
try {
|
|
177
183
|
debugLogging('INIT', true);
|
|
178
184
|
|
|
179
|
-
|
|
185
|
+
// it is possible to run without an editorApp, for example when using the ViewsService
|
|
186
|
+
if (recreateEditor && haveEditorService()) {
|
|
180
187
|
debugLogging('INIT: Creating editor', true);
|
|
181
188
|
|
|
182
189
|
editorAppRef.current?.dispose();
|
|
@@ -251,8 +258,8 @@ export const MonacoEditorReactComp: React.FC<MonacoEditorProps> = (props) => {
|
|
|
251
258
|
debugLogging('DISPOSE', true);
|
|
252
259
|
|
|
253
260
|
await editorAppRef.current?.dispose();
|
|
261
|
+
editorAppRef.current = undefined;
|
|
254
262
|
onDisposeEditor?.();
|
|
255
|
-
editorAppRef.current = null;
|
|
256
263
|
|
|
257
264
|
debugLogging('DISPOSE DONE', true);
|
|
258
265
|
};
|