MudBlazor.Markdown icon indicating copy to clipboard operation
MudBlazor.Markdown copied to clipboard

Deleting end $ from a LaTex equation crashes the application

Open shirkrm opened this issue 4 months ago • 1 comments

MudMarkdown Version: 8.11.0

Description

When using MudMarkdown, deleting a parsed, formatted LaTeX equation throws an uncatchable exception.

Microsoft.AspNetCore.Components.Server.Circuits.RemoteRenderer: Warning: Unhandled exception rendering component: TypeError: can't access property "removeChild", o.parentNode is null

System.InvalidOperationException: TypeError: can't access property "removeChild", o.parentNode is null
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.InvokeRenderCompletedCallsAfterUpdateDisplayTask(Task updateDisplayTask, Int32[] updatedComponents)
Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost: Error: Unhandled exception in circuit 'fpI9GpFEy2sK9PSU5PaiPyWCoKrRJTZuLWzzEptgi8M'.

System.AggregateException: One or more errors occurred. (TypeError: can't access property "removeChild", o.parentNode is null)
 ---> System.InvalidOperationException: TypeError: can't access property "removeChild", o.parentNode is null
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.InvokeRenderCompletedCallsAfterUpdateDisplayTask(Task updateDisplayTask, Int32[] updatedComponents)
   --- End of inner exception stack trace ---

Steps

  1. Create a simple Blazor web app using MudBlazor and MudMarkdown using InteractiveRenderMode.Server applied globally.

  2. Put the following into Home.razor.

<MudTextField @bind-Value="TextValue" Immediate/>
<MudMarkdown Value="@TextValue"/>

@code{
    private string TextValue { get; set; } = string.Empty;
}
  1. Run the app. Type $$x+y$$ and wait until it parses and displays the LaTeX equation.
  2. Delete the last $
  3. Application crashes.

Expected Result

Application to not crash when LaTeX equation is modified.

Workarounds

Deleting the entire LaTeX equation appears to work, but this is not acceptable for our use case.

Additional Comments

I don't know if this is caused by MudBlazor.Markdown or the underlying Markdig library. While reproducing this, I also noticed that a parsed LaTeX equation can't be modified. I'm hoping that whatever fixes the root cause of this issue will also address that.

shirkrm avatar Aug 11 '25 13:08 shirkrm

For now I cannot offer a solution to this problem (unless math jax is rewritten without JS dependencies), but I will keep the issue open. It is a plan of the 【no JS】 series, but I do not know when I will do it.

The issue is related to the fact that Blazor is trying to remove the previously rendered math jax element that has been modified by the javascript code, so blazor cannot find it and fails (if you enter just $$x+y$ it will work without any issues).

MihailsKuzmins avatar Aug 16 '25 04:08 MihailsKuzmins