-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Blazor] Add an API to describe the render mode (if any) a component …
…is running in (#55577)
- Loading branch information
Showing
16 changed files
with
252 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/Components/Components/src/RenderTree/ComponentPlatform.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/Components/test/E2ETest/Tests/InteractiveHostRendermodeTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...nents/test/testassets/Components.TestServer/RazorComponents/Pages/ComponentPlatform.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}"); | ||
} | ||
} | ||
} |
Oops, something went wrong.