Skip to content

Commit d3188f7

Browse files
author
Loïc Mangeonjean
committed
fix: dispose model references
1 parent 89c73ff commit d3188f7

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/MonacoEditor.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,12 @@ function MonacoEditor ({
202202
setModelReady(false)
203203

204204
const value = valueRef.current
205+
let modelIRefPromise: Promise<IReference<ITextFileEditorModel>> | undefined
205206
let modelIRef: IReference<ITextFileEditorModel> | undefined
206207
let model: monaco.editor.ITextModel
207208
if (fileUri != null) {
208-
modelIRef = await createModelReference(monaco.Uri.parse(fileUri), value!)
209+
modelIRefPromise = createModelReference(monaco.Uri.parse(fileUri), value!)
210+
modelIRef = (await modelIRefPromise)!
209211
if (cancelled) {
210212
modelIRef.dispose()
211213
return () => {}
@@ -228,6 +230,7 @@ function MonacoEditor ({
228230
if (editorRef.current != null) {
229231
lastSaveViewState(editorRef.current, model)
230232
}
233+
modelIRefPromise?.then(modelIRef => modelIRef.dispose(), console.error)
231234
modelRef.current = undefined
232235
}
233236
}

0 commit comments

Comments
 (0)