Skip to content

Commit f3031b9

Browse files
authored
Pages that are re-executed should allow interactivity (#63964)
1 parent f7226e4 commit f3031b9

File tree

6 files changed

+48
-5
lines changed

6 files changed

+48
-5
lines changed

src/Components/Endpoints/src/Rendering/EndpointHtmlRenderer.Prerendering.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ internal partial class EndpointHtmlRenderer
2020

2121
protected override IComponent ResolveComponentForRenderMode([DynamicallyAccessedMembers(Component)] Type componentType, int? parentComponentId, IComponentActivator componentActivator, IComponentRenderMode renderMode)
2222
{
23-
if (_isHandlingErrors || _isReExecuted)
23+
if (_isHandlingErrors)
2424
{
2525
// Ignore the render mode boundary in error scenarios.
2626
return componentActivator.CreateInstance(componentType);

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1515,6 +1515,24 @@ public void BrowserNavigationToNotExistingPathReExecutesTo404(string renderMode)
15151515
Assert404ReExecuted();
15161516
}
15171517

1518+
[Fact]
1519+
public void BrowserNavigationToNotExistingPathReExecutesTo404_Interactive()
1520+
{
1521+
// non-existing path has to have re-execution middleware set up
1522+
// so it has to have "interactive-reexecution" prefix. Otherwise middleware mapping
1523+
// will not be activated, see configuration in Startup
1524+
Navigate($"{ServerPathBase}/interactive-reexecution/not-existing-page");
1525+
Assert404ReExecuted();
1526+
AssertReExecutedPageIsInteractive();
1527+
}
1528+
1529+
private void AssertReExecutedPageIsInteractive()
1530+
{
1531+
Browser.Equal("Current count: 0", () => Browser.FindElement(By.CssSelector("[role='status']")).Text);
1532+
Browser.Click(By.Id("increment-button"));
1533+
Browser.Equal("Current count: 1", () => Browser.FindElement(By.CssSelector("[role='status']")).Text);
1534+
}
1535+
15181536
private void Assert404ReExecuted() =>
15191537
Browser.Equal("Welcome On Page Re-executed After Not Found Event", () => Browser.Exists(By.Id("test-info")).Text);
15201538
}

src/Components/test/testassets/Components.TestServer/RazorComponentEndpointsStartup.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
109109
reexecutionApp.UseAntiforgery();
110110
ConfigureEndpoints(reexecutionApp, env);
111111
});
112+
app.Map("/interactive-reexecution", reexecutionApp =>
113+
{
114+
reexecutionApp.UseStatusCodePagesWithReExecute("/not-found-reexecute-interactive", createScopeForStatusCodePages: true);
115+
reexecutionApp.UseRouting();
116+
reexecutionApp.UseAntiforgery();
117+
ConfigureEndpoints(reexecutionApp, env);
118+
});
112119

113120
ConfigureSubdirPipeline(app, env);
114121
});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<PageTitle>Re-executed page</PageTitle>
2+
3+
<h3 id="test-info">Welcome On Page Re-executed After Not Found Event</h3>
4+
<p>This page is shown when UseStatusCodePagesWithReExecute is set and another page sets 404</p>
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
@page "/not-found-reexecute"
22

3-
<PageTitle>Re-executed page</PageTitle>
4-
5-
<h3 id="test-info">Welcome On Page Re-executed After Not Found Event</h3>
6-
<p>This page is shown when UseStatusCodePagesWithReExecute is set and another page sets 404</p>
3+
<ReExecutedComponent />
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
@page "/not-found-reexecute-interactive"
2+
@rendermode RenderMode.InteractiveServer
3+
4+
<ReExecutedComponent />
5+
6+
<p role="status">Current count: @currentCount</p>
7+
8+
<button id="increment-button" class="btn btn-primary" @onclick="IncrementCount">Click me</button>
9+
10+
@code {
11+
private int currentCount = 0;
12+
13+
private void IncrementCount()
14+
{
15+
currentCount++;
16+
}
17+
}

0 commit comments

Comments
 (0)