-
Notifications
You must be signed in to change notification settings - Fork 10k
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
Changes from all commits
1cd685b
448869e
1f21391
066a250
06d1e47
c637de2
1017c33
4a2bdba
fd57940
397d779
8e8cad0
8eabd02
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,12 @@ | ||
#nullable enable | ||
Microsoft.AspNetCore.Components.ComponentBase.AssignedRenderMode.get -> Microsoft.AspNetCore.Components.IComponentRenderMode? | ||
Microsoft.AspNetCore.Components.ComponentBase.Platform.get -> Microsoft.AspNetCore.Components.ComponentPlatform! | ||
Microsoft.AspNetCore.Components.ComponentPlatform | ||
Microsoft.AspNetCore.Components.ComponentPlatform.ComponentPlatform(string! platformName, bool isInteractive) -> void | ||
Microsoft.AspNetCore.Components.ComponentPlatform.IsInteractive.get -> bool | ||
Microsoft.AspNetCore.Components.ComponentPlatform.Name.get -> string! | ||
Microsoft.AspNetCore.Components.ExcludeFromInteractiveRoutingAttribute | ||
Microsoft.AspNetCore.Components.ExcludeFromInteractiveRoutingAttribute.ExcludeFromInteractiveRoutingAttribute() -> void | ||
Microsoft.AspNetCore.Components.RenderHandle.Platform.get -> Microsoft.AspNetCore.Components.ComponentPlatform! | ||
Microsoft.AspNetCore.Components.RenderHandle.RenderMode.get -> Microsoft.AspNetCore.Components.IComponentRenderMode? | ||
virtual Microsoft.AspNetCore.Components.RenderTree.Renderer.ComponentPlatform.get -> Microsoft.AspNetCore.Components.ComponentPlatform! |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace Microsoft.AspNetCore.Components; | ||
|
||
/// <summary> | ||
/// Provides information about the platform that the component is running on. | ||
/// </summary> | ||
public sealed class ComponentPlatform | ||
{ | ||
/// <summary> | ||
/// 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> | ||
public ComponentPlatform(string platformName, bool isInteractive) | ||
{ | ||
Name = platformName; | ||
IsInteractive = isInteractive; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the name of the platform. | ||
/// </summary> | ||
public string Name { get; } | ||
|
||
/// <summary> | ||
/// Gets a flag to indicate if the platform is interactive. | ||
/// </summary> | ||
public bool IsInteractive { get; } | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,8 +20,8 @@ public GridScenario() : base("grid") | |
protected override async Task ExecuteAsync(ConsoleHostRenderer renderer, int numCycles) | ||
{ | ||
var gridType = _gridTypeOption.HasValue() | ||
? (GridRendering.RenderMode)Enum.Parse(typeof(GridRendering.RenderMode), _gridTypeOption.Value(), true) | ||
: GridRendering.RenderMode.FastGrid; | ||
? (GridRendering.GridRenderMode)Enum.Parse(typeof(GridRendering.GridRenderMode), _gridTypeOption.Value(), true) | ||
: GridRendering.GridRenderMode.FastGrid; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suppose this shows it's a breaking change in a super niche sense, but we have to accept that otherwise we couldn't extend the base class at all. If there's a lot of pushback in previews we can consider options. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we decided to go with |
||
|
||
for (var i = 0; i < numCycles; i++) | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Components.TestServer.RazorComponents; | ||
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure; | ||
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures; | ||
using Microsoft.AspNetCore.E2ETesting; | ||
using OpenQA.Selenium; | ||
using TestServer; | ||
using Xunit.Abstractions; | ||
|
||
namespace Microsoft.AspNetCore.Components.E2ETests.Tests; | ||
|
||
public class InteractiveHostRendermodeTest : ServerTestBase<BasicTestAppServerSiteFixture<RazorComponentEndpointsStartup<App>>> | ||
{ | ||
public InteractiveHostRendermodeTest( | ||
BrowserFixture browserFixture, | ||
BasicTestAppServerSiteFixture<RazorComponentEndpointsStartup<App>> serverFixture, | ||
ITestOutputHelper output) | ||
: base(browserFixture, serverFixture, output) | ||
{ | ||
} | ||
|
||
[Theory] | ||
[InlineData("server")] | ||
[InlineData("webassembly")] | ||
[InlineData("auto")] | ||
[InlineData("static")] | ||
public void EmbeddingServerAppInsideIframe_Works(string renderMode) | ||
{ | ||
Navigate($"/subdir/ComponentPlatform?suppress-autostart&ComponentRenderMode={renderMode}"); | ||
|
||
Browser.Equal(renderMode, () => Browser.Exists(By.Id("host-render-mode")).Text); | ||
Browser.Equal("False", () => Browser.Exists(By.Id("platform-is-interactive")).Text); | ||
|
||
Browser.Click(By.Id("call-blazor-start")); | ||
|
||
if (renderMode == "static") | ||
{ | ||
Browser.Equal("False", () => Browser.Exists(By.Id("platform-is-interactive")).Text); | ||
} | ||
else | ||
{ | ||
Browser.Equal("True", () => Browser.Exists(By.Id("platform-is-interactive")).Text); | ||
} | ||
|
||
if (renderMode != "auto") | ||
{ | ||
Browser.Equal(renderMode, () => Browser.Exists(By.Id("host-render-mode")).Text); | ||
} | ||
else | ||
{ | ||
Browser.True(() => Browser.Exists(By.Id("host-render-mode")).Text is "server" or "webassembly"); | ||
} | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
@page "/componentplatform" | ||
@using TestContentPackage | ||
|
||
<h3>Component platform tests</h3> | ||
|
||
<p> | ||
Defines a component and applies the render mode in the query string value for ComponentRenderMode. | ||
The component prints the render mode and whether its interactive. | ||
</p> | ||
|
||
<ComponentPlatformDetails @rendermode="_renderMode" /> | ||
|
||
@code { | ||
[SupplyParameterFromQuery] public string ComponentRenderMode { get; set; } | ||
|
||
IComponentRenderMode _renderMode; | ||
|
||
protected override void OnInitialized() | ||
{ | ||
switch (ComponentRenderMode) | ||
{ | ||
case "server": | ||
_renderMode = RenderMode.InteractiveServer; | ||
break; | ||
case "webassembly": | ||
_renderMode = RenderMode.InteractiveWebAssembly; | ||
break; | ||
case "auto": | ||
_renderMode = RenderMode.InteractiveAuto; | ||
break; | ||
case "static": | ||
_renderMode = null; | ||
break; | ||
default: | ||
throw new InvalidOperationException($"Unknown component render mode: {ComponentRenderMode}"); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
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).