{
  "id": "react/duplicate-key-in-list",
  "signature": "Warning: Encountered two children with the same key, `duplicate`. Keys should be unique so that components maintain their identity across updates. Non-unique keys may cause children to be duplicated and/or omitted — the behavior is unsupported and could change in a future version.",
  "signature_zh": "警告：遇到两个具有相同键 `duplicate` 的子元素。键应该是唯一的，以便组件在更新时保持其身份。非唯一键可能导致子元素重复和/或遗漏——此行为不受支持，并可能在将来版本中更改。",
  "regex": "Encountered two children with the same key, `[^`]+`",
  "domain": "react",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "When rendering a list with .map(), two or more items have the same key prop, violating the requirement that keys must be unique among siblings.",
  "root_cause_type": "generic",
  "root_cause_zh": "当使用 .map() 渲染列表时，两个或多个项目具有相同的 key prop，违反了键在同级元素中必须唯一的要求。",
  "versions": [
    {
      "version": "React 16.8+",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "React 17.0.2",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "React 18.2.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Using the array index as the key",
      "why_fails": "While this suppresses the warning, using index as key can cause incorrect component behavior if the list order changes (e.g., sorting, filtering).",
      "fail_rate": 0.4,
      "condition": "",
      "sources": []
    },
    {
      "action": "Generating a random key on each render (e.g., Math.random())",
      "why_fails": "Random keys cause React to remount all components on every render, losing state and causing performance degradation.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "Concatenating index with another value (e.g., key={`${index}-${item.id}`})",
      "why_fails": "This works if item.id is unique, but if not, the concatenation may still produce duplicates. Better to use a truly unique identifier.",
      "fail_rate": 0.3,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Use a unique identifier from your data as the key: data.map(item => <Component key={item.id} />). If no unique ID exists, generate one when data is created (e.g., using uuid).",
      "success_rate": 0.95,
      "how": "Use a unique identifier from your data as the key: data.map(item => <Component key={item.id} />). If no unique ID exists, generate one when data is created (e.g., using uuid).",
      "condition": "",
      "sources": []
    },
    {
      "action": "If the data has duplicate IDs, deduplicate the array before rendering: const uniqueData = Array.from(new Map(data.map(item => [item.id, item])).values());",
      "success_rate": 0.85,
      "how": "If the data has duplicate IDs, deduplicate the array before rendering: const uniqueData = Array.from(new Map(data.map(item => [item.id, item])).values());",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Use a unique identifier from your data as the key: data.map(item => <Component key={item.id} />). If no unique ID exists, generate one when data is created (e.g., using uuid).",
    "If the data has duplicate IDs, deduplicate the array before rendering: const uniqueData = Array.from(new Map(data.map(item => [item.id, item])).values());"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://reactjs.org/docs/lists-and-keys.html#keys",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.95,
  "resolvable": "true",
  "first_seen": "2023-07-01",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}