Skip to content

Blazor: Preview9 made HtmlRenderer & ComponentRenderedText internal #13687

@chanan

Description

@chanan

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).

CC: @danroth27 @SteveSandersonMS @egil

Metadata

Metadata

Assignees

No one assigned

    Labels

    affected-fewThis issue impacts only small number of customersarea-blazorIncludes: Blazor, Razor ComponentsenhancementThis issue represents an ask for new feature or an enhancement to an existing onefeature-prerenderingIssues related to prerendering blazor componentsreevaluateWe need to reevaluate the issue and make a decision about itseverity-minorThis label is used by an internal tool

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions