forked from qodo-benchmark/aspnetcore
-
Notifications
You must be signed in to change notification settings - Fork 0
Improve Blazor reconnection experience after the server is restarted #8
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
Open
tomerqodo
wants to merge
7
commits into
coderabbit_only-issues-20260113-coderabbit_base_improve_blazor_reconnection_experience_after_the_server_is_restarted_pr32
Choose a base branch
from
coderabbit_only-issues-20260113-coderabbit_head_improve_blazor_reconnection_experience_after_the_server_is_restarted_pr32
base: coderabbit_only-issues-20260113-coderabbit_base_improve_blazor_reconnection_experience_after_the_server_is_restarted_pr32
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9bb74ec
Improve Blazor reconnection experience after server restart
oroztocil 4c73ee2
Update CannotResumeAppWhenPersistedComponentStateIsNotAvailable to re…
oroztocil 7426bc6
Revert a minor UI change
oroztocil 23e2f32
Add E2E tests to check reconnection behavior without server state
oroztocil 5c5681f
Fix typos
oroztocil 84ba1b8
Add missing hiding of buttons in DefaultReconnectDisplay
oroztocil f287efa
Apply changes for benchmark PR
tomerqodo 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
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
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
168 changes: 168 additions & 0 deletions
168
src/Components/test/E2ETest/ServerExecutionTests/ServerReconnectionWithoutStateTest.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,168 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Text; | ||
| using Components.TestServer.RazorComponents; | ||
| using Microsoft.AspNetCore.Components.E2ETest; | ||
| using Microsoft.AspNetCore.Components.E2ETest.Infrastructure; | ||
| using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures; | ||
| using Microsoft.AspNetCore.Components.E2ETest.ServerExecutionTests; | ||
| using Microsoft.AspNetCore.E2ETesting; | ||
| using OpenQA.Selenium; | ||
| using OpenQA.Selenium.BiDi.Communication; | ||
| using OpenQA.Selenium.DevTools; | ||
| using TestServer; | ||
| using Xunit.Abstractions; | ||
|
|
||
| namespace Microsoft.AspNetCore.Components.E2ETests.ServerExecutionTests; | ||
|
|
||
| public class ServerReconnectionWithoutStateTest : ServerTestBase<BasicTestAppServerSiteFixture<RazorComponentEndpointsStartup<Root>>> | ||
| { | ||
| public ServerReconnectionWithoutStateTest( | ||
| BrowserFixture browserFixture, | ||
| BasicTestAppServerSiteFixture<RazorComponentEndpointsStartup<Root>> serverFixture, | ||
| ITestOutputHelper output) | ||
| : base(browserFixture, serverFixture, output) | ||
| { | ||
| serverFixture.AdditionalArguments.AddRange("--DisableReconnectionCache", "true"); | ||
| serverFixture.AdditionalArguments.AddRange("--DisableCircuitPersistence", "true"); | ||
| } | ||
|
|
||
| protected override void InitializeAsyncCore() | ||
| { | ||
| Navigate(TestUrl); | ||
| Browser.Exists(By.Id("render-mode-interactive")); | ||
| } | ||
|
|
||
| public string TestUrl { get; set; } = "/subdir/persistent-state/disconnection"; | ||
|
|
||
| public bool UseShadowRoot { get; set; } = true; | ||
|
|
||
| [Fact] | ||
| public void ReloadsPage_AfterDisconnection_WithoutServerState() | ||
| { | ||
| // Check interactivity | ||
| Browser.Equal("5", () => Browser.Exists(By.Id("non-persisted-counter")).Text); | ||
| Browser.Exists(By.Id("increment-non-persisted-counter")).Click(); | ||
| Browser.Equal("6", () => Browser.Exists(By.Id("non-persisted-counter")).Text); | ||
|
|
||
| // Store a reference to an element to detect page reload | ||
| // When the page reloads, this element reference will become stale | ||
| var initialElement = Browser.Exists(By.Id("non-persisted-counter")); | ||
| var initialConnectedLogCount = GetConnectedLogCount(); | ||
|
|
||
| // Force close the connection | ||
| // The client should get rejected on both reconnection and circuit resume because the server has no state | ||
| var javascript = (IJavaScriptExecutor)Browser; | ||
| javascript.ExecuteScript("Blazor._internal.forceCloseConnection()"); | ||
|
|
||
| // Check for page reload using multiple conditions: | ||
| // 1. Previously captured element is stale | ||
| Browser.True(initialElement.IsStale); | ||
| // 2. Counter state is reset | ||
| Browser.Equal("5", () => Browser.Exists(By.Id("non-persisted-counter")).Text); | ||
| // 3. WebSocket connection has been re-established | ||
| Browser.True(() => GetConnectedLogCount() == initialConnectedLogCount + 1); | ||
|
|
||
| int GetConnectedLogCount() => Browser.Manage().Logs.GetLog(LogType.Browser) | ||
| .Where(l => l.Level == LogLevel.Info && l.Message.Contains("Information: WebSocket connected")).Count(); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void CanResume_AfterClientPause_WithoutServerState() | ||
| { | ||
| // Initial state: NonPersistedCounter should be 5 | ||
| Browser.Equal("5", () => Browser.Exists(By.Id("non-persisted-counter")).Text); | ||
|
|
||
| // Increment both counters | ||
| Browser.Exists(By.Id("increment-persistent-counter-count")).Click(); | ||
| Browser.Exists(By.Id("increment-non-persisted-counter")).Click(); | ||
|
|
||
| Browser.Equal("1", () => Browser.Exists(By.Id("persistent-counter-count")).Text); | ||
| Browser.Equal("6", () => Browser.Exists(By.Id("non-persisted-counter")).Text); | ||
|
|
||
| var javascript = (IJavaScriptExecutor)Browser; | ||
| TriggerClientPauseAndInteract(javascript); | ||
|
|
||
| // After first reconnection: | ||
| Browser.Equal("2", () => Browser.Exists(By.Id("persistent-counter-count")).Text); | ||
| Browser.Equal("0", () => Browser.Exists(By.Id("non-persisted-counter")).Text); | ||
|
|
||
| // Increment non-persisted counter again | ||
| Browser.Exists(By.Id("increment-non-persisted-counter")).Click(); | ||
| Browser.Equal("1", () => Browser.Exists(By.Id("non-persisted-counter")).Text); | ||
|
|
||
| TriggerClientPauseAndInteract(javascript); | ||
|
|
||
| // After second reconnection: | ||
| Browser.Equal("3", () => Browser.Exists(By.Id("persistent-counter-count")).Text); | ||
| Browser.Equal("0", () => Browser.Exists(By.Id("non-persisted-counter")).Text); | ||
| } | ||
|
|
||
| private void TriggerClientPauseAndInteract(IJavaScriptExecutor javascript) | ||
| { | ||
| var previousText = Browser.Exists(By.Id("persistent-counter-render")).Text; | ||
| javascript.ExecuteScript("Blazor.pauseCircuit()"); | ||
| Browser.Equal("block", () => Browser.Exists(By.Id("components-reconnect-modal")).GetCssValue("display")); | ||
|
|
||
| // Retry button should be hidden | ||
| Browser.Equal( | ||
| (false, true), | ||
| () => Browser.Exists( | ||
| () => | ||
| { | ||
| var buttons = UseShadowRoot ? | ||
| Browser.Exists(By.Id("components-reconnect-modal")) | ||
| .GetShadowRoot() | ||
| .FindElements(By.CssSelector(".components-reconnect-dialog button")) : | ||
| Browser.Exists(By.Id("components-reconnect-modal")) | ||
| .FindElements(By.CssSelector(".components-reconnect-container button")); | ||
|
|
||
| Assert.Equal(2, buttons.Count); | ||
| return (buttons[0].Displayed, buttons[1].Displayed); | ||
| }, | ||
| TimeSpan.FromSeconds(1))); | ||
|
|
||
| Browser.Exists( | ||
| () => | ||
| { | ||
| var buttons = UseShadowRoot ? | ||
| Browser.Exists(By.Id("components-reconnect-modal")) | ||
| .GetShadowRoot() | ||
| .FindElements(By.CssSelector(".components-reconnect-dialog button")) : | ||
| Browser.Exists(By.Id("components-reconnect-modal")) | ||
| .FindElements(By.CssSelector(".components-reconnect-container button")); | ||
| return buttons[1]; | ||
| }, | ||
| TimeSpan.FromSeconds(1)).Click(); | ||
|
|
||
| // Then it should disappear | ||
| Browser.Equal("none", () => Browser.Exists(By.Id("components-reconnect-modal")).GetCssValue("display")); | ||
|
|
||
| var newText = Browser.Exists(By.Id("persistent-counter-render")).Text; | ||
| Assert.NotEqual(previousText, newText); | ||
|
|
||
| Browser.Exists(By.Id("increment-persistent-counter-count")).Click(); | ||
| } | ||
| } | ||
|
|
||
| public class ServerReconnectionWithoutStateCustomUITest : ServerReconnectionWithoutStateTest | ||
| { | ||
| public ServerReconnectionWithoutStateCustomUITest( | ||
| BrowserFixture browserFixture, | ||
| BasicTestAppServerSiteFixture<RazorComponentEndpointsStartup<Root>> serverFixture, | ||
| ITestOutputHelper output) | ||
| : base(browserFixture, serverFixture, output) | ||
| { | ||
| TestUrl = "/subdir/persistent-state/disconnection?custom-reconnect-ui=true"; | ||
| UseShadowRoot = false; // Custom UI does not use shadow DOM | ||
| } | ||
|
|
||
| protected override void InitializeAsyncCore() | ||
| { | ||
| base.InitializeAsyncCore(); | ||
| Browser.Exists(By.CssSelector("#components-reconnect-modal[data-nosnippet]")); | ||
| } | ||
| } | ||
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
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.
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.
🧩 Analysis chain
🏁 Script executed:
Repository: qodo-benchmark/aspnetcore-combined-coderabbit
Length of output: 1836
🏁 Script executed:
Repository: qodo-benchmark/aspnetcore-combined-coderabbit
Length of output: 5699
🏁 Script executed:
Repository: qodo-benchmark/aspnetcore-combined-coderabbit
Length of output: 3292
🏁 Script executed:
rg "static.*IsStale|extension.*IsStale" --type cs -B 2 -A 5Repository: qodo-benchmark/aspnetcore-combined-coderabbit
Length of output: 929
🏁 Script executed:
Repository: qodo-benchmark/aspnetcore-combined-coderabbit
Length of output: 2112
🏁 Script executed:
fd "Browser.cs" --type fRepository: qodo-benchmark/aspnetcore-combined-coderabbit
Length of output: 71
🏁 Script executed:
fd "BrowserWait.cs|BrowserExtensions.cs" --type fRepository: qodo-benchmark/aspnetcore-combined-coderabbit
Length of output: 149
🏁 Script executed:
Repository: qodo-benchmark/aspnetcore-combined-coderabbit
Length of output: 1255
🏁 Script executed:
Repository: qodo-benchmark/aspnetcore-combined-coderabbit
Length of output: 2347
🏁 Script executed:
Repository: qodo-benchmark/aspnetcore-combined-coderabbit
Length of output: 2873
🏁 Script executed:
Repository: qodo-benchmark/aspnetcore-combined-coderabbit
Length of output: 395
🏁 Script executed:
rg "public.*True" src/Shared/E2ETesting/ --type cs -B 2 -A 3Repository: qodo-benchmark/aspnetcore-combined-coderabbit
Length of output: 1406
🏁 Script executed:
rg "public static.*True|public.*True\(" src/Shared/BrowserTesting/src/ --type cs -B 1 -A 5Repository: qodo-benchmark/aspnetcore-combined-coderabbit
Length of output: 71
Fix staleness check invocation.
IsStaleis an extension method, so the current usage won't compile; wrap it in a lambda to keep the wait behavior.🐛 Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents