dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.43k stars 10.02k forks source link

Blazor - (client side) the "guid" Route Constraint forces the component execute for every single click #19008

Closed royzhang666 closed 1 year ago

royzhang666 commented 4 years ago

Describe the bug

When using the guid RouteConstraint in client-side blazor, the component will be executed with every single mouse click which is in-efficient. This issue does not happen for datetime route constraint.

To Reproduce

  1. Using the latest version of Asp.NET Core 3.1
  2. Run this blazor component (with the height style included)
    
    @page "/user/{Id:guid}"

@{ Console.WriteLine("test execution"); }

@code { [Parameter] public Guid Id { get; set; } }


3. click within the page
4. "test execution" outputs for every mouse click

This issue does not reproduce for **datetime** constraint.

### Screenshots
![image](https://user-images.githubusercontent.com/17616236/74444714-3ba37480-4eb0-11ea-8e78-182a087700d3.png)
mkArtakMSFT commented 4 years ago

Thanks for contacting us. We will investigate this if we hear more similar feedback.

doveryai commented 3 years ago

Possibly related to how Guids are interpreted:

I have a Razor component with the following parameter:

    [Parameter]
    public Guid PropertyId { get; set; }

The component is consumed within a list control (Virtualize)

    <Virtualize Items="@SelectedProperties">
        <My.Web.Components.PropertyHeader PropertyId="@context.PropertyId"></My.Web.Components.PropertyHeader>
    </Virtualize>

context.PropertyId is also a Guid and the code compiles and runs fine, but Visual Studio (2019 Pro) complains (false negative):

Error   CS1662  Cannot convert lambda expression to intended delegate type because some of the return types in the block are not implicitly convertible to the delegate return type My.Web  C:\Users\xxxxxxxx\source\repos\xxxxxxx\xxxxxx\My.Web\Pages\PropertySearch.razor 1   Active
Error   CS1503  Argument 1: cannot convert from 'System.Guid' to 'int'  Myreta.Web  C:\Users\xxxxxxxx\source\repos\xxxxxxx\xxxxxx\My.Web\Pages\PropertySearch.razor 38  Active
javiercn commented 1 year ago

@royzhang666 this has likely been addressed in .NET 8.0, try out the latest build and feel free to reopen the issue if you are still observing this behavior.