Skip to content

Commit fb37227

Browse files
committed
Unconditionally enable the regex during development (linker will still trim it unless enabled on the project)
1 parent a8f3d68 commit fb37227

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/Components/Components/src/Routing/RegexConstraintSupport.cs

+7-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ namespace Microsoft.AspNetCore.Components.Routing;
55

66
internal static class RegexConstraintSupport
77
{
8-
public static bool IsEnabled =>
9-
AppContext.TryGetSwitch("Microsoft.AspNetCore.Components.Routing.RegexConstraintSupport", out var enabled) && enabled;
8+
// We should check the AppContext switch in the implementation, but it doesn't flow to the wasm runtime
9+
// during development, so we can't offer a better experience (build time message to enable the switch)
10+
// until the context switch flows to the runtime.
11+
// This value gets updated by the linker when the app is trimmed, so the code will always be removed from
12+
// webassembly unless the switch is enabled.
13+
public static bool IsEnabled => true;
14+
// AppContext.TryGetSwitch("Microsoft.AspNetCore.Components.Routing.RegexConstraintSupport", out var enabled) && enabled;
1015
}

src/Components/test/testassets/Components.TestServer/Components.TestServer.csproj

+9
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,17 @@
77
<BlazorWebAssemblyLoadAllGlobalizationData>true</BlazorWebAssemblyLoadAllGlobalizationData>
88
<Nullable>annotations</Nullable>
99
<RazorLangVersion>latest</RazorLangVersion>
10+
<BlazorRoutingEnableRegexConstraint>true</BlazorRoutingEnableRegexConstraint>
11+
<BlazorRoutingEnableRegexConstraint Condition="'$(BlazorRoutingEnableRegexConstraint)' == ''">false</BlazorRoutingEnableRegexConstraint>
1012
</PropertyGroup>
1113

14+
<ItemGroup>
15+
<RuntimeHostConfigurationOption Include="Microsoft.AspNetCore.Components.Routing.RegexConstraintSupport"
16+
Condition="'$(BlazorRoutingEnableRegexConstraint)' != ''"
17+
Value="$(BlazorRoutingEnableRegexConstraint)"
18+
Trim="true" />
19+
</ItemGroup>
20+
1221
<ItemGroup>
1322
<Reference Include="Microsoft.AspNetCore" />
1423
<Reference Include="Microsoft.AspNetCore.Authentication.Cookies" />

0 commit comments

Comments
 (0)