Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
foxable opened this issue Jan 3, 2019 · 1 comment
Assignees
Labels

Comments

@foxable
Copy link

foxable commented Jan 3, 2019

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.

@nodejh
Copy link

nodejh commented Mar 18, 2019

I have the same issue on macOS Chrome.

@vscodebot vscodebot bot locked and limited conversation to collaborators Oct 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants