Open
Description
Two Libraries (that I know of) use HtmlRenderer & ComponentRenderedText prior to previw 9. One is BlazorStyled: https://github.com/chanan/BlazorStyled and the other is Egil's testing library: https://github.com/egil/razor-components-testing-library
Both use it for the same reason, to get the content of ChildContent. It was used like so:
private string RenderAsString()
{
string result = string.Empty;
try
{
ParameterView paramView = ParameterView.FromDictionary(new Dictionary<string, object>() { { "ChildContent", ChildContent } });
using HtmlRenderer htmlRenderer = new HtmlRenderer(_emptyServiceProvider, NullLoggerFactory.Instance, _encoder);
IEnumerable<string> tokens = GetResult(htmlRenderer.Dispatcher.InvokeAsync(() => htmlRenderer.RenderComponentAsync<TempComponent>(paramView)));
result = string.Join("", tokens.ToArray());
}
catch
{
//ignored dont crash if can't get result
}
return result;
}
private IEnumerable<string> GetResult(Task<ComponentRenderedText> task)
{
if (task.IsCompleted && task.Status == TaskStatus.RanToCompletion && !task.IsFaulted && !task.IsCanceled)
{
return task.Result.Tokens;
}
else
{
ExceptionDispatchInfo.Capture(task.Exception).Throw();
throw new InvalidOperationException("We will never hit this line");
}
}
However as of Preview9 that is no longer possible as HtmlRenderer & ComponentRenderedText are both internal - Please make them public (Or provide another way to get the content of ChildContent).
Metadata
Metadata
Assignees
Labels
This issue impacts only small number of customersIncludes: Blazor, Razor ComponentsThis issue represents an ask for new feature or an enhancement to an existing oneIssues related to prerendering blazor componentsWe need to reevaluate the issue and make a decision about itThis label is used by an internal tool