From be7eda5e3da92ee60cd38580ceac1455f4306954 Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz Date: Wed, 8 Oct 2025 16:21:05 +0200 Subject: [PATCH 1/2] Fix. --- .../EndpointHtmlRenderer.Prerendering.cs | 2 +- .../ServerRenderingTests/InteractivityTest.cs | 17 +++++++++++------ .../NotFound/ReexecutedPage.razor | 14 ++++++++++++++ 3 files changed, 26 insertions(+), 7 deletions(-) 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..48e21f77c73e 100644 --- a/src/Components/test/E2ETest/ServerRenderingTests/InteractivityTest.cs +++ b/src/Components/test/E2ETest/ServerRenderingTests/InteractivityTest.cs @@ -1502,17 +1502,22 @@ public void LinkNavigationToNotExistingPathReExecutesTo404(string renderMode) Assert404ReExecuted(); } - [Theory] - // prerendering (SSR) is tested in NoInteractivityTest - [InlineData("ServerNonPrerendered")] - [InlineData("WebAssemblyNonPrerendered")] - public void BrowserNavigationToNotExistingPathReExecutesTo404(string renderMode) + [Fact] + public void BrowserNavigationToNotExistingPathReExecutesTo404() { // non-existing path has to have re-execution middleware set up // so it has to have "reexecution" prefix. Otherwise middleware mapping // will not be activated, see configuration in Startup - Navigate($"{ServerPathBase}/reexecution/not-existing-page?renderMode={renderMode}"); + Navigate($"{ServerPathBase}/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() => diff --git a/src/Components/test/testassets/TestContentPackage/NotFound/ReexecutedPage.razor b/src/Components/test/testassets/TestContentPackage/NotFound/ReexecutedPage.razor index 6cf5ec51481a..544de1fc5015 100644 --- a/src/Components/test/testassets/TestContentPackage/NotFound/ReexecutedPage.razor +++ b/src/Components/test/testassets/TestContentPackage/NotFound/ReexecutedPage.razor @@ -1,6 +1,20 @@ @page "/not-found-reexecute" +@rendermode RenderMode.InteractiveServer 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

+ +

Current count: @currentCount

+ + + +@code { + private int currentCount = 0; + + private void IncrementCount() + { + currentCount++; + } +} \ No newline at end of file From 29070c360e8824e39cdc2da4212942f688b778da Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz Date: Thu, 9 Oct 2025 13:54:00 +0200 Subject: [PATCH 2/2] Fix tests. --- .../ServerRenderingTests/InteractivityTest.cs | 19 ++++++++++++++++--- .../RazorComponentEndpointsStartup.cs | 7 +++++++ .../NotFound/ReExecutedComponent.razor | 4 ++++ .../NotFound/ReexecutedPage.razor | 19 +------------------ .../NotFound/ReexecutedPageInteractive.razor | 17 +++++++++++++++++ 5 files changed, 45 insertions(+), 21 deletions(-) create mode 100644 src/Components/test/testassets/TestContentPackage/NotFound/ReExecutedComponent.razor create mode 100644 src/Components/test/testassets/TestContentPackage/NotFound/ReexecutedPageInteractive.razor diff --git a/src/Components/test/E2ETest/ServerRenderingTests/InteractivityTest.cs b/src/Components/test/E2ETest/ServerRenderingTests/InteractivityTest.cs index 48e21f77c73e..c2c4e6c66340 100644 --- a/src/Components/test/E2ETest/ServerRenderingTests/InteractivityTest.cs +++ b/src/Components/test/E2ETest/ServerRenderingTests/InteractivityTest.cs @@ -1502,13 +1502,26 @@ public void LinkNavigationToNotExistingPathReExecutesTo404(string renderMode) Assert404ReExecuted(); } - [Fact] - public void BrowserNavigationToNotExistingPathReExecutesTo404() + [Theory] + // prerendering (SSR) is tested in NoInteractivityTest + [InlineData("ServerNonPrerendered")] + [InlineData("WebAssemblyNonPrerendered")] + public void BrowserNavigationToNotExistingPathReExecutesTo404(string renderMode) { // non-existing path has to have re-execution middleware set up // so it has to have "reexecution" prefix. Otherwise middleware mapping // will not be activated, see configuration in Startup - Navigate($"{ServerPathBase}/reexecution/not-existing-page"); + Navigate($"{ServerPathBase}/reexecution/not-existing-page?renderMode={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(); } 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 544de1fc5015..a36b405c45f4 100644 --- a/src/Components/test/testassets/TestContentPackage/NotFound/ReexecutedPage.razor +++ b/src/Components/test/testassets/TestContentPackage/NotFound/ReexecutedPage.razor @@ -1,20 +1,3 @@ @page "/not-found-reexecute" -@rendermode RenderMode.InteractiveServer -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

- -

Current count: @currentCount

- - - -@code { - private int currentCount = 0; - - private void IncrementCount() - { - currentCount++; - } -} \ No newline at end of file + \ 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