Skip to content

Implementing RendererInfo with Enum #63315

@zandiarash

Description

@zandiarash

Summary

Since developers are already consuming RendererInfo in their applications, and writing code that depends on its properties, it would be beneficial to replace the current string-based platform identifier with a strongly typed enum. This improves type safety, discoverability, and consistency, while maintaining full source and binary compatibility.

The proposal introduces a new EnumRendererInfo enum and a RenderedType property on RendererInfo. The existing Name property remains available but is marked [Obsolete], and its value is derived from RenderedType. This approach provides a safe migration path while enabling developers to work with strongly typed renderer information.

I’d greatly appreciate your feedback on my PR. Please take a moment to review my PR-63316.

Motivation and goals

  • Type safety & discoverability: string rendererName is easy to make Speling mistak and hard to navigate. An enum offers IntelliSense, compile-time checks, and clearer semantics.
  • Easier refactoring: Enum values can be extended in a controlled way; callers can switch over known values reliably.
  • Consistency: Aligns with how render modes are typically discussed and reasoned about in docs and code.

In scope

No response

Out of scope

Nothing has been excluded, All related files are reformed by respect.

Risks / unknowns

Docs & guidance: Documentation need migration guidance to use RenderedType and the new ctor.

Examples

@page "/counter"
@rendermode InteractiveAuto

<PageTitle>Counter</PageTitle>

<h1>Counter</h1>
<h1>@RendererInfo.RenderedType</h1>
<p role="status">Current count: @currentCount</p>

<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>

@code {
    private int currentCount = 0;

    protected override Task OnAfterRenderAsync(bool firstRender)
    {
        switch (RendererInfo.RenderedType)
        {
            case EnumRendererInfo.Static:
                // Do something specific for InteractiveAuto
                break;
            case EnumRendererInfo.SSR:
                // Do something specific for SSR
                break;
            case EnumRendererInfo.Server:
                // Do something specific for Server
                break;
            case EnumRendererInfo.WebAssembly:
                // Do something specific for WebAssembly
                break;
            case EnumRendererInfo.WebView:
                // Do something specific for WebView
                break;
        }
        return base.OnAfterRenderAsync(firstRender);
    }
    private void IncrementCount()
    {
        currentCount++;
    }
}

Thanks @danroth27 for explaining about RendererInfo.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ✔️ Resolution: AnsweredResolved because the question asked by the original author has been answered.Status: Resolvedarea-blazorIncludes: Blazor, Razor Componentsdesign-proposalThis issue represents a design proposal for a different issue, linked in the descriptionquestion

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions