{"record":{"id":"4d85322c9ae826cc","repo":"facebook/lexical","slug":"lexical-duplicate-domimportrule-name-rule-nam","errorCode":null,"errorMessage":"[lexical] duplicate DOMImportRule name \"${rule.name}\" — keep names unique to aid debugging.","messagePattern":"\\[lexical\\] duplicate DOMImportRule name \"(.+?)\" — keep names unique to aid debugging\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/lexical-html/src/import/compileImportRules.ts","lineNumber":84,"sourceCode":" * contributor occupy the lowest indices.\n *\n * @internal\n */\nexport function compileImportRules(\n  rules: readonly AnyDOMImportRule[],\n): CompiledDispatch {\n  const compiled: CompiledRule[] = [];\n  const byTag = new Map<string, number[]>();\n  const wildcardIndices: number[] = [];\n  const textIndices: number[] = [];\n  const commentIndices: number[] = [];\n  const seenNames = new Set<string>();\n\n  rules.forEach((rule, i) => {\n    const sel = getSelectorImpl(rule.match);\n    const name = rule.name || defaultRuleName(sel, i);\n    if (__DEV__ && typeof rule.name === 'string' && seenNames.has(rule.name)) {\n      console.warn(\n        `[lexical] duplicate DOMImportRule name \"${rule.name}\" — keep names unique to aid debugging.`,\n      );\n    }\n    if (rule.name) {\n      seenNames.add(rule.name);\n    }\n    compiled.push({\n      $import: rule.$import as DOMImportFn<\n        Node,\n        Record<string, RegExpMatchArray>\n      >,\n      name,\n      predicate: sel.predicate,\n    });\n\n    if (sel.kind === 'text') {\n      textIndices.push(i);\n    } else if (sel.kind === 'comment') {","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/facebook/lexical/blob/76a22dcba981b46119fcec45f935270707e26a57/packages/lexical-html/src/import/compileImportRules.ts#L66-L102","documentation":"compileImportRules() emits a console.warn when two DOMImportRule entries share the same explicit `name`. Names only exist to make debugging (rule attribution in devtools/logs) easier, so a duplicate means two rules are indistinguishable during debugging. The rules still compile and run; only the diagnostic value is lost.","triggerScenarios":"Calling compileImportRules (directly or via dispatch/defineOverlayRules) with an array of rules where at least two rules have the same non-empty `name` string; the __DEV__-only check dedupes via a Set of seen names.","commonSituations":"Spreading/concatenating rule arrays from two modules that both define a rule named e.g. 'image'; copy-pasting a rule and forgetting to rename it; programmatic rule generation that reuses a fixed name.","solutions":["Rename one of the duplicate rules so every rule has a unique `name`.","If names are generated, include the index or selector in the name to guarantee uniqueness (the fallback defaultRuleName(sel, i) does this).","If the name adds no value, omit `name` and let the default unique name be generated.","This is only a dev warning — for production builds (__DEV__ false) no warning is emitted; still fix the duplication for debuggability."],"exampleFix":"// before\nconst rules = [\n  {name: 'image', match: 'img', ...},\n  {name: 'image', match: 'img[data-src]', ...},\n];\n// after\nconst rules = [\n  {name: 'image', match: 'img', ...},\n  {name: 'image-data-src', match: 'img[data-src]', ...},\n];","handlingStrategy":"validation","validationCode":"const names = rules.filter(r => r.name).map(r => r.name);\nconst dupes = names.filter((n, i) => names.indexOf(n) !== i);\nif (dupes.length) throw new Error(`Duplicate DOMImportRule names: ${[...new Set(dupes)].join(', ')}`);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Give each rule a unique, descriptive name derived from its selector or purpose.","Add a dev-time assertion/test that iterates your rule list and asserts name uniqueness.","Omit `name` when it carries no debugging value so defaults are used."],"tags":["console-warning","dev-only","import-rules","debugging"],"backgroundTag":"duplicate-identifier","analyzedSha":"76a22dcba981b46119fcec45f935270707e26a57","analyzedAt":"2026-08-31T21:45:54.792Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}