-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Description
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 makeSpeling mistakand hard to navigate. Anenum
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
.