I want to use a editable div in Blazor to mix plain text and some html-elements like
But when I change the content and leave the div I get an InvalidOperationException.
This only occurs when I use a custom Tag like Microsoft.AspNetCore.Components.Server.Circuits.RemoteRenderer: Warning: Unhandled exception rendering component: TypeError: Cannot read property 'ownerDocument' of null Here is a simple example to reproduce this issue: ``` @code { } //this is the content of the Test.razor. the x is a sample content @code { }
System.InvalidOperationException: TypeError: Cannot read property 'ownerDocument' of null
at Microsoft.AspNetCore.Components.RenderTree.Renderer.InvokeRenderCompletedCallsAfterUpdateDisplayTask(Task updateDisplayTask, Int32[] updatedComponents)
Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost: Error: Unhandled exception in circuit 'NnPSnUvIn1Wh1tNJYULIQVe_UmVkJcyxD7Aj5x80qV8'.
System.AggregateException: One or more errors occurred. (TypeError: Cannot read property 'ownerDocument' of null)
---> System.InvalidOperationException: TypeError: Cannot read property 'ownerDocument' of null
at Microsoft.AspNetCore.Components.RenderTree.Renderer.InvokeRenderCompletedCallsAfterUpdateDisplayTask(Task updateDisplayTask, Int32[] updatedComponents)
--- End of inner exception stack trace ---
The thread 0x14ff8 has exited with code 0 (0x0).private MyClass _part;
protected override async Task OnInitializedAsync()
{
_part = new MyClass();
}
private async void OnBlur(FocusEventArgs args)
{
}
public class MyClass
{
public string Id { get; set; }
}
x[Parameter]
public Index.MyClass MyParam { get; set; }
I can't even get onblur to fire or the handler to be entered atm myself...
<td @ondblclick=(...) @onblur=(...)> fires the ondblclick event and handles it fine, but the handler for the onblur never even gets entered... May or may not be related...
Using the stable version of .NET Core 3.1 btw.
@TobiasKoller I created a repro using the code samples that you provided above. I was not able to reproduce the InvalidOperationException and the handler is executed correctly.
I can't even get onblur to fire or the handler to be entered atm myself...
Can you open another issue for this with a repro project? Thanks!
I have since resolved my issue with this. It was me, not the framework. My bad. Thanks though!
I'll go ahead and close this for now. It looks like onblur events on contenteditable divs are generally working from a quick app I spun up.
If you are able to provide a full app as a repro, please reopen the issue. Thanks!
Please reopen this bugreport.
Here is a very simple working example of this issue:
- Unzip the project
- Build the project
- Run the project in debug mode
- Delete all the text inside the editable div
- you will get an exception when you leave the editable div.
```
System.InvalidOperationException: TypeError: Cannot read property 'ownerDocument' of null
at Microsoft.AspNetCore.Components.RenderTree.Renderer.InvokeRenderCompletedCallsAfterUpdateDisplayTask(Task updateDisplayTask, Int32[] updatedComponents)
Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost: Error: Unhandled exception in circuit 'Swbo9SZWGvWPlPskMIny6in-bSXy_1d1IWmLChbf9KY'.System.AggregateException: One or more errors occurred. (TypeError: Cannot read property 'ownerDocument' of null)
---> System.InvalidOperationException: TypeError: Cannot read property 'ownerDocument' of null
at Microsoft.AspNetCore.Components.RenderTree.Renderer.InvokeRenderCompletedCallsAfterUpdateDisplayTask(Task updateDisplayTask, Int32[] updatedComponents)
--- End of inner exception stack trace ---
The thread 0x14d30 has exited with code 0 (0x0).
The thread 0x19a08 has exited with code 0 (0x0).
Microsoft.AspNetCore.Components.Server.Circuits.RemoteRenderer: Warning: Unhandled exception rendering component: TypeError: Cannot read property 'ownerDocument' of nullSystem.InvalidOperationException: TypeError: Cannot read property 'ownerDocument' of null
at Microsoft.AspNetCore.Components.RenderTree.Renderer.InvokeRenderCompletedCallsAfterUpdateDisplayTask(Task updateDisplayTask, Int32[] updatedComponents)
Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost: Error: Unhandled exception in circuit 'QG3dCgY6YbpBtMOfMZD-RFf8NkIGGr5rU_LW0_mWXRw'.System.AggregateException: One or more errors occurred. (TypeError: Cannot read property ownerDocument' of null)
---> System.InvalidOperationException: TypeError: Cannot read property 'ownerDocument' of null
at Microsoft.AspNetCore.Components.RenderTree.Renderer.InvokeRenderCompletedCallsAfterUpdateDisplayTask(Task updateDisplayTask, Int32[] updatedComponents)
--- End of inner exception stack trace ---
The thread 0x13158 has exited with code 0 (0x0).
The thread 0x148b0 has exited with code 0 (0x0).
The thread 0x19f50 has exited with code 0 (0x0).
The program '[104844] iisexpress.exe' has exited with code -1 (0xffffffff).`
- Delete all the text inside the editable div
- you will get an exception when you leave the editable div.
As it turns out, "Delete all the text inside the editable div" is the important distinction here. The issue does not happen when you trigger an onblur on an content-editable div with content in it.
When the content is cleared from the div, there are no DOM elements and the
updateComponentmethod throws when applying the latest updates. I think it is sensible to add some better error-handling against null values in that function.Potentially relevant: https://github.com/dotnet/aspnetcore/issues/21241
Was this page helpful?0 / 5 - 0 ratingsRelated issues
farhadibehnam 路 3Comments
ermithun 路 3Comments
ipinak 路 3Comments
Kevenvz 路 3Comments
UweKeim 路 3Comments
Most helpful comment
I have since resolved my issue with this. It was me, not the framework. My bad. Thanks though!