-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Conversation
Thanks for your PR, @JelleHissink. Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
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. |
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. |
@@ -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)); |
There was a problem hiding this comment.
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)
.
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
/azp run aspnetcore-ci |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run aspnetcore-quarantined-pr |
Azure Pipelines successfully started running 1 pipeline(s). |
Thanks for picking this up! |
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)