Skip to content

Commit

Permalink
fix: dispose model references
Browse files Browse the repository at this point in the history
  • Loading branch information
Loïc Mangeonjean committed Jan 30, 2024
1 parent 89c73ff commit d3188f7
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/MonacoEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,12 @@ function MonacoEditor ({
setModelReady(false)

const value = valueRef.current
let modelIRefPromise: Promise<IReference<ITextFileEditorModel>> | undefined
let modelIRef: IReference<ITextFileEditorModel> | undefined
let model: monaco.editor.ITextModel
if (fileUri != null) {
modelIRef = await createModelReference(monaco.Uri.parse(fileUri), value!)
modelIRefPromise = createModelReference(monaco.Uri.parse(fileUri), value!)
modelIRef = (await modelIRefPromise)!
if (cancelled) {
modelIRef.dispose()
return () => {}
Expand All @@ -228,6 +230,7 @@ function MonacoEditor ({
if (editorRef.current != null) {
lastSaveViewState(editorRef.current, model)
}
modelIRefPromise?.then(modelIRef => modelIRef.dispose(), console.error)
modelRef.current = undefined
}
}
Expand Down

0 comments on commit d3188f7

Please sign in to comment.