{"record":{"id":"5a427c98796e7f17","repo":"dotnet/aspnetcore","slug":"the-event-eventname-is-already-registered","errorCode":null,"errorMessage":"The event '${eventName}' is already registered.","messagePattern":"The event '(.+?)' is already registered\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/Components/Web.JS/src/Rendering/Events/EventTypes.ts","lineNumber":23,"sourceCode":"  browserEventName?: string;\n  createEventArgs?: (event: Event) => unknown;\n}\n\nconst eventTypeRegistry: Map<string, EventTypeOptions> = new Map();\nconst browserEventNamesToAliases: Map<string, string[]> = new Map();\nconst 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*","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/294cab2f9b2e03af6b953820c7ab497c3c8b7ad9/src/Components/Web.JS/src/Rendering/Events/EventTypes.ts#L5-L41","documentation":"Thrown by registerCustomEventType when eventName already exists in the eventTypeRegistry. Each event name maps to exactly one createEventArgs function; a second registration would be ambiguous, so it is rejected. Built-in DOM events (click, input, etc.) are pre-registered at module load.","triggerScenarios":"Calling registerCustomEventType with a name you already registered, or with a name that collides with a built-in event (e.g. 'click', 'change', 'input').","commonSituations":"Registering the same custom event in a module that loads twice (HMR); naming a custom event after a native DOM event; library + app both registering the same event name.","solutions":["Choose a unique, non-native event name (e.g. 'myapp:custom' rather than 'click').","Guard against double-registration in HMR by checking before registering, or moving registration to a single init module.","Avoid shadowing built-in event names listed in EventTypes.ts."],"exampleFix":"// before\nBlazor.registerCustomEventType('click', { ... }); // collides with built-in\n\n// after\nBlazor.registerCustomEventType('myapp:click', { ... });","handlingStrategy":"validation","validationCode":"// Check before registering to avoid duplicate/HMR double-register.\nif (!isRegistered('myevent')) {\n  Blazor.registerCustomEventType('myevent', { createEventArgs: e => ({}) });\n}","typeGuard":null,"tryCatchPattern":"try { Blazor.registerCustomEventType(name, opts); }\ncatch (e) {\n  if (/already registered/i.test(e.message)) return; // idempotent on HMR\n  throw e;\n}","preventionTips":["Use unique custom event names that don't collide with native DOM events.","Centralize registration in one module to avoid double-loads under HMR.","Guard with an 'already registered' check before re-registering."],"tags":["blazor","events","custom-event","duplicate"],"analyzedSha":"294cab2f9b2e03af6b953820c7ab497c3c8b7ad9","analyzedAt":"2026-08-06T20:08:02.189Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}