From 391f01c603e9d936fdbfd652c77532d0082b0cd1 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 15 Dec 2025 13:56:29 +0000 Subject: [PATCH 1/3] Initial plan From f21a4ac3550ee23ca29f31d354b5e6b902b0e45f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 15 Dec 2025 14:02:01 +0000 Subject: [PATCH 2/3] Add validation to prevent custom events with same name as browser events Co-authored-by: javiercn <6995051+javiercn@users.noreply.github.com> --- .../Web.JS/src/Rendering/Events/EventTypes.ts | 6 ++++++ .../test/E2ETest/Tests/EventCustomArgsTest.cs | 11 +++++++++++ .../BasicTestApp/EventCustomArgsComponent.razor | 9 +++++++++ 3 files changed, 26 insertions(+) diff --git a/src/Components/Web.JS/src/Rendering/Events/EventTypes.ts b/src/Components/Web.JS/src/Rendering/Events/EventTypes.ts index 89eb799ed3b9..e2cdef267a20 100644 --- a/src/Components/Web.JS/src/Rendering/Events/EventTypes.ts +++ b/src/Components/Web.JS/src/Rendering/Events/EventTypes.ts @@ -23,6 +23,12 @@ export function registerCustomEventType(eventName: string, options: EventTypeOpt throw new Error(`The event '${eventName}' is already registered.`); } + // When aliasing a browser event, the custom event name must be different from the browser event name + // to avoid double-triggering (once for the browser event, once for the custom event wrapper) + if (options.browserEventName && eventName === options.browserEventName) { + throw new Error(`The custom event '${eventName}' cannot have the same name as its browserEventName '${options.browserEventName}'. Choose a different name for the custom event.`); + } + // If applicable, register this as an alias of the given browserEventName if (options.browserEventName) { const aliasGroup = browserEventNamesToAliases.get(options.browserEventName); diff --git a/src/Components/test/E2ETest/Tests/EventCustomArgsTest.cs b/src/Components/test/E2ETest/Tests/EventCustomArgsTest.cs index a5a236a67585..a0bafe47d750 100644 --- a/src/Components/test/E2ETest/Tests/EventCustomArgsTest.cs +++ b/src/Components/test/E2ETest/Tests/EventCustomArgsTest.cs @@ -170,6 +170,17 @@ public void CanRegisterCustomEventAndSupplyComplexParams() line => Assert.Equal("Event with IJSObjectReference received: Hello!", line)); } + [Fact] + public void ThrowsErrorWhenEventNameMatchesBrowserEventName() + { + // Attempt to register a custom event with the same name as the browser event + Browser.Exists(By.Id("register-invalid-same-name-event")).Click(); + + // Verify that an error is thrown + var errorMessage = Browser.Exists(By.Id("same-name-event-error")).Text; + Assert.Contains("cannot have the same name as its browserEventName", errorMessage); + } + void SendKeysSequentially(IWebElement target, string text) { foreach (var c in text) diff --git a/src/Components/test/testassets/BasicTestApp/EventCustomArgsComponent.razor b/src/Components/test/testassets/BasicTestApp/EventCustomArgsComponent.razor index 805cf82b9ff6..ec2f6781f573 100644 --- a/src/Components/test/testassets/BasicTestApp/EventCustomArgsComponent.razor +++ b/src/Components/test/testassets/BasicTestApp/EventCustomArgsComponent.razor @@ -60,6 +60,15 @@ onclick="Blazor.registerCustomEventType('custommouseover', { browserEventName: 'mouseover' })"> Register custom mouseover event (which has no corresponding native listener) + + +

+ +

+

From bee2de4e64819679ef4c48ab9c0a241252ef6006 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 15 Dec 2025 14:12:23 +0000 Subject: [PATCH 3/3] Fix test to use non-pre-registered event name Co-authored-by: javiercn <6995051+javiercn@users.noreply.github.com> --- .../test/testassets/BasicTestApp/EventCustomArgsComponent.razor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Components/test/testassets/BasicTestApp/EventCustomArgsComponent.razor b/src/Components/test/testassets/BasicTestApp/EventCustomArgsComponent.razor index ec2f6781f573..b7afb2d5d192 100644 --- a/src/Components/test/testassets/BasicTestApp/EventCustomArgsComponent.razor +++ b/src/Components/test/testassets/BasicTestApp/EventCustomArgsComponent.razor @@ -62,7 +62,7 @@