-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Add reconnect UI component to the Blazor template #60376
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
Merged
ilonatommy
merged 13 commits into
dotnet:main
from
oroztocil:bugfix/57453-blazor-reconnect-ui
Feb 18, 2025
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
34f8b63
Add prototype to sample app
oroztocil 84ba9ad
Add e2e test for the new reconnect UI
oroztocil a2391d4
Add E2E test for CSP violation
oroztocil ba714df
Add HTML attributes to ReconnectModal
oroztocil 8840fc8
Add ReconnectModal to the BlazorWeb-CSharp project template
oroztocil e967665
Add comments, simplify test component, clean up sample app
oroztocil 03a54f4
Add new project template files to template-baselines.json
oroztocil 34d85ca
Add missing cases to template-baselines.json
oroztocil 5ec46ab
Add HeadOutlet to TestServer app, use meta tag for setting CSP in rec…
oroztocil 9fd6ca3
Dispatch reconnection state change events in UserSpecifiedDisplay
oroztocil 51d1008
Fix code style
oroztocil 71d0efd
Add missing Add missing cases to template-baselines.json
oroztocil 25f93fa
Add missing cases to template-baselines.json
oroztocil File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
src/Components/Web.JS/src/Platform/Circuits/ReconnectStateChangedEvent.ts
This file contains hidden or 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,5 @@ | ||
export interface ReconnectStateChangedEvent { | ||
state: "show" | "hide" | "retrying" | "failed" | "rejected"; | ||
currentAttempt?: number; | ||
secondsToNextAttempt?: number; | ||
} |
This file contains hidden or 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
84 changes: 84 additions & 0 deletions
84
src/Components/test/E2ETest/ServerExecutionTests/ServerReconnectionCustomUITest.cs
This file contains hidden or 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,84 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using BasicTestApp.Reconnection; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure; | ||
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures; | ||
using Microsoft.AspNetCore.Components.E2ETest.ServerExecutionTests; | ||
using Microsoft.AspNetCore.E2ETesting; | ||
using Microsoft.AspNetCore.Hosting; | ||
using OpenQA.Selenium; | ||
using TestServer; | ||
using Xunit.Abstractions; | ||
|
||
namespace Microsoft.AspNetCore.Components.E2ETest.ServerExecutionTests; | ||
|
||
public class ServerReconnectionCustomUITest : ServerTestBase<BasicTestAppServerSiteFixture<ServerStartup>> | ||
{ | ||
public ServerReconnectionCustomUITest( | ||
BrowserFixture browserFixture, | ||
BasicTestAppServerSiteFixture<ServerStartup> serverFixture, | ||
ITestOutputHelper output) | ||
: base(browserFixture, serverFixture, output) | ||
{ | ||
} | ||
|
||
protected override void InitializeAsyncCore() | ||
{ | ||
/// Setting this query parameter causes <see cref="ReconnectionComponent"/> to include the custom reconnect dialog. | ||
Navigate($"{ServerPathBase}?useCustomReconnectModal=true"); | ||
Browser.MountTestComponent<ReconnectionComponent>(); | ||
Browser.Exists(By.Id("count")); | ||
} | ||
|
||
/// <summary> | ||
/// Tests that the custom reconnect is displayed when the server circuit is disconnected. | ||
/// This UI is provided statically by a Razor component instead being generated by the default | ||
/// JS fallback code (see 'DefaultReconnectDisplay.ts'). | ||
/// </summary> | ||
[Fact] | ||
public void ReconnectionUI_CustomDialog_IsDisplayed() | ||
{ | ||
Browser.Exists(By.Id("increment")).Click(); | ||
|
||
var js = (IJavaScriptExecutor)Browser; | ||
js.ExecuteScript("Blazor._internal.forceCloseConnection()"); | ||
|
||
// We should see the 'reconnecting' UI appear | ||
Browser.Equal("block", () => Browser.Exists(By.Id("components-reconnect-modal")).GetCssValue("display")); | ||
Browser.NotEqual(null, () => Browser.Exists(By.Id("components-reconnect-modal")).GetAttribute("open")); | ||
|
||
// The reconnect modal should not be a 'div' element created by the fallback JS code | ||
Browser.Equal("dialog", () => Browser.Exists(By.Id("components-reconnect-modal")).TagName); | ||
|
||
// Then it should disappear | ||
Browser.Equal("none", () => Browser.Exists(By.Id("components-reconnect-modal")).GetCssValue("display")); | ||
Browser.Equal(null, () => Browser.Exists(By.Id("components-reconnect-modal")).GetAttribute("open")); | ||
|
||
Browser.Exists(By.Id("increment")).Click(); | ||
|
||
// Can dispatch events after reconnect | ||
Browser.Equal("2", () => Browser.Exists(By.Id("count")).Text); | ||
} | ||
|
||
/// <summary> | ||
/// Tests that when the custom reconnect UI is used, there are no style-related CSP errors. | ||
/// </summary> | ||
[Fact] | ||
public void ReconnectionUI_WorksWith_StrictStyleCspPolicy() | ||
{ | ||
var js = (IJavaScriptExecutor)Browser; | ||
js.ExecuteScript("Blazor._internal.forceCloseConnection()"); | ||
|
||
// We should see the 'reconnecting' UI appear | ||
Browser.Equal("block", () => Browser.Exists(By.Id("components-reconnect-modal")).GetCssValue("display")); | ||
|
||
// Check that there is no CSP-related error in the browser console | ||
var cspErrorMessage = "violates the following Content Security Policy directive: \"style-src"; | ||
var logs = Browser.Manage().Logs.GetLog(LogType.Browser); | ||
var styleErrors = logs.Where(log => log.Message.Contains(cspErrorMessage)); | ||
|
||
Assert.Empty(styleErrors); | ||
} | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -28,3 +28,6 @@ | |
<span class="dismiss">🗙</span> | ||
</div> | ||
##endif*@ | ||
@*#if (UseServer) --> | ||
<ReconnectModal /> | ||
##endif*@ |
22 changes: 22 additions & 0 deletions
22
...emplates/content/BlazorWeb-CSharp/BlazorWeb-CSharp/Components/Layout/ReconnectModal.razor
This file contains hidden or 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,22 @@ | ||
<script type="module" src="@Assets["Layout/ReconnectModal.razor.js"]"></script> | ||
|
||
<dialog id="components-reconnect-modal" data-nosnippet> | ||
<div class="components-reconnect-container"> | ||
<div class="components-rejoining-animation" aria-hidden="true"> | ||
<div></div> | ||
<div></div> | ||
</div> | ||
<p class="components-reconnect-first-attempt-visible"> | ||
Rejoining the server... | ||
</p> | ||
<p class="components-reconnect-repeated-attempt-visible"> | ||
Rejoin failed... trying again in <span id="components-seconds-to-next-attempt"></span> seconds. | ||
</p> | ||
<p class="components-reconnect-failed-visible"> | ||
Failed to rejoin.<br />Please retry or reload the page. | ||
</p> | ||
<button id="components-reconnect-button" class="components-reconnect-failed-visible"> | ||
Retry | ||
</button> | ||
</div> | ||
</dialog> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.