dotnet / razor

Compiler and tooling experience for Razor ASP.NET Core apps in Visual Studio, Visual Studio for Mac, and VS Code.
https://asp.net
MIT License
505 stars 195 forks source link

Using SDK 9.0.100-rc.1 no longer possible to have custom attribute with similar to a property name however with different casing #10880

Closed enchev closed 2 months ago

enchev commented 2 months ago

The following custom component cannot be compiled using .NET SDK 9.0.100-rc.1: CustomComponent.razor

<input  @attributes="Attributes" />

@code {
    [Parameter(CaptureUnmatchedValues = true)]
    public IReadOnlyDictionary<string, object> Attributes { get; set; }

    [Parameter]
    public bool AutoComplete { get; set; }
}

Home.razor

@page "/"

@rendermode InteractiveServer

<PageTitle>Home</PageTitle>

<h1>Hello, world!</h1>

Welcome to your new app.

<CustomComponent autocomplete="off" />

image

Adding global.json to the project referring to .NET 8 will enable normal compilation:

{
  "sdk": {
    "version": "8.0.201"
  }
}

image

jjonescz commented 2 months ago

This is due to a bug fix in the razor compiler: https://github.com/dotnet/razor/issues/8854 - component parameters are now case insensitive at compile-time (they were always case insensitive at runtime).

But I think your example never worked at runtime - it results in:

image

I'm not sure what you are trying to achieve, but because Blazor matches component parameters case-insensitively, the autocomplete=off won't be passed to the IReadOnlyDictionary<string, object> Attributes when you also have [Parameter] public bool AutoComplete { get; set; }.