Skip to content

Exceptions when trying to remove a registered JSON schema and disposing a model #1254

@foxable

Description

@foxable

monaco-editor version: 0.15.6
Browser: Chrome
OS: Windows 10

I create instances of monaco-editor to edit several JSON configurations, each having a different, dynamically generated JSON schema. Since there may be a lot of different JSON schemas and the schema may change over time, I remove each schema from the JSON defaults whenever disposing the associated monaco instance (including the model). This to avoid unnecessary memory usage.

Unfortunately, this approach causes exceptions with monaco-editor 0.15.6. You can reproduce the issue with the following snippet:

var modelUri = monaco.Uri.parse("a://b/foo.json");
var model = monaco.editor.createModel("{}", "json", modelUri);

function setSchemas(newSchemas) {
    monaco.languages.json.jsonDefaults.setDiagnosticsOptions({
        schemas: newSchemas
    });
}

setSchemas([{
    uri: "http://myserver/foo-schema.json",
    fileMatch: [modelUri.toString()]
}]);

var editor = monaco.editor.create(document.getElementById("container"), {
    model: model
});

setTimeout(function() {
    setSchemas([]);
    model.dispose();
}, 1000);

This results in the following Exception: jsonMode.js:7 TypeError: Cannot read property 'getModeId' of null. Monaco tries to find the associated model by its URI, which fails and results in the null pointer.

I also tried to remove the JSON schema after disposing the model. However, this results in another exception, namely Uncaught (in promise) TypeError: Cannot read property 'withSyncedResources' of null. In this case, monaco tries to access the JSON worker, which was already stopped when disposing the model.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions