Skip to content

Commit

Permalink
Changes per PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
pranavkm committed Jan 18, 2022
1 parent ad2ec25 commit 70deb39
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,15 @@ 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;
}

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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -12,11 +14,18 @@ public InvokedRenderModes(Mode mode)

public Mode Value { get; set; }

/// <summary>
/// Tracks <see cref="RenderMode"/> for components.
/// </summary>
internal enum Mode
{
None,
Server,
WebAssembly,

/// <summary>
/// Tracks an app that has both components rendered both on the Server and WebAssembly.
/// </summary>
ServerAndWebAssembly
}
}
5 changes: 5 additions & 0 deletions src/Mvc/Mvc.ViewFeatures/src/ServerComponentSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down Expand Up @@ -46,6 +48,9 @@ public ServerComponentMarker SerializeInvocation(ServerComponentInvocationSequen
return (serverComponent.Sequence, Convert.ToBase64String(protectedBytes));
}

/// <remarks>
/// Remember to update <see cref="PreambleBufferSize"/> if the number of entries being appended in this function changes.
/// </remarks>
internal static void AppendPreamble(IHtmlContentBuilder htmlContentBuilder, ServerComponentMarker record)
{
var serializedStartRecord = JsonSerializer.Serialize(
Expand Down

0 comments on commit 70deb39

Please sign in to comment.