diff --git a/CHANGELOG.md b/CHANGELOG.md index 8bc96b2e46..826696a029 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange ## Unreleased +### Fixed +* [`jsx-no-leaked-render`]: prevent wrongly adding parens ([#3700][] @developer-bandi) + +[#3700]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3700 + ## [7.34.0] - 2024.03.03 ### Added diff --git a/lib/rules/jsx-no-leaked-render.js b/lib/rules/jsx-no-leaked-render.js index 05f319edbf..b77cd576cc 100644 --- a/lib/rules/jsx-no-leaked-render.js +++ b/lib/rules/jsx-no-leaked-render.js @@ -79,7 +79,7 @@ function ruleFixer(context, fixStrategy, fixer, reportedNode, leftNode, rightNod return fixer.replaceText(reportedNode, `${newText} && ${alternateVal}`); } - if (rightNode.type === 'ConditionalExpression') { + if (rightNode.type === 'ConditionalExpression' || rightNode.type === 'LogicalExpression') { return fixer.replaceText(reportedNode, `${newText} && (${rightSideText})`); } if (rightNode.type === 'JSXElement') { diff --git a/tests/lib/rules/jsx-no-leaked-render.js b/tests/lib/rules/jsx-no-leaked-render.js index 969c93635c..f5729bf059 100644 --- a/tests/lib/rules/jsx-no-leaked-render.js +++ b/tests/lib/rules/jsx-no-leaked-render.js @@ -733,6 +733,24 @@ ruleTester.run('jsx-no-leaked-render', rule, { } `, }, + { + code: ` + const Component = ({ connection, hasError, hasErrorUpdate}) => { + return