question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BUnit render component to string deadlocks when using in a Blazor context > 1.18.4

See original GitHub issue

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:

var context = new TestContext();

context.Services.AddFallbackServiceProvider(ServiceProvider);

var rendered = context.Render(ChildContent);
var markup = MarkdownStringUtils.TrimLeftSpaces(rendered.Markup);

var html = Markdown.ToHtml(markup, Pipeline);
_markupString = new MarkupString(html);

All versions after 1.18.4 end in a deadlock rendering the component to html

I guess the crucket is here: https://github.com/bUnit-dev/bUnit/commit/7c156921b5f78023ed435577d1baff6116d4d2f4

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.

Issue Analytics

  • State:closed
  • Created 2 months ago
  • Reactions:1
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
egilcommented, Jul 18, 2023

Great. Still have a few other issues to solve before we make a none-preview release.

1reaction
biohazard999commented, Jul 18, 2023

@egil works 👏👏

Read more comments on GitHub >

github_iconTop Results From Across the Web

Deadlock when using FindComponent(s) with WaitForX #577
FindComponents where it waits for TestRenderer.renderTreeAccessLock . Version info: bUnit version: 1.3.42 .NET Runtime and Blazor version: .NET ...
Read more >
Triggering a render life cycle on a component
With a IRenderedComponent<TComponent>, it is possible to cause the component to render again directly through the Render() method or one of the ...
Read more >
Controlling the root render tree
The root render tree, the render tree in which components under test are rendered, can be added to before components are rendered with...
Read more >
Passing parameters to components
There are two methods in bUnit that allow passing parameters in C#-based test code: RenderComponent method on the test context, which is used...
Read more >
Writing tests for Blazor components
Rendering a component happens through bUnit's TestContext. The result of the rendering is an IRenderedComponent , referred to as a "rendered component", that ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found