From 873923f4d9bc01534f179b50b6c0adbc18481e05 Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz Date: Mon, 16 Jun 2025 09:04:27 +0200 Subject: [PATCH 1/9] Flip. --- .../src/DependencyInjection/HttpNavigationManager.cs | 6 +++--- src/Components/Endpoints/test/EndpointHtmlRendererTest.cs | 4 ++-- .../Server/src/Circuits/RemoteNavigationManager.cs | 6 +++--- .../test/E2ETest/ServerRenderingTests/InteractivityTest.cs | 2 +- .../E2ETest/ServerRenderingTests/NoInteractivityTest.cs | 2 +- src/submodules/googletest | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Components/Endpoints/src/DependencyInjection/HttpNavigationManager.cs b/src/Components/Endpoints/src/DependencyInjection/HttpNavigationManager.cs index 4585368b830a..9707637840af 100644 --- a/src/Components/Endpoints/src/DependencyInjection/HttpNavigationManager.cs +++ b/src/Components/Endpoints/src/DependencyInjection/HttpNavigationManager.cs @@ -8,11 +8,11 @@ namespace Microsoft.AspNetCore.Components.Endpoints; internal sealed class HttpNavigationManager : NavigationManager, IHostEnvironmentNavigationManager { - private const string _enableThrowNavigationException = "Microsoft.AspNetCore.Components.Endpoints.NavigationManager.EnableThrowNavigationException"; + private const string _disableThrowNavigationException = "Microsoft.AspNetCore.Components.Endpoints.NavigationManager.DisableThrowNavigationException"; - [FeatureSwitchDefinition(_enableThrowNavigationException)] + [FeatureSwitchDefinition(_disableThrowNavigationException)] private static bool _throwNavigationException => - AppContext.TryGetSwitch(_enableThrowNavigationException, out var switchValue) && switchValue; + !AppContext.TryGetSwitch(_disableThrowNavigationException, out var switchValue) && switchValue; private Func? _onNavigateTo; diff --git a/src/Components/Endpoints/test/EndpointHtmlRendererTest.cs b/src/Components/Endpoints/test/EndpointHtmlRendererTest.cs index febc15871d01..fbaf0bb73690 100644 --- a/src/Components/Endpoints/test/EndpointHtmlRendererTest.cs +++ b/src/Components/Endpoints/test/EndpointHtmlRendererTest.cs @@ -846,9 +846,9 @@ public async Task Rendering_ComponentWithJsInteropThrows() [Theory] [InlineData(true)] [InlineData(false)] - public async Task UriHelperRedirect_ThrowsInvalidOperationException_WhenResponseHasAlreadyStarted(bool expectException) + public async Task UriHelperRedirect_ThrowsInvalidOperationException_WhenResponseHasAlreadyStarted(bool allowException) { - AppContext.SetSwitch("Microsoft.AspNetCore.Components.Endpoints.NavigationManager.EnableThrowNavigationException", isEnabled: expectException); + AppContext.SetSwitch("Microsoft.AspNetCore.Components.Endpoints.NavigationManager.DisableThrowNavigationException", isEnabled: !allowException); // Arrange var ctx = new DefaultHttpContext(); ctx.Request.Scheme = "http"; diff --git a/src/Components/Server/src/Circuits/RemoteNavigationManager.cs b/src/Components/Server/src/Circuits/RemoteNavigationManager.cs index ddb5df5b03db..ef2fc08b3172 100644 --- a/src/Components/Server/src/Circuits/RemoteNavigationManager.cs +++ b/src/Components/Server/src/Circuits/RemoteNavigationManager.cs @@ -17,11 +17,11 @@ internal sealed partial class RemoteNavigationManager : NavigationManager, IHost private readonly ILogger _logger; private IJSRuntime _jsRuntime; private bool? _navigationLockStateBeforeJsRuntimeAttached; - private const string _enableThrowNavigationException = "Microsoft.AspNetCore.Components.Endpoints.NavigationManager.EnableThrowNavigationException"; + private const string _disableThrowNavigationException = "Microsoft.AspNetCore.Components.Endpoints.NavigationManager.DisableThrowNavigationException"; - [FeatureSwitchDefinition(_enableThrowNavigationException)] + [FeatureSwitchDefinition(_disableThrowNavigationException)] private static bool _throwNavigationException => - AppContext.TryGetSwitch(_enableThrowNavigationException, out var switchValue) && switchValue; + !AppContext.TryGetSwitch(_disableThrowNavigationException, out var switchValue) && switchValue; private Func? _onNavigateTo; public event EventHandler? UnhandledException; diff --git a/src/Components/test/E2ETest/ServerRenderingTests/InteractivityTest.cs b/src/Components/test/E2ETest/ServerRenderingTests/InteractivityTest.cs index dd9f2a3a47e8..b99a682a9457 100644 --- a/src/Components/test/E2ETest/ServerRenderingTests/InteractivityTest.cs +++ b/src/Components/test/E2ETest/ServerRenderingTests/InteractivityTest.cs @@ -1405,7 +1405,7 @@ public void CanPersistMultiplePrerenderedStateDeclaratively_Auto_PersistsOnWebAs [InlineData(false)] public void NavigatesWithInteractivityByRequestRedirection(bool controlFlowByException) { - AppContext.SetSwitch("Microsoft.AspNetCore.Components.Endpoints.NavigationManager.EnableThrowNavigationException", isEnabled: controlFlowByException); + AppContext.SetSwitch("Microsoft.AspNetCore.Components.Endpoints.NavigationManager.DisableThrowNavigationException", isEnabled: !controlFlowByException); Navigate($"{ServerPathBase}/routing/ssr-navigate-to"); Browser.Equal("Click submit to navigate to home", () => Browser.Exists(By.Id("test-info")).Text); Browser.Click(By.Id("redirectButton")); diff --git a/src/Components/test/E2ETest/ServerRenderingTests/NoInteractivityTest.cs b/src/Components/test/E2ETest/ServerRenderingTests/NoInteractivityTest.cs index 35f7140f9170..452bc32ef750 100644 --- a/src/Components/test/E2ETest/ServerRenderingTests/NoInteractivityTest.cs +++ b/src/Components/test/E2ETest/ServerRenderingTests/NoInteractivityTest.cs @@ -72,7 +72,7 @@ public void CanUseServerAuthenticationStateByDefault() [InlineData(false, true)] public void NavigatesWithoutInteractivityByRequestRedirection(bool controlFlowByException, bool isStreaming) { - AppContext.SetSwitch("Microsoft.AspNetCore.Components.Endpoints.NavigationManager.EnableThrowNavigationException", isEnabled: controlFlowByException); + AppContext.SetSwitch("Microsoft.AspNetCore.Components.Endpoints.NavigationManager.DisableThrowNavigationException", isEnabled: !controlFlowByException); string streaming = isStreaming ? $"streaming-" : ""; Navigate($"{ServerPathBase}/routing/ssr-{streaming}navigate-to"); Browser.Equal("Click submit to navigate to home", () => Browser.Exists(By.Id("test-info")).Text); diff --git a/src/submodules/googletest b/src/submodules/googletest index 175c1b55cfb3..7427a6b5e3e0 160000 --- a/src/submodules/googletest +++ b/src/submodules/googletest @@ -1 +1 @@ -Subproject commit 175c1b55cfb3dbed519b94a370c083aac605009f +Subproject commit 7427a6b5e3e04f895ecad5c647c94629fb2acdc0 From f2493a948774bb3d594bd9d270e842d04b2acd7f Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz Date: Mon, 16 Jun 2025 09:19:37 +0200 Subject: [PATCH 2/9] Update templates. --- .../content/BlazorWeb-CSharp/BlazorWeb-CSharp/Program.Main.cs | 1 + .../content/BlazorWeb-CSharp/BlazorWeb-CSharp/Program.cs | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWeb-CSharp/Program.Main.cs b/src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWeb-CSharp/Program.Main.cs index b0b8d955cc6d..ca0cc62f3d17 100644 --- a/src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWeb-CSharp/Program.Main.cs +++ b/src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWeb-CSharp/Program.Main.cs @@ -20,6 +20,7 @@ public class Program { public static void Main(string[] args) { + System.AppContext.SetSwitch("Microsoft.AspNetCore.Components.Endpoints.NavigationManager.DisableThrowNavigationException", true); var builder = WebApplication.CreateBuilder(args); // Add services to the container. diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWeb-CSharp/Program.cs b/src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWeb-CSharp/Program.cs index 8eb1deacb1fa..e6afef0c4e8d 100644 --- a/src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWeb-CSharp/Program.cs +++ b/src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWeb-CSharp/Program.cs @@ -14,6 +14,8 @@ using BlazorWeb_CSharp.Data; #endif +System.AppContext.SetSwitch("Microsoft.AspNetCore.Components.Endpoints.NavigationManager.DisableThrowNavigationException", true); + var builder = WebApplication.CreateBuilder(args); // Add services to the container. From 1c0f1d74107108ebc24eb4e202374d00ef58d50e Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz Date: Mon, 16 Jun 2025 09:31:00 +0200 Subject: [PATCH 3/9] Missing rename. --- src/Components/Endpoints/test/EndpointHtmlRendererTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Components/Endpoints/test/EndpointHtmlRendererTest.cs b/src/Components/Endpoints/test/EndpointHtmlRendererTest.cs index fbaf0bb73690..74bc6f7e0761 100644 --- a/src/Components/Endpoints/test/EndpointHtmlRendererTest.cs +++ b/src/Components/Endpoints/test/EndpointHtmlRendererTest.cs @@ -864,7 +864,7 @@ public async Task UriHelperRedirect_ThrowsInvalidOperationException_WhenResponse string redirectUri = "http://localhost/redirect"; // Act - if (expectException) + if (allowException) { var exception = await Assert.ThrowsAsync(async () => await renderer.PrerenderComponentAsync( httpContext, From 48b88db47dda5ad4efa00958c44221c2dbd955bf Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz Date: Mon, 16 Jun 2025 09:36:12 +0200 Subject: [PATCH 4/9] Fix new default value. --- .../Endpoints/src/DependencyInjection/HttpNavigationManager.cs | 2 +- src/Components/Server/src/Circuits/RemoteNavigationManager.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Components/Endpoints/src/DependencyInjection/HttpNavigationManager.cs b/src/Components/Endpoints/src/DependencyInjection/HttpNavigationManager.cs index 9707637840af..5c2d42fedd24 100644 --- a/src/Components/Endpoints/src/DependencyInjection/HttpNavigationManager.cs +++ b/src/Components/Endpoints/src/DependencyInjection/HttpNavigationManager.cs @@ -12,7 +12,7 @@ internal sealed class HttpNavigationManager : NavigationManager, IHostEnvironmen [FeatureSwitchDefinition(_disableThrowNavigationException)] private static bool _throwNavigationException => - !AppContext.TryGetSwitch(_disableThrowNavigationException, out var switchValue) && switchValue; + !AppContext.TryGetSwitch(_disableThrowNavigationException, out var switchValue) || !switchValue; private Func? _onNavigateTo; diff --git a/src/Components/Server/src/Circuits/RemoteNavigationManager.cs b/src/Components/Server/src/Circuits/RemoteNavigationManager.cs index ef2fc08b3172..2100ef3a7a16 100644 --- a/src/Components/Server/src/Circuits/RemoteNavigationManager.cs +++ b/src/Components/Server/src/Circuits/RemoteNavigationManager.cs @@ -21,7 +21,7 @@ internal sealed partial class RemoteNavigationManager : NavigationManager, IHost [FeatureSwitchDefinition(_disableThrowNavigationException)] private static bool _throwNavigationException => - !AppContext.TryGetSwitch(_disableThrowNavigationException, out var switchValue) && switchValue; + !AppContext.TryGetSwitch(_disableThrowNavigationException, out var switchValue) || !switchValue; private Func? _onNavigateTo; public event EventHandler? UnhandledException; From bedb6687520f4401622cbd4b996d5f3d366d271b Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz Date: Mon, 16 Jun 2025 11:12:02 +0200 Subject: [PATCH 5/9] Feedback: use sdk for setting the switch. --- src/ProjectTemplates/Directory.Build.props | 1 + .../content/BlazorWeb-CSharp/BlazorWeb-CSharp/Program.Main.cs | 1 - .../content/BlazorWeb-CSharp/BlazorWeb-CSharp/Program.cs | 2 -- 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/ProjectTemplates/Directory.Build.props b/src/ProjectTemplates/Directory.Build.props index c97233e66a46..140d885dc840 100644 --- a/src/ProjectTemplates/Directory.Build.props +++ b/src/ProjectTemplates/Directory.Build.props @@ -4,6 +4,7 @@ false + true diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWeb-CSharp/Program.Main.cs b/src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWeb-CSharp/Program.Main.cs index ca0cc62f3d17..b0b8d955cc6d 100644 --- a/src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWeb-CSharp/Program.Main.cs +++ b/src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWeb-CSharp/Program.Main.cs @@ -20,7 +20,6 @@ public class Program { public static void Main(string[] args) { - System.AppContext.SetSwitch("Microsoft.AspNetCore.Components.Endpoints.NavigationManager.DisableThrowNavigationException", true); var builder = WebApplication.CreateBuilder(args); // Add services to the container. diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWeb-CSharp/Program.cs b/src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWeb-CSharp/Program.cs index e6afef0c4e8d..8eb1deacb1fa 100644 --- a/src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWeb-CSharp/Program.cs +++ b/src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWeb-CSharp/Program.cs @@ -14,8 +14,6 @@ using BlazorWeb_CSharp.Data; #endif -System.AppContext.SetSwitch("Microsoft.AspNetCore.Components.Endpoints.NavigationManager.DisableThrowNavigationException", true); - var builder = WebApplication.CreateBuilder(args); // Add services to the container. From 03e77f7109fc505eaf0f9aa4c267a93ab036bfdb Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz Date: Mon, 16 Jun 2025 11:15:08 +0200 Subject: [PATCH 6/9] With Blazor prefix it's easier to detect where this switch belongs. --- src/ProjectTemplates/Directory.Build.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ProjectTemplates/Directory.Build.props b/src/ProjectTemplates/Directory.Build.props index 140d885dc840..dae990787d63 100644 --- a/src/ProjectTemplates/Directory.Build.props +++ b/src/ProjectTemplates/Directory.Build.props @@ -4,7 +4,7 @@ false - true + true From 67d086b3dcab77b5ded5b98032b266d3b30b503f Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz Date: Mon, 16 Jun 2025 13:55:32 +0200 Subject: [PATCH 7/9] Move the property. --- src/ProjectTemplates/Directory.Build.props | 1 - .../Web.ProjectTemplates/BlazorWeb-CSharp.csproj.in | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ProjectTemplates/Directory.Build.props b/src/ProjectTemplates/Directory.Build.props index dae990787d63..c97233e66a46 100644 --- a/src/ProjectTemplates/Directory.Build.props +++ b/src/ProjectTemplates/Directory.Build.props @@ -4,7 +4,6 @@ false - true diff --git a/src/ProjectTemplates/Web.ProjectTemplates/BlazorWeb-CSharp.csproj.in b/src/ProjectTemplates/Web.ProjectTemplates/BlazorWeb-CSharp.csproj.in index 541be08bd263..22ce06f89047 100644 --- a/src/ProjectTemplates/Web.ProjectTemplates/BlazorWeb-CSharp.csproj.in +++ b/src/ProjectTemplates/Web.ProjectTemplates/BlazorWeb-CSharp.csproj.in @@ -8,6 +8,7 @@ True BlazorWeb-CSharp `$(AssemblyName.Replace(' ', '_')) + true From 92c39c4bd1dbcfa6341046270655ade7b8943aba Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz Date: Mon, 16 Jun 2025 13:56:54 +0200 Subject: [PATCH 8/9] Revert miscommit. --- src/submodules/googletest | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/submodules/googletest b/src/submodules/googletest index 7427a6b5e3e0..175c1b55cfb3 160000 --- a/src/submodules/googletest +++ b/src/submodules/googletest @@ -1 +1 @@ -Subproject commit 7427a6b5e3e04f895ecad5c647c94629fb2acdc0 +Subproject commit 175c1b55cfb3dbed519b94a370c083aac605009f From 0432cc0eb03a7a69a9985d2b780e32e1bc95be83 Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz Date: Mon, 16 Jun 2025 15:30:25 +0200 Subject: [PATCH 9/9] Update client csproj. --- .../Web.ProjectTemplates/BlazorWeb-CSharp.Client.csproj.in | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ProjectTemplates/Web.ProjectTemplates/BlazorWeb-CSharp.Client.csproj.in b/src/ProjectTemplates/Web.ProjectTemplates/BlazorWeb-CSharp.Client.csproj.in index 829c12db913c..a7c485d95644 100644 --- a/src/ProjectTemplates/Web.ProjectTemplates/BlazorWeb-CSharp.Client.csproj.in +++ b/src/ProjectTemplates/Web.ProjectTemplates/BlazorWeb-CSharp.Client.csproj.in @@ -8,6 +8,7 @@ Default BlazorWeb-CSharp.Client `$(AssemblyName.Replace(' ', '_')) + true