Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/Components/Components/src/PublicAPI.Shipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,17 @@ Microsoft.AspNetCore.Components.PersistentComponentState.TryTakeFromJson<TValue>
Microsoft.AspNetCore.Components.PersistingComponentStateSubscription
Microsoft.AspNetCore.Components.PersistingComponentStateSubscription.Dispose() -> void
Microsoft.AspNetCore.Components.PersistingComponentStateSubscription.PersistingComponentStateSubscription() -> void
Microsoft.AspNetCore.Components.EnumRendererInfo
Microsoft.AspNetCore.Components.EnumRendererInfo.Static = 0 -> Microsoft.AspNetCore.Components.EnumRendererInfo
Microsoft.AspNetCore.Components.EnumRendererInfo.SSR = 1 -> Microsoft.AspNetCore.Components.EnumRendererInfo
Microsoft.AspNetCore.Components.EnumRendererInfo.Server = 2 -> Microsoft.AspNetCore.Components.EnumRendererInfo
Microsoft.AspNetCore.Components.EnumRendererInfo.WebAssembly = 3 -> Microsoft.AspNetCore.Components.EnumRendererInfo
Microsoft.AspNetCore.Components.EnumRendererInfo.WebView = 4 -> Microsoft.AspNetCore.Components.EnumRendererInfo
Microsoft.AspNetCore.Components.RendererInfo
Microsoft.AspNetCore.Components.RendererInfo.IsInteractive.get -> bool
Microsoft.AspNetCore.Components.RendererInfo.Name.get -> string!
Microsoft.AspNetCore.Components.RendererInfo.RendererInfo(string! rendererName, bool isInteractive) -> void
Microsoft.AspNetCore.Components.RendererInfo.RenderedType.get -> Microsoft.AspNetCore.Components.EnumRendererInfo
Microsoft.AspNetCore.Components.RendererInfo.RendererInfo(Microsoft.AspNetCore.Components.EnumRendererInfo rendererType, bool isInteractive) -> void
Microsoft.AspNetCore.Components.RenderFragment
Microsoft.AspNetCore.Components.RenderFragment<TValue>
Microsoft.AspNetCore.Components.RenderHandle
Expand Down
44 changes: 41 additions & 3 deletions src/Components/Components/src/RenderTree/RendererInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,55 @@ namespace Microsoft.AspNetCore.Components;
/// <summary>
/// Provides information about the platform that the component is running on.
/// </summary>
/// <param name="rendererName">The name of the platform.</param>
/// <param name="rendererType">The Type of the platform.</param>
/// <param name="isInteractive">A flag to indicate if the platform is interactive.</param>
public sealed class RendererInfo(string rendererName, bool isInteractive)
public sealed class RendererInfo(EnumRendererInfo rendererType, bool isInteractive)
{
/// <summary>
/// Gets the name of the platform.
/// </summary>
public string Name { get; } = rendererName;
[Obsolete("Name is deprecated. Use RenderedType instead.")]
public string Name => RenderedType.ToString();

/// <summary>
/// Gets the type of the Renderer.
/// </summary>
public EnumRendererInfo RenderedType => rendererType;

/// <summary>
/// Gets a flag to indicate if the platform is interactive.
/// </summary>
public bool IsInteractive { get; } = isInteractive;
}

