From be227076f17b490247bdb26eb6dc7871beff364d Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz Date: Mon, 16 Jun 2025 09:04:27 +0200 Subject: [PATCH 01/10] 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 e9c6d470d80d..3aa8e936e4d6 100644 --- a/src/Components/Endpoints/test/EndpointHtmlRendererTest.cs +++ b/src/Components/Endpoints/test/EndpointHtmlRendererTest.cs @@ -849,9 +849,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 e5a438283f84..bbeb1ad4d9bb 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 971b7abcf0f42fa8e9658268d7f168adc679125d Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz Date: Mon, 16 Jun 2025 09:19:37 +0200 Subject: [PATCH 02/10] 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 baab0d2a9c1c2518845e42d35e91976e2802974f Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz Date: Mon, 16 Jun 2025 09:31:00 +0200 Subject: [PATCH 03/10] 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 3aa8e936e4d6..3c27365169cb 100644 --- a/src/Components/Endpoints/test/EndpointHtmlRendererTest.cs +++ b/src/Components/Endpoints/test/EndpointHtmlRendererTest.cs @@ -867,7 +867,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 957cc6781cf11e0f8b0cedb9e8a09d2a67ccb683 Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz Date: Mon, 16 Jun 2025 09:36:12 +0200 Subject: [PATCH 04/10] 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 3e2abb91765d6a956bcd6ef959c10e795c0347a6 Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz Date: Mon, 16 Jun 2025 11:12:02 +0200 Subject: [PATCH 05/10] 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 bdf79aee185494eae7456a481448229acfff0620 Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz Date: Mon, 16 Jun 2025 11:15:08 +0200 Subject: [PATCH 06/10] 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 aaa7a64b06d926f6b94f897fadad102adf904655 Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz Date: Mon, 16 Jun 2025 13:55:32 +0200 Subject: [PATCH 07/10] 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 c66a199df2b566dbcb5e5e900fd9ffc27cc1d846 Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz Date: Mon, 16 Jun 2025 13:56:54 +0200 Subject: [PATCH 08/10] 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 16e9a85aa0cd7e947d9e14c92c082c6858d7fae8 Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz Date: Mon, 16 Jun 2025 15:30:25 +0200 Subject: [PATCH 09/10] 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 From 2bdb718e602cc15133737dc30e9f2affabb9d3b0 Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz Date: Wed, 18 Jun 2025 12:29:59 +0200 Subject: [PATCH 10/10] Fix CI. --- .../FormsTest/NotifyPropertyChangedValidationComponent.razor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Components/test/testassets/BasicTestApp/FormsTest/NotifyPropertyChangedValidationComponent.razor b/src/Components/test/testassets/BasicTestApp/FormsTest/NotifyPropertyChangedValidationComponent.razor index f08a419ef6f6..f21620148737 100644 --- a/src/Components/test/testassets/BasicTestApp/FormsTest/NotifyPropertyChangedValidationComponent.razor +++ b/src/Components/test/testassets/BasicTestApp/FormsTest/NotifyPropertyChangedValidationComponent.razor @@ -107,6 +107,6 @@ public class TestServiceProvider : IServiceProvider { public object GetService(Type serviceType) - => throw new NotImplementedException(); + => null; } }