From 70deb390fdc1f8b0c5e03cb2a331e28a9679a46f Mon Sep 17 00:00:00 2001 From: Pranav K Date: Tue, 18 Jan 2022 10:48:10 -0800 Subject: [PATCH] Changes per PR feedback --- .../src/RazorComponents/ComponentRenderer.cs | 4 ++-- .../src/RazorComponents/InvokedRenderModes.cs | 11 ++++++++++- .../Mvc.ViewFeatures/src/ServerComponentSerializer.cs | 5 +++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Mvc/Mvc.ViewFeatures/src/RazorComponents/ComponentRenderer.cs b/src/Mvc/Mvc.ViewFeatures/src/RazorComponents/ComponentRenderer.cs index 4ef9ca1756d4..8ff7c8af3c9f 100644 --- a/src/Mvc/Mvc.ViewFeatures/src/RazorComponents/ComponentRenderer.cs +++ b/src/Mvc/Mvc.ViewFeatures/src/RazorComponents/ComponentRenderer.cs @@ -181,7 +181,7 @@ private IHtmlContent NonPrerenderedServerComponent(HttpContext context, ServerCo var currentInvocation = _serverComponentSerializer.SerializeInvocation(invocationId, type, parametersCollection, prerendered: false); - var viewBuffer = new ViewBuffer(_viewBufferScope, nameof(ComponentRenderer), 16); // Preamble is fixed size + var viewBuffer = new ViewBuffer(_viewBufferScope, nameof(ComponentRenderer), ServerComponentSerializer.PreambleBufferSize); ServerComponentSerializer.AppendPreamble(viewBuffer, currentInvocation); return viewBuffer; } @@ -189,7 +189,7 @@ private IHtmlContent NonPrerenderedServerComponent(HttpContext context, ServerCo private IHtmlContent NonPrerenderedWebAssemblyComponent(HttpContext context, Type type, ParameterView parametersCollection) { var currentInvocation = WebAssemblyComponentSerializer.SerializeInvocation(type, parametersCollection, prerendered: false); - var viewBuffer = new ViewBuffer(_viewBufferScope, nameof(ComponentRenderer), 16); // Preamble is fixed size + var viewBuffer = new ViewBuffer(_viewBufferScope, nameof(ComponentRenderer), ServerComponentSerializer.PreambleBufferSize); WebAssemblyComponentSerializer.AppendPreamble(viewBuffer, currentInvocation); return viewBuffer; } diff --git a/src/Mvc/Mvc.ViewFeatures/src/RazorComponents/InvokedRenderModes.cs b/src/Mvc/Mvc.ViewFeatures/src/RazorComponents/InvokedRenderModes.cs index 3eb4e37e0d8a..ad44136bdd63 100644 --- a/src/Mvc/Mvc.ViewFeatures/src/RazorComponents/InvokedRenderModes.cs +++ b/src/Mvc/Mvc.ViewFeatures/src/RazorComponents/InvokedRenderModes.cs @@ -1,6 +1,8 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using Microsoft.AspNetCore.Mvc.Rendering; + namespace Microsoft.AspNetCore.Mvc.ViewFeatures; internal sealed class InvokedRenderModes @@ -12,11 +14,18 @@ public InvokedRenderModes(Mode mode) public Mode Value { get; set; } + /// + /// Tracks for components. + /// internal enum Mode { None, Server, WebAssembly, + + /// + /// Tracks an app that has both components rendered both on the Server and WebAssembly. + /// ServerAndWebAssembly } } diff --git a/src/Mvc/Mvc.ViewFeatures/src/ServerComponentSerializer.cs b/src/Mvc/Mvc.ViewFeatures/src/ServerComponentSerializer.cs index 335b8f81716d..677264a1b7c7 100644 --- a/src/Mvc/Mvc.ViewFeatures/src/ServerComponentSerializer.cs +++ b/src/Mvc/Mvc.ViewFeatures/src/ServerComponentSerializer.cs @@ -11,6 +11,8 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures; // See the details of the component serialization protocol in ServerComponentDeserializer.cs on the Components solution. internal class ServerComponentSerializer { + public const int PreambleBufferSize = 3; + private readonly ITimeLimitedDataProtector _dataProtector; public ServerComponentSerializer(IDataProtectionProvider dataProtectionProvider) => @@ -46,6 +48,9 @@ public ServerComponentMarker SerializeInvocation(ServerComponentInvocationSequen return (serverComponent.Sequence, Convert.ToBase64String(protectedBytes)); } + /// + /// Remember to update if the number of entries being appended in this function changes. + /// internal static void AppendPreamble(IHtmlContentBuilder htmlContentBuilder, ServerComponentMarker record) { var serializedStartRecord = JsonSerializer.Serialize(