/// <summary>
/// Defines the available rendering environments for Blazor components.
/// </summary>
public enum EnumRendererInfo
{
/// <summary>
/// The renderer outputs only static HTML without interactivity.
/// </summary>
Static,

/// <summary>
/// The renderer is executing during server-side prerendering (SSR).
/// </summary>
SSR,

/// <summary>
/// The renderer runs in interactive server mode, maintaining a live
/// SignalR connection between the browser and the server.
/// </summary>
Server,

/// <summary>
/// The renderer runs directly in the browser using WebAssembly.
/// </summary>
WebAssembly,

/// <summary>
/// The renderer runs inside a native WebView host (for example, .NET MAUI).
/// </summary>
WebView
}
2 changes: 1 addition & 1 deletion src/Components/Server/src/Circuits/RemoteRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal partial class RemoteRenderer : WebRenderer
#pragma warning restore CA1852 // Seal internal types
{
private static readonly Task CanceledTask = Task.FromCanceled(new CancellationToken(canceled: true));
private static readonly RendererInfo _componentPlatform = new("Server", isInteractive: true);
private static readonly RendererInfo _componentPlatform = new(EnumRendererInfo.Server, isInteractive: true);

private readonly CircuitClientProxy _client;
private readonly CircuitOptions _options;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Microsoft.AspNetCore.Components.HtmlRendering.Infrastructure;
/// </summary>
public partial class StaticHtmlRenderer : Renderer
{
private static readonly RendererInfo _componentPlatform = new RendererInfo("Static", isInteractive: false);
private static readonly RendererInfo _componentPlatform = new RendererInfo(EnumRendererInfo.Static, isInteractive: false);

private readonly NavigationManager? _navigationManager;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ internal sealed partial class WebAssemblyRenderer : WebRenderer
private readonly Dispatcher _dispatcher;
private readonly ResourceAssetCollection _resourceCollection;
private readonly IInternalJSImportMethods _jsMethods;
private static readonly RendererInfo _componentPlatform = new("WebAssembly", isInteractive: true);
private static readonly RendererInfo _componentPlatform = new(EnumRendererInfo.WebAssembly, isInteractive: true);

public WebAssemblyRenderer(IServiceProvider serviceProvider, ResourceAssetCollection resourceCollection, ILoggerFactory loggerFactory, JSComponentInterop jsComponentInterop)
: base(serviceProvider, loggerFactory, DefaultWebAssemblyJSRuntime.Instance.ReadJsonSerializerOptions(), jsComponentInterop)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Microsoft.AspNetCore.Components.WebView.Services;

internal sealed class WebViewRenderer : WebRenderer
{
private static readonly RendererInfo _componentPlatform = new("WebView", isInteractive: true);
private static readonly RendererInfo _componentPlatform = new(EnumRendererInfo.WebView, isInteractive: true);
private readonly Queue<UnacknowledgedRenderBatch> _unacknowledgedRenderBatches = new();
private readonly Dispatcher _dispatcher;
private readonly IpcSender _ipcSender;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ else

<p>
Platform:
<strong id="platform">@RendererInfo.Name</strong>
<strong id="platform">@RendererInfo.RenderedType</strong>
</p>

<hr />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
[PersistentState]
public int CustomValue { get; set; }

private string _renderMode = "SSR";
private EnumRendererInfo _renderMode = EnumRendererInfo.SSR;

protected override void OnInitialized()
{
Expand All @@ -24,6 +24,6 @@
{
CustomValue = !RendererInfo.IsInteractive ? 42 : 0;
}
_renderMode = OperatingSystem.IsBrowser() ? "WebAssembly" : "Server";
_renderMode = OperatingSystem.IsBrowser() ? EnumRendererInfo.WebAssembly : EnumRendererInfo.Server;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@

@code {

private string _renderMode = "";
private EnumRendererInfo _renderMode;

protected override void OnInitialized()
{
_renderMode = RendererInfo.Name;
_renderMode = RendererInfo.RenderedType;
if (!RendererInfo.IsInteractive)
{
InteractiveServerState.State = "Server state";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
@using Microsoft.AspNetCore.Components.Web;
@inject IJSRuntime JSRuntime

<p id="platform-name">@RendererInfo.Name</p>
<p id="platform-name">@RendererInfo.RenderedType</p>

<p id="basic-app-styles">@Assets["BasicTestApp.styles.css"]</p>

@if (!RendererInfo.IsInteractive)
{
<button id="import-module" onclick="import('./Index.mjs')">Import JS Module</button>
<button id="import-module" onclick="import('./Index.mjs')">Import JS Module</button>
}else
{
<button id="import-module" @onclick="ManualImport">Import JS Module</button>
Expand Down
Loading