-
Several issues are related to Describe the bug Example: using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Rendering;
namespace ClassLibrary1;
public class ComponentWithAsyncSetParameters : ComponentBase
{
public override async Task SetParametersAsync(ParameterView parameters)
{
await Task.Delay(1000);
}
protected override void BuildRenderTree(RenderTreeBuilder builder)
{
builder.OpenElement(1, "h1");
builder.AddContent(2, "HEADER TEXT");
builder.CloseElement();
}
}
public class ComponentWithoutAsyncSetParameters : ComponentBase
{
public override Task SetParametersAsync(ParameterView parameters)
{
return Task.CompletedTask;
}
protected override void BuildRenderTree(RenderTreeBuilder builder)
{
builder.OpenElement(1, "h1");
builder.AddContent(2, "HEADER TEXT");
builder.CloseElement();
}
}
public class ComponentWithoutSetParameters : ComponentBase
{
protected override void BuildRenderTree(RenderTreeBuilder builder)
{
builder.OpenElement(1, "h1");
builder.AddContent(2, "HEADER TEXT");
builder.CloseElement();
}
} With this test: using Bunit;
using ClassLibrary1;
namespace TestProject1;
public sealed class UnitTest1 : TestContext
{
[Fact]
public void TestComponentWithAsyncSetParameters()
{
const string expected = "<h1>HEADER TEXT</h1>";
var component = RenderComponent<ComponentWithAsyncSetParameters>();
component.MarkupMatches(expected);
}
[Fact]
public void TestComponentWithoutAsyncSetParameters()
{
const string expected = "<h1>HEADER TEXT</h1>";
var component = RenderComponent<ComponentWithoutAsyncSetParameters>();
component.MarkupMatches(expected);
}
[Fact]
public void TestComponentWithoutSetParameters()
{
const string expected = "<h1>HEADER TEXT</h1>";
var component = RenderComponent<ComponentWithoutSetParameters>();
component.MarkupMatches(expected);
}
}
Expected behavior: Version info:
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
Hey @mku-vesca, maybe we can talk through examples of why certain things are happening. The easiest is The While your render-tree might not need any parameter, Blazor anyways enters your The normal way to do it would be taking: But even if you would do that, let's come to your second example: In your second example, you are overriding The default implementation has a bit logic, therefore If you are not calling I would assume, that such a component will not be rendered in Blazor as well. Because bUnit doesn't do anything special here. So it boils down to: When overriding |
Beta Was this translation helpful? Give feedback.
-
@linkdotnet, thank you for the precise instructions. By adding Looking at the call stack, it looks like the component lifecycle methods are being invoked, so maybe it corrupts the state of
public class ComponentWithAsyncSetParameters : ComponentBase
{
public override async Task SetParametersAsync(ParameterView parameters)
{
await Task.Delay(1000);
await base.SetParametersAsync(parameters);
}
protected override void BuildRenderTree(RenderTreeBuilder builder)
{
builder.OpenElement(1, "h1");
builder.AddContent(2, "HEADER TEXT");
builder.CloseElement();
}
} [Fact]
public void TestComponentWithAsyncSetParameters()
{
const string expected = "<h1>HEADER TEXT</h1>";
var component = RenderComponent<ComponentWithAsyncSetParameters>();
component.WaitForElement("h1");
component.MarkupMatches(expected);
} |
Beta Was this translation helpful? Give feedback.
-
That seems to be an internal issue of Blazor itself, which leads to an error. If it is fine with you, I will convert this into a discussion. |
Beta Was this translation helpful? Give feedback.
It seems like you are correct and Blazor does not like it.. Then it means that I need to come up with a new design for how values are processed (extract async logic from the SetParametersAsync).