MyNihongo / MudBlazor.Markdown

Markdown component based on the MudBlazor environment
https://mudblazor.com/
MIT License
136 stars 13 forks source link

Object reference when using MudBlazor 7.7.0 but not with 7.6.0 #273

Closed Mhaxym closed 1 month ago

Mhaxym commented 1 month ago

Overview

I saw that you already have a PR to support MudBlazor 7.0 but I was already using 7.6.0 and it was working fine just with

<MudMarkdown Value="@Page.Content" CodeBlockTheme="CodeBlockTheme.StackoverflowLight" />

After updating to MudBlazor last version (from three days ago) to test everything it started throwing Object reference randomly.

System.NullReferenceException: Object reference not set to an instance of an object.
   at MudBlazor.Utilities.CssBuilder.AddValue(String value)
   at MudBlazor.Utilities.CssBuilder.AddClass(String value)
   at MudBlazor.MudCodeHighlight.get_CodeClasses()
   at MudBlazor.MudCodeHighlight.BuildRenderTree(RenderTreeBuilder builder)
   at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment, Exception& renderFragmentException)
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessRenderQueue()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessRenderQueue()
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.AddToRenderQueue(Int32 componentId, RenderFragment renderFragment)
   at Microsoft.AspNetCore.Components.ComponentBase.StateHasChanged()
   at Microsoft.AspNetCore.Components.ComponentBase.CallOnParametersSetAsync()
   at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()
   at Microsoft.AspNetCore.Components.Rendering.ComponentState.SetDirectParameters(ParameterView parameters)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.RenderRootComponentAsync(Int32 componentId, ParameterView initialParameters)
   at Microsoft.AspNetCore.Components.HtmlRendering.Infrastructure.StaticHtmlRenderer.BeginRenderingComponent(IComponent component, ParameterView initialParameters)
   at Microsoft.AspNetCore.Components.Endpoints.EndpointHtmlRenderer.RenderEndpointComponent(HttpContext httpContext, Type rootComponentType, ParameterView parameters, Boolean waitForQuiescence)
   at Microsoft.AspNetCore.Components.Endpoints.RazorComponentEndpointInvoker.RenderComponentCore(HttpContext context)
   at Microsoft.AspNetCore.Components.Endpoints.RazorComponentEndpointInvoker.RenderComponentCore(HttpContext context)
   at Microsoft.AspNetCore.Components.Rendering.RendererSynchronizationContext.<>c.<<InvokeAsync>b__10_0>d.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)

To reproduce it just create a project with MudBlazor 7.7.0 and try to use the component.

my-nihongo commented 1 month ago

Thank you for your comment. We will make sure to update the NuGet version to the latest version and fix the bug (+ unit tests). We plan to do it tomorrow 😄

MihailsKuzmins commented 1 month ago

@Mhaxym could you please install MudBlazor.Markdown v7.8.0 and verify that it is all right. I cannot reproduce the null ref exception in my sample and the codeblock is rendered successfully.

image

@page "/"
@using System.Text

<PageTitle>Index</PageTitle>

<MudText Typo="Typo.h3">My markdown</MudText>
<MudMarkdown Value="@Value" CodeBlockTheme="CodeBlockTheme.StackoverflowLight"/>

@code
{
    private string Value { get; } = new StringBuilder("text *italics* and bold and this is a [link](https://www.mynihongo.org)")
        .AppendLine()
        .AppendLine()
        .AppendLine("cs")
        .AppendLine("var a = a;")
        .AppendLine("")
        .ToString();

    private void OnLinkClicked(string url)
    {
        Console.Write($"aaaa: {url}");
    }
}
Mhaxym commented 1 month ago

Hello! Thank you for your quick revision.

It's working fine with the latest version of MudBlazor.Markdown.

GJ :rocket: