Skip to content

Commit 0b20add

Browse files
committed
PR feedback
1 parent effc7cb commit 0b20add

20 files changed

+97
-244
lines changed

src/Components/Endpoints/src/DependencyInjection/ServerComponentSerializer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ public ServerComponentSerializer(IDataProtectionProvider dataProtectionProvider)
1818

1919
public void SerializeInvocation(ref ComponentMarker marker, ServerComponentInvocationSequence invocationId, Type type, ParameterView parameters)
2020
{
21-
var (sequence, serverComponent) = CreateSerializedServerComponent(invocationId, type, parameters, marker.Key!);
21+
var (sequence, serverComponent) = CreateSerializedServerComponent(invocationId, type, parameters, marker.Key);
2222
marker.WriteServerData(sequence, serverComponent);
2323
}
2424

2525
private (int sequence, string payload) CreateSerializedServerComponent(
2626
ServerComponentInvocationSequence invocationId,
2727
Type rootComponent,
2828
ParameterView parameters,
29-
string key)
29+
ComponentMarkerKey? key)
3030
{
3131
var sequence = invocationId.Next();
3232

src/Components/Endpoints/src/Microsoft.AspNetCore.Components.Endpoints.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
<Compile Include="$(RepoRoot)src\Shared\Components\PrerenderComponentApplicationStore.cs" LinkBase="DependencyInjection" />
3535
<Compile Include="$(RepoRoot)src\Shared\Components\ProtectedPrerenderComponentApplicationStore.cs" LinkBase="DependencyInjection" />
3636
<Compile Include="$(RepoRoot)src\Shared\ClosedGenericMatcher\ClosedGenericMatcher.cs" LinkBase="FormMapping" />
37-
<Compile Include="$(ComponentsSharedSourceRoot)src\BoundaryMarkerKey.cs" Link="Shared\BoundaryMarkerKey.cs" />
3837
<Compile Include="$(ComponentsSharedSourceRoot)src\CacheHeaderSettings.cs" Link="Shared\CacheHeaderSettings.cs" />
3938
<Compile Include="$(ComponentsSharedSourceRoot)src\DefaultAntiforgeryStateProvider.cs" LinkBase="Forms" />
4039
<Compile Include="$(SharedSourceRoot)LinkerFlags.cs" LinkBase="Shared" />

src/Components/Endpoints/src/Rendering/SSRRenderModeBoundary.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ internal class SSRRenderModeBoundary : IComponent
2929
private readonly bool _prerender;
3030
private RenderHandle _renderHandle;
3131
private IReadOnlyDictionary<string, object?>? _latestParameters;
32-
private string? _markerKey;
32+
private ComponentMarkerKey? _markerKey;
3333

3434
public IComponentRenderMode RenderMode { get; }
3535

@@ -154,11 +154,11 @@ private void Prerender(RenderTreeBuilder builder)
154154
builder.CloseComponent();
155155
}
156156

157-
public ComponentMarker ToMarker(HttpContext httpContext, int sequence, object? key)
157+
public ComponentMarker ToMarker(HttpContext httpContext, int sequence, object? componentKey)
158158
{
159159
// We expect that the '@key' and sequence number shouldn't change for a given component instance,
160160
// so we lazily compute the marker key once.
161-
_markerKey ??= GenerateMarkerKey(sequence, key);
161+
_markerKey ??= GenerateMarkerKey(sequence, componentKey);
162162

163163
var parameters = _latestParameters is null
164164
? ParameterView.Empty
@@ -190,18 +190,19 @@ public ComponentMarker ToMarker(HttpContext httpContext, int sequence, object? k
190190
return marker;
191191
}
192192

193-
private string GenerateMarkerKey(int sequence, object? key)
193+
private ComponentMarkerKey GenerateMarkerKey(int sequence, object? componentKey)
194194
{
195195
var componentTypeNameHash = _componentTypeNameHashCache.GetOrAdd(_componentType, ComputeComponentTypeNameHash);
196196
var sequenceString = sequence.ToString(CultureInfo.InvariantCulture);
197-
var formattedComponentKey = (key as IFormattable)?.ToString(null, CultureInfo.InvariantCulture) ?? string.Empty;
198197

199-
var boundaryMarkerKey = new BoundaryMarkerKey(
200-
componentTypeNameHash.AsMemory(),
201-
sequenceString.AsMemory(),
202-
formattedComponentKey.AsMemory());
198+
var locationHash = $"{componentTypeNameHash}:{sequenceString}";
199+
var formattedComponentKey = (componentKey as IFormattable)?.ToString(null, CultureInfo.InvariantCulture) ?? string.Empty;
203200

204-
return boundaryMarkerKey.ToString();
201+
return new()
202+
{
203+
LocationHash = locationHash,
204+
FormattedComponentKey = formattedComponentKey,
205+
};
205206
}
206207

207208
private static string ComputeComponentTypeNameHash(Type componentType)

src/Components/Endpoints/test/BoundaryMarkerKeyTest.cs

Lines changed: 0 additions & 117 deletions
This file was deleted.

src/Components/Server/src/CircuitRootComponentOptions.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,4 @@ public class CircuitRootComponentOptions : IJSComponentConfiguration
1818
/// </summary>
1919
/// <value>Defaults to <c>100</c>.</value>
2020
public int MaxJSRootComponents { get; set; } = 100;
21-
22-
/// <summary>
23-
/// Gets or sets the maximum number of root components with an interactive server
24-
/// render mode that may exist on a circuit at any given time.
25-
/// </summary>
26-
/// <value>Defaults to <c>1000</c>.</value>
27-
public int MaxInteractiveServerRootComponentCount { get; set; } = 1000;
2821
}

src/Components/Server/src/Circuits/WebRootComponentDescriptor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ namespace Microsoft.AspNetCore.Components.Server;
55

66
internal sealed class WebRootComponentDescriptor(
77
Type componentType,
8-
string key,
8+
ComponentMarkerKey? key,
99
WebRootComponentParameters parameters)
1010
{
1111
public Type ComponentType => componentType;
1212

13-
public string Key => key;
13+
public ComponentMarkerKey? Key => key;
1414

1515
public WebRootComponentParameters Parameters => parameters;
1616
}

src/Components/Server/src/Microsoft.AspNetCore.Components.Server.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
<UsingTask AssemblyFile="$(_FileProviderTaskAssembly)" TaskName="Microsoft.Extensions.FileProviders.Embedded.Manifest.Task.GenerateEmbeddedResourcesManifest" />
5454

5555
<ItemGroup>
56-
<Compile Include="$(ComponentsSharedSourceRoot)src\BoundaryMarkerKey.cs" Link="Shared\BoundaryMarkerKey.cs" />
5756
<Compile Include="$(ComponentsSharedSourceRoot)src\CacheHeaderSettings.cs" Link="Shared\CacheHeaderSettings.cs" />
5857
<Compile Include="$(ComponentsSharedSourceRoot)src\ArrayBuilder.cs" LinkBase="Circuits" />
5958
<Compile Include="$(ComponentsSharedSourceRoot)src\RenderBatchWriter.cs" LinkBase="Circuits" />

src/Components/Server/src/PublicAPI.Unshipped.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#nullable enable
22
Microsoft.AspNetCore.Builder.ServerRazorComponentsEndpointConventionBuilderExtensions
3-
Microsoft.AspNetCore.Components.Server.CircuitRootComponentOptions.MaxInteractiveServerRootComponentCount.get -> int
4-
Microsoft.AspNetCore.Components.Server.CircuitRootComponentOptions.MaxInteractiveServerRootComponentCount.set -> void
53
Microsoft.AspNetCore.Components.Server.Circuits.CircuitInboundActivityContext
64
Microsoft.AspNetCore.Components.Server.Circuits.CircuitInboundActivityContext.Circuit.get -> Microsoft.AspNetCore.Components.Server.Circuits.Circuit!
75
Microsoft.Extensions.DependencyInjection.ServerRazorComponentsBuilderExtensions

src/Components/Server/test/Circuits/CircuitHostTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -622,8 +622,8 @@ private static void SetupMockInboundActivityHandler(Mock<CircuitHandler> circuit
622622
private ComponentMarker CreateMarker(Type type, Dictionary<string, object> parameters = null, string componentKey = "")
623623
{
624624
var serializer = new ServerComponentSerializer(_ephemeralDataProtectionProvider);
625-
var key = new BoundaryMarkerKey(type.FullName.AsMemory(), "0".AsMemory(), componentKey.AsMemory());
626-
var marker = ComponentMarker.Create(ComponentMarker.ServerMarkerType, false, key.ToString());
625+
var key = new ComponentMarkerKey(type.FullName, componentKey);
626+
var marker = ComponentMarker.Create(ComponentMarker.ServerMarkerType, false, key);
627627
serializer.SerializeInvocation(
628628
ref marker,
629629
_invocationSequence,

src/Components/Server/test/Circuits/RemoteRendererTest.cs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ public async Task WebRootComponentManager_AddRootComponentAsync_Throws_IfDuplica
464464
}
465465

466466
[Fact]
467-
public async Task WebRootComponentManager_AddRootComponentAsync_Throws_IfKeyIsMalformed()
467+
public async Task WebRootComponentManager_AddRootComponentAsync_Throws_IfKeyIsInvalid()
468468
{
469469
// Arrange
470470
var serviceProvider = CreateServiceProvider();
@@ -477,11 +477,11 @@ public async Task WebRootComponentManager_AddRootComponentAsync_Throws_IfKeyIsMa
477477
await webRootComponentManager.AddRootComponentAsync(
478478
0,
479479
typeof(TestComponent),
480-
"malformed-key",
480+
default, // Invalid key
481481
WebRootComponentParameters.Empty);
482482
});
483483

484-
Assert.Equal("The key 'malformed-key' had an invalid format.", ex.Message);
484+
Assert.Equal("An invalid component marker key was provided.", ex.Message);
485485
}
486486

487487
[Fact]
@@ -512,7 +512,7 @@ public async Task WebRootComponentManager_UpdateRootComponentAsync_Throws_IfSsrC
512512
var ex = await Assert.ThrowsAsync<InvalidOperationException>(async () =>
513513
{
514514
var webRootComponentManager = renderer.GetOrCreateWebRootComponentManager();
515-
await webRootComponentManager.UpdateRootComponentAsync(1, key.ToString(), WebRootComponentParameters.Empty);
515+
await webRootComponentManager.UpdateRootComponentAsync(1, key, WebRootComponentParameters.Empty);
516516
});
517517

518518
Assert.Equal($"No root component exists with SSR component ID 1.", ex.Message);
@@ -532,7 +532,7 @@ public async Task WebRootComponentManager_UpdateRootComponentAsync_Throws_IfKeyD
532532
var ex = await Assert.ThrowsAsync<InvalidOperationException>(async () =>
533533
{
534534
var webRootComponentManager = renderer.GetOrCreateWebRootComponentManager();
535-
await webRootComponentManager.UpdateRootComponentAsync(0, "invalid-key", WebRootComponentParameters.Empty);
535+
await webRootComponentManager.UpdateRootComponentAsync(0, new("1", null), WebRootComponentParameters.Empty);
536536
});
537537

538538
Assert.Equal("Cannot update components with mismatching keys.", ex.Message);
@@ -551,7 +551,7 @@ await renderer.Dispatcher.InvokeAsync(() =>
551551
{
552552
var webRootComponentManager = renderer.GetOrCreateWebRootComponentManager();
553553
var parameters = new Dictionary<string, object> { ["Name"] = "value" };
554-
webRootComponentManager.UpdateRootComponentAsync(0, key.ToString(), CreateWebRootComponentParameters(parameters));
554+
webRootComponentManager.UpdateRootComponentAsync(0, key, CreateWebRootComponentParameters(parameters));
555555
});
556556

