{"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":null,"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/3600ca084e9c8b5f4174fc5e747f4c52d2100806/src/Components/Web.JS/src/Rendering/Events/EventTypes.ts#L11-L47","documentation":"Thrown by registerCustomEventType when options.browserEventName is set and equals eventName. Blazor aliases a browser event by wrapping it; if the custom name matches the browser name the handler fires twice (once for the native event, once for the wrapper). The check explicitly prevents this double-trigger.","triggerScenarios":"Calling registerCustomEventType('click', { browserEventName: 'click', ... }) or any pair where the first arg equals options.browserEventName.","commonSituations":"Developer wants to 'extend' a native event and reuses its name by mistake; copy-pasting a registration and forgetting to rename the custom event.","solutions":["Choose a distinct custom event name that differs from the browserEventName (e.g. 'customclick' wrapping 'click').","If you don't actually need aliasing, omit browserEventName entirely.","Document the chosen custom name so consumers reference it via @oneventname."],"exampleFix":"// before (throws)\nregisterCustomEventType('click', { browserEventName: 'click', createEventArgs: e => ({ x: e.clientX }) });\n\n// after\nregisterCustomEventType('customclick', { browserEventName: 'click', createEventArgs: e => ({ x: e.clientX }) });\n// in Razor: @oncustomclick=\"...\"","handlingStrategy":"validation","validationCode":"function registerAlias(customName: string, browserName: string, options: EventTypeOptions) {\n  if (customName === browserName) {\n    throw new Error(`Custom name '${customName}' must differ from browserEventName '${browserName}'.`);\n  }\n  registerCustomEventType(customName, { ...options, browserEventName: browserName });\n}","typeGuard":"function isValidAlias(customName: string, browserName?: string): boolean {\n  return !browserName || customName !== browserName;\n}","tryCatchPattern":null,"preventionTips":["Always pick a distinct custom event name when aliasing a browser event.","Omit browserEventName entirely if you are not aliasing.","Add a unit test asserting customName !== browserEventName."],"tags":["blazor","events","aliasing","configuration"],"backgroundTag":null,"analyzedSha":"3600ca084e9c8b5f4174fc5e747f4c52d2100806","analyzedAt":"2026-08-11T16:32:30.678Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}