serdarciplak / BlazorMonaco

Blazor component for Microsoft's Monaco Editor which powers Visual Studio Code.
https://serdarciplak.github.io/BlazorMonaco/
MIT License
454 stars 98 forks source link

Cannot register to event without errors #74

Closed svenboulanger closed 1 year ago

svenboulanger commented 1 year ago

I have been using v2.1 previously in a Blazor wasm app and am trying to migrate to 3.0. However, registering to the OnDidModelContentChange event causes errors in the browser console.

The error that is showing in the browser log is:

Uncaught Error: Cannot read properties of null (reading 'invokeMethodAsync')

TypeError: Cannot read properties of null (reading 'invokeMethodAsync')
    at listener (jsInterop.js:470:23)
    at p.fire (marked.js:2074:1)
    at editorScrollbar.ts:195:19
    at findInput.ts:388:40
    at p.fire (marked.js:2074:1)
    at X.fire (pieceTreeTextBufferBuilder.ts:39:10)
    at W._emitContentChangedEvent (abstractTree.ts:1383:2)
    at W._setValueFromTextBuffer (abstractTree.ts:1439:15)
    at W.setValue (abstractTree.ts:1398:3)
    at I.setValue (editorScrollbar.ts:195:19)
    at dompurify.js:571:1

It occurs every time the contents of the editor change. If I do not register for the event, I don't receive any errors.

I should mention that I am using a custom language. I define it in index.html as a javascript function registerLanguage and invoke it after rendering the page using:

await _js.InvokeVoidAsync("registerLanguage", new object[] { keys.ToArray() });
var model = await _scriptEditor.GetModel();
await Global.SetModelLanguage(model, "simpleCircuit");
await Global.SetTheme("simpleCircuitTheme");

(keys is a list of keywords that is generated using reflection). SimpleCircuit is the name of the program (repository).

serdarciplak commented 1 year ago

The line number in the error (jsInterop.js:470:23) is a location from the old version of this js file. It may be a browser cache issue. Can you please try again clearing the browser cache? Please let me know if it works or not.

svenboulanger commented 1 year ago

Thanks. It seems to have fixed the errors if I disabled cache.

I am still seeing weird warnings in the console however (probably unrelated to this issue, it's the first two warnings I posted in issue #75) and it seems my custom language has broken but I'm guessing that is because the Monaco editor has also been updated...

serdarciplak commented 1 year ago

As I mentioned in #75, those warnings are expected. I'll clear them in the next release.

You're right that broken custom language may be because of the Monaco Editor version update. Nothing has changed about custom languages in BlazorMonaco.

svenboulanger commented 1 year ago

I missed that the warnings were expected. I changed the language to css and was simply happy it was working... Thanks!