-
-
Notifications
You must be signed in to change notification settings - Fork 109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BUnit render component to string deadlocks when using in a Blazor context > 1.18.4 #1144
Comments
Yes please. I'd be very curious to see what is in the RenderFragment. You can also try the latest preview 1.22.xx. It attempts to solve the #1064 issue which may be related. |
@egil here you go: https://github.com/biohazard999/bunit-repro-1144 does not change with the latest preview. Double checked downgrade to 1.18.4 works as expected. |
Thanks. I'll try to take a look in the coming days. |
I think it is sort of out of scope, but it should also work without problems, so I want to understand what's going on because it could also affect others in test scenarios. That said, as part of net 8, the functionality you need will be built-in to the framework. Look for the blog post for preview 2 or 3 for details. |
Given you are on @ChildContent
@code {
[Parameter]
public RenderFragment ChildContent { get; set; } = default!;
} After that it's possible to workaround like so: ILoggerFactory loggerFactory = ServiceProvider.GetRequiredService<ILoggerFactory>();
await using var htmlRenderer = new HtmlRenderer(ServiceProvider, loggerFactory);
var markup = await htmlRenderer.Dispatcher.InvokeAsync(async () =>
{
var parameters = ParameterView.FromDictionary(new Dictionary<string, object?>
{
[nameof(MarkdownRenderer.ChildContent)] = ChildContent
});
var output = await htmlRenderer.RenderComponentAsync<MarkdownRenderer>(parameters);
return output.ToHtmlString();
});
markup = MarkdownStringUtils.TrimLeftSpaces(markup);
var html = Markdown.ToHtml(markup, Pipeline);
_markupString = new MarkupString(html); This should be a hint for other's how to workaround this problem. I will stick with Thanks @egil :) |
@biohazard999 can you try again with the 1.22.16-preview release and see if that solves the issue for you. |
@egil works 👏👏 |
Great. Still have a few other issues to solve before we make a none-preview release. |
I use BUnit to render a component to a string inside a blazor application to support rendering markdown.
Currently i'm using it somewhat like this:
All versions after 1.18.4 end in a deadlock rendering the component to html
I guess the crucket is here: 7c15692
I tried to wrap my code into a InvokeAsync etc but still get deadlocked (the render pipeline just never passes
Render(ChildContent)
).I know this is not the primary use case for bunit, and i am waiting for the native net8.0 implementation to render a component to a string from microsoft.
Are there any workarounds i could use?
I could provide a small repro if needed.
The text was updated successfully, but these errors were encountered: