{"record":{"id":"f49ee2caf5116fe9","repo":"dotnet/aspnetcore","slug":"the-custom-event-eventname-cannot-have-the-sa","errorCode":null,"errorMessage":"The custom event '${eventName}' cannot have the same name as its browserEventName '${options.browserEventName}'. Choose a different name for the custom event.","messagePattern":"The custom event '(.+?)' cannot have the same name as its browserEventName '(.+?)'\\. Choose a different name for the custom event\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/Components/Web.JS/src/Rendering/Events/EventTypes.ts","lineNumber":29,"sourceCode":"const createBlankEventArgsOptions: EventTypeOptions = { createEventArgs: () => ({}) };\n\nexport const eventNameAliasRegisteredCallbacks: ((aliasEventName: string, browserEventName) => void)[] = [];\n\nexport function registerCustomEventType(eventName: string, options: EventTypeOptions): void {\n  if (!options) {\n    throw new Error('The options parameter is required.');\n  }\n\n  // There can't be more than one registration for the same event name because then we wouldn't\n  // know which eventargs data to supply.\n  if (eventTypeRegistry.has(eventName)) {\n    throw new Error(`The event '${eventName}' is already registered.`);\n  }\n\n  // When aliasing a browser event, the custom event name must be different from the browser event name\n  // to avoid double-triggering (once for the browser event, once for the custom event wrapper)\n  if (options.browserEventName && eventName === options.browserEventName) {\n    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.`);\n  }\n\n  // If applicable, register this as an alias of the given browserEventName\n  if (options.browserEventName) {\n    const aliasGroup = browserEventNamesToAliases.get(options.browserEventName);\n    if (aliasGroup) {\n      aliasGroup.push(eventName);\n    } else {\n      browserEventNamesToAliases.set(options.browserEventName, [eventName]);\n    }\n\n    // For developer convenience, it's allowed to register the custom event type *after*\n    // some listeners for it are already present. Once the event name alias gets registered,\n    // we have to notify any existing event delegators so they can update their delegated\n    // events list.\n    eventNameAliasRegisteredCallbacks.forEach(callback => callback(eventName, options.browserEventName));\n  }\n","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/294cab2f9b2e03af6b953820c7ab497c3c8b7ad9/src/Components/Web.JS/src/Rendering/Events/EventTypes.ts#L11-L47","documentation":"Thrown by registerCustomEventType when a browserEventName alias is supplied and the custom eventName equals it. Aliasing wraps a native event; if both names match the handler would fire twice (once natively, once via the alias), so Blazor requires them to differ.","triggerScenarios":"Calling registerCustomEventType('paste', { browserEventName: 'paste', ... }) — same string for both the custom name and the aliased browser event.","commonSituations":"Author misunderstanding the alias feature (thinking you must name the custom event after the native one); copy-paste from docs where the names were meant to differ.","solutions":["Give the custom event a distinct name from its browserEventName (e.g. custom 'custompaste' aliasing 'paste').","If you don't need aliasing, omit browserEventName entirely."],"exampleFix":"// before\nBlazor.registerCustomEventType('paste', { browserEventName: 'paste', createEventArgs: e => ({}) });\n\n// after\nBlazor.registerCustomEventType('custompaste', { browserEventName: 'paste', createEventArgs: e => ({}) });","handlingStrategy":"validation","validationCode":"// Ensure custom name differs from aliased browser event.\nfunction registerAlias(custom: string, browser: string, opts: EventTypeOptions) {\n  if (custom === browser) throw new Error('custom name must differ from browserEventName');\n  Blazor.registerCustomEventType(custom, { ...opts, browserEventName: browser });\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Namespace custom event names (e.g. 'myapp:paste') to avoid clashing with the aliased native event.","Omit browserEventName if you don't actually need aliasing."],"tags":["blazor","events","custom-event","validation"],"analyzedSha":"294cab2f9b2e03af6b953820c7ab497c3c8b7ad9","analyzedAt":"2026-08-06T20:08:02.189Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}