557557
// Assert
@@ -570,7 +570,7 @@ public async Task WebRootComponentManager_UpdateRootComponentAsync_DoesNothing_I
570570
await renderer.Dispatcher.InvokeAsync(() =>
571571
{
572572
var webRootComponentManager = renderer.GetOrCreateWebRootComponentManager();
573-
webRootComponentManager.UpdateRootComponentAsync(0, key.ToString(), WebRootComponentParameters.Empty);
573+
webRootComponentManager.UpdateRootComponentAsync(0, key, WebRootComponentParameters.Empty);
574574
});
575575

576576
// Assert
@@ -590,7 +590,7 @@ await renderer.Dispatcher.InvokeAsync(() =>
590590
{
591591
var webRootComponentManager = renderer.GetOrCreateWebRootComponentManager();
592592
var parameters = new Dictionary<string, object> { ["Name"] = "value" };
593-
webRootComponentManager.UpdateRootComponentAsync(0, key.ToString(), CreateWebRootComponentParameters(parameters));
593+
webRootComponentManager.UpdateRootComponentAsync(0, key, CreateWebRootComponentParameters(parameters));
594594
});
595595

596596
// Assert
@@ -656,28 +656,29 @@ private TestRemoteRenderer GetRemoteRenderer(IServiceProvider serviceProvider, C
656656
{
657657
RootComponents =
658658
{
659-
MaxInteractiveServerRootComponentCount = MaxInteractiveServerRootComponentCount
659+
MaxJSRootComponents = MaxInteractiveServerRootComponentCount
660660
},
661661
},
662662
circuitClient ?? new CircuitClientProxy(),
663663
serverComponentDeserializer,
664664
NullLogger.Instance);
665665
}
666666

667-
private static Task<BoundaryMarkerKey> AddWebRootComponentAsync(RemoteRenderer renderer, int ssrComponentId, string componentKey = null)
667+
private static Task<ComponentMarkerKey> AddWebRootComponentAsync(RemoteRenderer renderer, int ssrComponentId, string componentKey = null)
668668
=> renderer.Dispatcher.InvokeAsync(async () =>
669669
{
670670
var webRootComponentManager = renderer.GetOrCreateWebRootComponentManager();
671-
var boundaryMarkerKey = new BoundaryMarkerKey(
672-
nameof(TestComponent).AsMemory(),
673-
ssrComponentId.ToString(CultureInfo.CurrentCulture).AsMemory(),
674-
componentKey?.AsMemory() ?? ReadOnlyMemory<char>.Empty);
671+
var componentMarkerKey = new ComponentMarkerKey()
672+
{
673+
LocationHash = ssrComponentId.ToString(CultureInfo.CurrentCulture),
674+
FormattedComponentKey = componentKey,
675+
};
675676
await webRootComponentManager.AddRootComponentAsync(
676677
ssrComponentId,
677678
typeof(TestComponent),
678-
boundaryMarkerKey.ToString(),
679+
componentMarkerKey,
679680
WebRootComponentParameters.Empty);
680-
return boundaryMarkerKey;
681+
return componentMarkerKey;
681682
});
682683

683684
private static WebRootComponentParameters CreateWebRootComponentParameters(IDictionary<string, object> parameters)

src/Components/Server/test/Circuits/ServerComponentDeserializerTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,8 +446,8 @@ private string SerializeMarkers(ComponentMarker[] markers) =>
446446
private ComponentMarker CreateMarker(Type type, Dictionary<string, object> parameters = null)
447447
{
448448
var serializer = new ServerComponentSerializer(_ephemeralDataProtectionProvider);
449-
var key = new BoundaryMarkerKey(type.FullName.AsMemory(), "0".AsMemory(), Memory<char>.Empty);
450-
var marker = ComponentMarker.Create(ComponentMarker.ServerMarkerType, false, key.ToString());
449+
var key = new ComponentMarkerKey(type.FullName, null);
450+
var marker = ComponentMarker.Create(ComponentMarker.ServerMarkerType, false, key);
451451
serializer.SerializeInvocation(
452452
ref marker,
453453
_invocationSequence,

0 commit comments

Comments
 (0)