Skip to content

Commit 9cd97f4

Browse files
Mackinnon Buckwtgodbe
authored andcommitted
Merged PR 37179: [internal/release/8.0] [Blazor] Fix interactive server component activation
Fixes an issue where interactive server components may sometimes fail to become interactive.
1 parent 90035db commit 9cd97f4

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

src/Components/Server/src/DependencyInjection/ComponentServiceCollectionExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ public static IServerSideBlazorBuilder AddServerSideBlazor(this IServiceCollecti
6161
// user's configuration. So even if the user has multiple independent server-side
6262
// Components entrypoints, this lot is the same and repeated registrations are a no-op.
6363
services.TryAddSingleton<ICircuitFactory, CircuitFactory>();
64-
services.TryAddSingleton<IServerComponentDeserializer, ServerComponentDeserializer>();
6564
services.TryAddSingleton<ICircuitHandleRegistry, CircuitHandleRegistry>();
6665
services.TryAddSingleton<RootComponentTypeCache>();
6766
services.TryAddSingleton<ComponentParameterDeserializer>();
6867
services.TryAddSingleton<ComponentParametersTypeCache>();
6968
services.TryAddSingleton<CircuitIdFactory>();
69+
services.TryAddScoped<IServerComponentDeserializer, ServerComponentDeserializer>();
7070
services.TryAddScoped<IErrorBoundaryLogger, RemoteErrorBoundaryLogger>();
7171
services.TryAddScoped<AntiforgeryStateProvider, DefaultAntiforgeryStateProvider>();
7272

src/Components/test/E2ETest/ServerRenderingTests/InteractivityTest.cs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,6 +1172,55 @@ public void InteractiveServerRootComponent_CanAccessCircuitContext()
11721172
Browser.Equal("True", () => Browser.FindElement(By.Id("has-circuit-context")).Text);
11731173
}
11741174

1175+
[Fact]
1176+
public void InteractiveServerRootComponents_CanBecomeInteractive_WithoutInterferingWithOtherCircuits()
1177+
{
1178+
// Start by setting up 2 tabs with interactive server components.
1179+
SetUpPageWithOneInteractiveServerComponent();
1180+
1181+
var firstWindow = Browser.CurrentWindowHandle;
1182+
Browser.SwitchTo().NewWindow(WindowType.Tab);
1183+
var secondWindow = Browser.CurrentWindowHandle;
1184+
1185+
SetUpPageWithOneInteractiveServerComponent();
1186+
1187+
// Start streaming in the second tab.
1188+
Browser.Click(By.Id("start-streaming-link"));
1189+
Browser.Equal("Streaming", () => Browser.FindElement(By.Id("status")).Text);
1190+
1191+
// Add an interactive server component while streaming.
1192+
// This will update the existing component, but the new component
1193+
// won't become interactive until streaming ends.
1194+
Browser.Click(By.Id(AddServerPrerenderedId));
1195+
Browser.Equal("False", () => Browser.FindElement(By.Id($"is-interactive-1")).Text);
1196+
1197+
// Add an interactive server component in the first tab.
1198+
// This component will become interactive immediately because the response
1199+
// that rendered the component will have completed quickly.
1200+
Browser.SwitchTo().Window(firstWindow);
1201+
Browser.Click(By.Id(AddServerPrerenderedId));
1202+
Browser.Equal("True", () => Browser.FindElement(By.Id($"is-interactive-1")).Text);
1203+
1204+
// Stop streaming in the second tab.
1205+
// This will activate the pending component for interactivity.
1206+
// This check verifies that a circuit can activate components from its most
1207+
// recent response, even if that response isn't the most recent between all
1208+
// circuits.
1209+
Browser.SwitchTo().Window(secondWindow);
1210+
Browser.Click(By.Id("stop-streaming-link"));
1211+
Browser.Equal("True", () => Browser.FindElement(By.Id($"is-interactive-1")).Text);
1212+
1213+
void SetUpPageWithOneInteractiveServerComponent()
1214+
{
1215+
Navigate($"{ServerPathBase}/streaming-interactivity");
1216+
1217+
Browser.Equal("Not streaming", () => Browser.FindElement(By.Id("status")).Text);
1218+
1219+
Browser.Click(By.Id(AddServerPrerenderedId));
1220+
Browser.Equal("True", () => Browser.FindElement(By.Id($"is-interactive-0")).Text);
1221+
}
1222+
}
1223+
11751224
private void BlockWebAssemblyResourceLoad()
11761225
{
11771226
// Force a WebAssembly resource cache miss so that we can fall back to using server interactivity

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy