Skip to content

Better implementation of EventCallback.Equals #53395

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 28, 2025

Conversation

JelleHissink
Copy link
Contributor

We noticed after upgrading our blazor application to .net 8.0 that some EventCallback keep being modified. Eventhough the value was the same, the same target component, the same method.

The generated code that renders the component seems to fabricate a new MulticastDelegate, having the same Type, Target and Method. The implementation of EventCallback uses Object.ReferenceEquals, so it concludes it is different every render.

Fixes #53361

NOTE

I recreated this because I have some difficulties changing the pr to go to main (#53362)

@JelleHissink JelleHissink requested a review from a team as a code owner January 15, 2024 19:22
@dotnet-issue-labeler dotnet-issue-labeler bot added the area-blazor Includes: Blazor, Razor Components label Jan 15, 2024
@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Jan 15, 2024
@ghost
Copy link

ghost commented Jan 15, 2024

Thanks for your PR, @JelleHissink. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@SteveSandersonMS
Copy link
Member

Thanks @JelleHissink!

Since this change will cause some components to re-render less often (which is a good thing), it would be ideal to also have an E2E test showing a case where a re-render is avoided by this change, and perhaps another showing that it is still possible to change an event handler to force a re-render. I appreciate it's not obvious how to do that and you might not wish to take it on, so this is something we can add if you prefer.

@JelleHissink
Copy link
Contributor Author

I did not manage to get the whole testsuite running on my machine. If there is somebody else who could take this on that would be great.

@ghost ghost added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Jan 26, 2024
@@ -80,5 +80,5 @@ public override int GetHashCode()
public override bool Equals(object? obj)
=> obj is EventCallback other
&& ReferenceEquals(Receiver, other.Receiver)
&& ReferenceEquals(Delegate, other.Delegate);
&& (Delegate?.Equals(other.Delegate) ?? (other.Delegate == null));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

object.Equals(a, b) performs null handling and delegates to a.Equals(b).

@wtgodbe wtgodbe removed the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 13, 2024
@dotnet-policy-service dotnet-policy-service bot added the area-infrastructure Includes: MSBuild projects/targets, build scripts, CI, Installers and shared framework label Feb 13, 2024
@dotnet dotnet deleted a comment Feb 13, 2024
@wtgodbe wtgodbe removed the area-infrastructure Includes: MSBuild projects/targets, build scripts, CI, Installers and shared framework label Feb 13, 2024
@dotnet-policy-service dotnet-policy-service bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 20, 2024
@lewing
Copy link
Member

lewing commented Jan 22, 2025

/azp run

@dotnet-policy-service dotnet-policy-service bot removed the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Jan 22, 2025
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@javiercn
Copy link
Member

/azp run aspnetcore-ci

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@javiercn
Copy link
Member

/azp run aspnetcore-quarantined-pr

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@javiercn javiercn added the pending-merge PR is scheduled to get merged at a convenient time label Jan 24, 2025
@javiercn javiercn merged commit b3de619 into dotnet:main Jan 28, 2025
25 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the 10.0-preview2 milestone Jan 28, 2025
@JelleHissink JelleHissink deleted the eventcallback-equals branch January 28, 2025 19:54
@JelleHissink
Copy link
Contributor Author

Thanks for picking this up!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components community-contribution Indicates that the PR has been added by a community member pending-merge PR is scheduled to get merged at a convenient time
Projects
None yet
Development

Successfully merging this pull request may close these issues.

EventCallback.Equals is not giving correct results
6 participants