havit / Havit.Blazor

Free Bootstrap 5 components for ASP.NET Blazor + optional enterprise-level stack for Blazor development (gRPC code-first, layered architecture, localization, auth, ...)
https://havit.blazor.eu
MIT License
463 stars 63 forks source link

[HxToast] Crash during render tree build when using a high-contrast ThemeColor #816

Closed jolaquai closed 1 month ago

jolaquai commented 1 month ago

Title. Repo link with minimal sample that reproduces the issue can be found here: jolaquai/HxToastDangerMessageProblem

While I have no idea about the nitty-gritty of Blazor or Component development, wading through the Blazor and Havit.Blazor sources showed that the exception comes from Havit.Blazor.Components.Web.Bootstrap.HxToast.BuildRenderTree(RenderTreeBuilder) because for ThemeColor.Danger, HasContrastColor() returns true.

This causes BuildRenderTree(RenderTreeBuilder) to attempt to write data-bs-theme="dark" into the "last non-attribute frame" (which is currently a RenderTreeFrameType.Region), which obviously fails Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder.AssertCanAddAttribute().

hakenr commented 1 month ago

@crdo Fixed the crash, but probably needs some more work on visual result: image

hakenr commented 1 month ago

@jolaquai Thanks for reporting the issue. We were able to reproduce the crash and will fix it for the next release.