Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Blazor] Add an API to describe the render mode (if any) a component is running in #55577

Merged
merged 12 commits into from
May 14, 2024
4 changes: 1 addition & 3 deletions src/Components/Components/src/ComponentBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,14 @@ public ComponentBase()
protected ComponentPlatform Platform => _renderHandle.Platform;

/// <summary>
/// Gets the target <see cref="IComponentRenderMode"/> this component will run in after prerendering.
/// Gets the <see cref="IComponentRenderMode"/> assigned to this component.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is to avoid implying we are currently prerendering, or that prerendering is even applicable (since on WebView or standalone WebAssembly it wouldn't be applicable as a concept).

/// </summary>
protected IComponentRenderMode? AssignedRenderMode
{
get
{
if (!_renderMode.cached)
{
// We use the platform render mode to avoid having to look up the render mode when the platform
// has a single render mode.
_renderMode = (_renderHandle.RenderMode, true);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Components/Components/src/RenderHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ public Dispatcher Dispatcher
public ComponentPlatform Platform => _renderer?.ComponentPlatform ?? throw new InvalidOperationException("No renderer has been initialized.");

/// <summary>
/// Retrieves the <see cref="IComponentRenderMode"/> of the component the component will run in after prerendering.
/// Retrieves the <see cref="IComponentRenderMode"/> assigned to the component.
/// </summary>
/// <returns>The <see cref="IComponentRenderMode"/> of the component the component will run in after prerendering.</returns>
/// <returns>The <see cref="IComponentRenderMode"/> assigned to the component.</returns>
public IComponentRenderMode? RenderMode
{
get
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
namespace Microsoft.AspNetCore.Components;

/// <summary>
/// Provide information about the platform that the component is running on.
/// Provides information about the platform that the component is running on.
/// </summary>
public sealed class ComponentPlatform
{
/// <summary>
/// Initialize a new instance of <see cref="ComponentPlatform"/>.
/// Constructs a new instance of <see cref="ComponentPlatform"/>.
/// </summary>
/// <param name="platformName">The name of the platform.</param>
/// <param name="isInteractive">A flag to indicate if the platform is interactive.</param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal sealed partial class WebAssemblyRenderer : WebRenderer
private readonly ILogger _logger;
private readonly Dispatcher _dispatcher;
private readonly IInternalJSImportMethods _jsMethods;
private static readonly ComponentPlatform _componentPlatform = new("Webassembly", isInteractive: true);
private static readonly ComponentPlatform _componentPlatform = new("WebAssembly", isInteractive: true);

public WebAssemblyRenderer(IServiceProvider serviceProvider, 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 ComponentPlatform _componentPlatform = new("Webview", isInteractive: true);
private static readonly ComponentPlatform _componentPlatform = new("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 @@ -26,7 +26,6 @@ public InteractiveHostRendermodeTest(
[InlineData("webassembly")]
[InlineData("auto")]
[InlineData("static")]

public void EmbeddingServerAppInsideIframe_Works(string renderMode)
{
Navigate($"/subdir/ComponentPlatform?suppress-autostart&ComponentRenderMode={renderMode}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
The component prints the render mode and whether its interactive.
</p>

<ComponentPlatformDetails @rendermode="_renderMode" />
<ComponentPlatformDetails @rendermode="_renderMode" />

@code {
[SupplyParameterFromQuery] public string ComponentRenderMode { get; set; }
Expand Down
Loading