Skip to content

Prevent InvokeVoidAsync Return Value Serialization #35929

@TanayParikh

Description

@TanayParikh

Background and Motivation

Currently we serialize return results for a InvokeVoidAsync call from .NET to JS. Given .NET is expecting a void result, we have no need to serialize these results. Removing this reduces data overhead and avoids issues with unserializable results (ex. window due to circular references).

This proposal adds a new enum value and empty interface which allows us to indicate return values from JS aren't to be serialized.

Proposed API

namespace Microsoft.JSInterop
{
    /// <summary>
    /// Describes the type of result expected from a JS interop call.
    /// </summary>
    public enum JSCallResultType : int
    {
        Default = 0,
        JSObjectReference = 1,
        JSStreamReference = 2,
+       JSVoidResult = 3,
    }
}
namespace Microsoft.JSInterop
{
+     public interface IJSVoidResult
+     {
+     }
}

Usage Examples

This wouldn't change developer interaction with the code, the changes are primarily internal. Public APIs are needed for testability and cross-project (src/Components) accessibility.

Alternative Designs

Using a public sealed class JSVoidResult, however we'd still need to make the constructor public (or at the very least non-private) for use in testing / mocking given it's a sealed class. Also by going the interface route, we maintain consistency with the other JSResultTypes which each have associated interfaces.

Risks

Minor change mostly to deal with how the framework internally handles InvokeVoidAsync.

Metadata

Metadata

Assignees

Labels

DoneThis issue has been fixedapi-approvedAPI was approved in API review, it can be implementedarea-blazorIncludes: Blazor, Razor ComponentsenhancementThis issue represents an ask for new feature or an enhancement to an existing onefeature-blazor-jsinteropThis issue is related to JSInterop in Blazor

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions