{
  "id": "react/memo-wrong-comparison",
  "signature": "Warning: React.memo: The comparison function returned true for props that are not equal. This may cause the component to skip rendering when it should update.",
  "signature_zh": "警告：React.memo：比较函数对不相等的 props 返回了 true。这可能导致组件在需要更新时跳过渲染。",
  "regex": "React.memo: The comparison function returned true for props that are not equal",
  "domain": "react",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "A custom comparison function passed to React.memo incorrectly returns true (equal) for props that are actually different, causing the component to skip re-renders when it should update.",
  "root_cause_type": "generic",
  "root_cause_zh": "传递给 React.memo 的自定义比较函数对实际上不同的 props 错误地返回 true（相等），导致组件在应该更新时跳过了重新渲染。",
  "versions": [
    {
      "version": "React 16.6+",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "React 17.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "React 18.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Shallow comparison may still miss deep changes, and the warning indicates the custom function is buggy, not that shallow is better.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "JSON.stringify is slow and can produce false positives for object key order; also triggers the same warning if not careful.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Defeats the purpose of memoization and may cause performance issues, but does not fix the underlying logic error.",
      "fail_rate": 0.65,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Fix the comparison function to correctly compare all relevant props. Example: const MyComponent = React.memo(Comp, (prevProps, nextProps) => { return prevProps.id === nextProps.id && prevProps.name === nextProps.name; }); Ensure it returns false when props differ.",
      "success_rate": 0.92,
      "how": "Fix the comparison function to correctly compare all relevant props. Example: const MyComponent = React.memo(Comp, (prevProps, nextProps) => { return prevProps.id === nextProps.id && prevProps.name === nextProps.name; }); Ensure it returns false when props differ.",
      "condition": "",
      "sources": []
    },
    {
      "action": "If the component relies on deep equality, use a library like lodash.isEqual for the comparison: import isEqual from 'lodash.isequal'; React.memo(Comp, isEqual);",
      "success_rate": 0.88,
      "how": "If the component relies on deep equality, use a library like lodash.isEqual for the comparison: import isEqual from 'lodash.isequal'; React.memo(Comp, isEqual);",
      "condition": "",
      "sources": []
    },
    {
      "action": "Remove the custom comparison function and let React.memo use default shallow comparison, but ensure props are immutable references.",
      "success_rate": 0.8,
      "how": "Remove the custom comparison function and let React.memo use default shallow comparison, but ensure props are immutable references.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Fix the comparison function to correctly compare all relevant props. Example: const MyComponent = React.memo(Comp, (prevProps, nextProps) => { return prevProps.id === nextProps.id && prevProps.name === nextProps.name; }); Ensure it returns false when props differ.",
    "If the component relies on deep equality, use a library like lodash.isEqual for the comparison: import isEqual from 'lodash.isequal'; React.memo(Comp, isEqual);",
    "Remove the custom comparison function and let React.memo use default shallow comparison, but ensure props are immutable references."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://reactjs.org/docs/react-api.html#reactmemo",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.9,
  "resolvable": "true",
  "first_seen": "2023-08-05",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}