Repository navigation
Conversation
|
Thanks for your PR, @Yuvan111. Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Add browser regression coverage for null callbacks not being dispatched or causing re-renders.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 1
What changed in this PR
This PR prevents Blazor from registering event handlers when their callbacks have no delegate.
Changes:
- Adds
HasDelegatechecks for typed and untyped event callbacks. - Adds unit tests verifying null callbacks are omitted.
| File | Summary |
|---|---|
src/Components/Components/test/Rendering/RenderTreeBuilderTest.cs |
Tests omission of event frames for null callbacks. |
src/Components/Components/src/Rendering/RenderTreeBuilder.cs |
Skips registering event handlers without delegates. |
|
Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime. |
There was a problem hiding this comment.
Written with GitHub Copilot (AI), which did the code reading and the local test runs described below ("I" refers to those runs). Posted by PureWeen.
Looked at this again at 20f98aa. Unfortunately I don't think it fixes #18118 yet, and one part of the change regresses; details inline.
I ran the Components tests locally (all green at head), and then wrote small repro tests against both the merge-base and this head:
- A null delegate bound through
EventCallback.Factory.Create(this, ...)still gets a frame and a registered handler at both, and clicking still re-renders. So the scenario in the issue isn't changed. - Boxed receiver-only null callbacks through the
object/@attributespath were dropped at the merge-base and now register a handler. That's the regression.
No test in the PR fails before and passes after the change, including the E2E one (inline). The PR description also still describes an earlier version of the change.
I didn't run the E2E tests (no browser available on my machine).
|
Thanks @PureWeen . Addressed all review feedback by restoring HasDelegate-based checks across typed and boxed EventCallback paths, ensuring receiver-only callbacks with null delegates are correctly omitted. Added unit coverage proving the regression and validating the fix across typed, untyped, and boxed callback scenarios. Updated the E2E test to reproduce the original scenario using a nullable Action bound through Razor instead of default(EventCallback). The test now verifies browser event registration directly, confirming no handlers are registered when the delegate is null and that registration occurs once the delegate is enabled. |

Skip registering event handlers when delegate is null
Description
This change prevents Blazor from registering event handlers that require an explicit receiver when no delegate is assigned. Previously, events such as onmousemove could still be included in the render tree when the callback was null, resulting in unnecessary event dispatching and potential re-renders. The condition has been updated from value.RequiresExplicitReceiver to value.RequiresExplicitReceiver && value.HasDelegate, ensuring that only valid event handlers are registered and reducing unnecessary client-server event traffic for optional event callbacks.
Fixes #18118