monaco-react icon indicating copy to clipboard operation
monaco-react copied to clipboard

Uncaught Error: TextModel got disposed before DiffEditorWidget model got reset

Open armisael opened this issue 1 year ago • 14 comments

When using DiffEditor with Monaco 0.51 and the component is unmounted, the following error is thrown:

Error: TextModel got disposed before DiffEditorWidget model got reset
    at u.value (diffEditorWidget.ts:327:24)
    at d._deliver (event.ts:1213:13)
    at d._deliverQueue (event.ts:1224:9)
    at d.fire (event.ts:1248:9)
    at q.dispose (textModel.ts:356:23)
...

The error does not appear with Monaco 0.50.

To Reproduce

I prepared a minimal code snippet to reproduce the issue: https://github.com/armisael/test-react-monaco-diff

Simply:

  1. npm run dev
  2. open your browser on http://localhost:3000
  3. open the inspector
  4. click on "Show editor"
  5. click on "Hide editor"
  6. see the error in console

Desktop (please complete the following information):

  • OS: OSX
  • Browser: Arc (chromium-based)
  • Version: @monaco-editor/react 4.6.0

armisael avatar Sep 25 '24 09:09 armisael

@armisael Do you know if this error has any real impact, or is it safe to ignore?

Eyal-Be avatar Sep 25 '24 14:09 Eyal-Be

In our case we didn't notice any real impact, so our solution was indeed to ignore it, but I can't assume this is true for all cases.

Also, people over https://github.com/microsoft/vscode/issues/218001 had what looks like the same issue, and fixed it a couple of months ago.

armisael avatar Sep 25 '24 15:09 armisael

@armisael @Eyal-Be could you please try to load the latest monaco-editor version via loader and see if the fix @armisael mentioned here helps? You can do something like this

suren-atoyan avatar Sep 26 '24 13:09 suren-atoyan

Hi @suren-atoyan , that's exactly what I'm doing in the test project, have a look at:

https://github.com/armisael/test-react-monaco-diff/blob/main/src/components/MonacoDiffEditor.tsx

The error appears when using [email protected] and [email protected], but not with [email protected].

I'm not sure how to interpret the issue on https://github.com/microsoft/vscode/issues/218001 I'm afraid I can't help much

armisael avatar Sep 26 '24 14:09 armisael

i'm experiencing the same error and in my case it is a problem indeed: i have a nextjs react app, and a page with a several Editors and DiffEditors, which can be switched by sidebar tabs, in case where i have 2+ DiffEditors and i switch between them a couple times – i get the mentioned error and the result looks like monaco is showing me correct text in the DiffEditor but is using a model from the previous tab' DiffEditor to highlight the diffs: image

tsx-ell avatar Dec 11 '24 08:12 tsx-ell

Any update to this as the issue is still there when the DiffEditor is unmounted !?

SundaramMaheshkumar avatar Mar 19 '25 11:03 SundaramMaheshkumar

https://github.com/microsoft/vscode/issues/218001

sankalpmukim avatar May 05 '25 06:05 sankalpmukim

https://github.com/microsoft/vscode/pull/222197

sankalpmukim avatar May 05 '25 06:05 sankalpmukim

I managed to solve this error by setting two fields to true, as per screenshot below:

keepCurrentOriginalModel={true} keepCurrentModifiedModel={true}

Image

SitholeWB avatar May 21 '25 08:05 SitholeWB

Hi @suren-atoyan, is there any update on this issue?

We're still encountering this error with [email protected] and 0.52.0, particularly in Firefox where it throws visibly and disrupts the UI. We've temporarily worked around it by forcing the Monaco version to 0.50.0 using @monaco-editor/loader as suggested earlier by @armisael

While this workaround works for now, we would prefer to upgrade and stay current. Do you have any timeline or ETA for an official fix?

Thanks for your help!

shreyasriram avatar Jul 01 '25 21:07 shreyasriram

Hi @suren-atoyan, is there any update on this issue?

We're still encountering this error with [email protected] and 0.52.0, particularly in Firefox where it throws visibly and disrupts the UI. We've temporarily worked around it by forcing the Monaco version to 0.50.0 using @monaco-editor/loader as suggested earlier by @armisael

While this workaround works for now, we would prefer to upgrade and stay current. Do you have any timeline or ETA for an official fix?

Thanks for your help!

have you tried this?

suren-atoyan avatar Jul 02 '25 11:07 suren-atoyan

Hi @suren-atoyan, is there any update on this issue? We're still encountering this error with [email protected] and 0.52.0, particularly in Firefox where it throws visibly and disrupts the UI. We've temporarily worked around it by forcing the Monaco version to 0.50.0 using @monaco-editor/loader as suggested earlier by @armisael While this workaround works for now, we would prefer to upgrade and stay current. Do you have any timeline or ETA for an official fix? Thanks for your help!

have you tried this?

Yes it works. Thank you for your time

shreyasriram avatar Jul 03 '25 18:07 shreyasriram

Hi @suren-atoyan, is there any update on this issue? We're still encountering this error with [email protected] and 0.52.0, particularly in Firefox where it throws visibly and disrupts the UI. We've temporarily worked around it by forcing the Monaco version to 0.50.0 using @monaco-editor/loader as suggested earlier by @armisael While this workaround works for now, we would prefer to upgrade and stay current. Do you have any timeline or ETA for an official fix? Thanks for your help!

have you tried this?

Worked for me are you able to tag as solution and maybe add to the example in README?

volkandkaya avatar Jul 08 '25 03:07 volkandkaya

I managed to solve this error by setting two fields to true, as per screenshot below:

keepCurrentOriginalModel={true} keepCurrentModifiedModel={true}

Image

When there are many editors, will this lead to memory leaks? We should manage the textmodel by ourselves.

fengzi2016 avatar Nov 24 '25 08:11 fengzi2016