diff --git a/src/Components/Endpoints/src/Rendering/EndpointHtmlRenderer.Prerendering.cs b/src/Components/Endpoints/src/Rendering/EndpointHtmlRenderer.Prerendering.cs index abc9441d54fa..ec8407b17a96 100644 --- a/src/Components/Endpoints/src/Rendering/EndpointHtmlRenderer.Prerendering.cs +++ b/src/Components/Endpoints/src/Rendering/EndpointHtmlRenderer.Prerendering.cs @@ -20,7 +20,7 @@ internal partial class EndpointHtmlRenderer protected override IComponent ResolveComponentForRenderMode([DynamicallyAccessedMembers(Component)] Type componentType, int? parentComponentId, IComponentActivator componentActivator, IComponentRenderMode renderMode) { - if (_isHandlingErrors || _isReExecuted) + if (_isHandlingErrors) { // Ignore the render mode boundary in error scenarios. return componentActivator.CreateInstance(componentType); diff --git a/src/Components/test/E2ETest/ServerRenderingTests/InteractivityTest.cs b/src/Components/test/E2ETest/ServerRenderingTests/InteractivityTest.cs index 3322c184ef7a..c2c4e6c66340 100644 --- a/src/Components/test/E2ETest/ServerRenderingTests/InteractivityTest.cs +++ b/src/Components/test/E2ETest/ServerRenderingTests/InteractivityTest.cs @@ -1515,6 +1515,24 @@ public void BrowserNavigationToNotExistingPathReExecutesTo404(string renderMode) Assert404ReExecuted(); } + [Fact] + public void BrowserNavigationToNotExistingPathReExecutesTo404_Interactive() + { + // non-existing path has to have re-execution middleware set up + // so it has to have "interactive-reexecution" prefix. Otherwise middleware mapping + // will not be activated, see configuration in Startup + Navigate($"{ServerPathBase}/interactive-reexecution/not-existing-page"); + Assert404ReExecuted(); + AssertReExecutedPageIsInteractive(); + } + + private void AssertReExecutedPageIsInteractive() + { + Browser.Equal("Current count: 0", () => Browser.FindElement(By.CssSelector("[role='status']")).Text); + Browser.Click(By.Id("increment-button")); + Browser.Equal("Current count: 1", () => Browser.FindElement(By.CssSelector("[role='status']")).Text); + } + private void Assert404ReExecuted() => Browser.Equal("Welcome On Page Re-executed After Not Found Event", () => Browser.Exists(By.Id("test-info")).Text); } diff --git a/src/Components/test/testassets/Components.TestServer/RazorComponentEndpointsStartup.cs b/src/Components/test/testassets/Components.TestServer/RazorComponentEndpointsStartup.cs index 7a8e554d424a..861e0fbdf288 100644 --- a/src/Components/test/testassets/Components.TestServer/RazorComponentEndpointsStartup.cs +++ b/src/Components/test/testassets/Components.TestServer/RazorComponentEndpointsStartup.cs @@ -109,6 +109,13 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) reexecutionApp.UseAntiforgery(); ConfigureEndpoints(reexecutionApp, env); }); + app.Map("/interactive-reexecution", reexecutionApp => + { + reexecutionApp.UseStatusCodePagesWithReExecute("/not-found-reexecute-interactive", createScopeForStatusCodePages: true); + reexecutionApp.UseRouting(); + reexecutionApp.UseAntiforgery(); + ConfigureEndpoints(reexecutionApp, env); + }); ConfigureSubdirPipeline(app, env); }); diff --git a/src/Components/test/testassets/TestContentPackage/NotFound/ReExecutedComponent.razor b/src/Components/test/testassets/TestContentPackage/NotFound/ReExecutedComponent.razor new file mode 100644 index 000000000000..de208d2a681c --- /dev/null +++ b/src/Components/test/testassets/TestContentPackage/NotFound/ReExecutedComponent.razor @@ -0,0 +1,4 @@ +Re-executed page + +

Welcome On Page Re-executed After Not Found Event

+

This page is shown when UseStatusCodePagesWithReExecute is set and another page sets 404

diff --git a/src/Components/test/testassets/TestContentPackage/NotFound/ReexecutedPage.razor b/src/Components/test/testassets/TestContentPackage/NotFound/ReexecutedPage.razor index 6cf5ec51481a..a36b405c45f4 100644 --- a/src/Components/test/testassets/TestContentPackage/NotFound/ReexecutedPage.razor +++ b/src/Components/test/testassets/TestContentPackage/NotFound/ReexecutedPage.razor @@ -1,6 +1,3 @@ @page "/not-found-reexecute" -Re-executed page - -

Welcome On Page Re-executed After Not Found Event

-

This page is shown when UseStatusCodePagesWithReExecute is set and another page sets 404

+ \ No newline at end of file diff --git a/src/Components/test/testassets/TestContentPackage/NotFound/ReexecutedPageInteractive.razor b/src/Components/test/testassets/TestContentPackage/NotFound/ReexecutedPageInteractive.razor new file mode 100644 index 000000000000..c041b96d14f8 --- /dev/null +++ b/src/Components/test/testassets/TestContentPackage/NotFound/ReexecutedPageInteractive.razor @@ -0,0 +1,17 @@ +@page "/not-found-reexecute-interactive" +@rendermode RenderMode.InteractiveServer + + + +

Current count: @currentCount

+ + + +@code { + private int currentCount = 0; + + private void IncrementCount() + { + currentCount++; + } +} \ No newline at end of file