serdarciplak / BlazorMonaco

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

Microsoft.JSInterop.JSException: Couldn't find the editor with id: entity-view editors.length: 0 #133

Open FLAMESpl opened 4 months ago

FLAMESpl commented 4 months ago

I cannot set value to code editor, I am getting this exception: Microsoft.JSInterop.JSException: Couldn't find the editor with id: entity-view editors.length: 0

I am declaring code editor like this:

                <StandaloneCodeEditor @ref="codeEditor"
                                      Id="entity-view"
                                      ConstructionOptions="GetConstructionOptions"/>

and setting value like this:

        await codeEditor.SetValue(args.Json);
cwevers commented 3 months ago

Same here

leigh-pointer commented 3 months ago

@FLAMESpl try setting the value in AfterRender, then you can be pretty sure the interop is loaded.

FLAMESpl commented 3 months ago

It is assigned on button click after I stay on a page for few minutes.

burtonrodman commented 3 months ago

I am having same issue. In my situation, I am using a Blazor WebAssembly project and I have a page that I visit multiple times to edit the details of an item. If I use ConstructionOptions, the value is set on the first instantiation, but then remains the same in subsequent visits to the page -- even though I see the OnInitializedAsync and OnParametersSetAsync get called and I am getting the correct parameters, loading the data and updating the models -- The editor never gets re-initialized with the new value.

If I remove the Value from the ConstructionOptions and try to set it in OnAfterRenderAsync, I get the error (regardless of firstRender).

any suggestions would be appreciated.

burtonrodman commented 3 months ago

I was able to resolve the issue by setting Value to a single space in the ContructionOptions, and also handle OnDidInit to set the value via SetValue method after my data was loaded.

This seems like a bug on 2 points...