diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8f88b8d4ac..2dfc22d380 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,7 +11,9 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
### Fixed
* [`jsx-no-leaked-render`]: preserve RHS parens for multiline jsx elements while fixing ([#3623][] @akulsr0)
* [`jsx-key`]: detect conditional returns ([#3630][] @yialo)
+* [`jsx-newline`]: prevent a crash when `allowMultilines ([#3633][] @ljharb)
+[#3633]: https://github.com/jsx-eslint/eslint-plugin-react/issues/3633
[#3630]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3630
[#3623]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3623
[#3615]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3615
diff --git a/lib/rules/jsx-newline.js b/lib/rules/jsx-newline.js
index d9c8262cc9..b4408e7cd8 100644
--- a/lib/rules/jsx-newline.js
+++ b/lib/rules/jsx-newline.js
@@ -20,7 +20,7 @@ const messages = {
};
function isMultilined(node) {
- return node.loc.start.line !== node.loc.end.line;
+ return node && node.loc.start.line !== node.loc.end.line;
}
module.exports = {
@@ -103,7 +103,6 @@ module.exports = {
const isWithoutNewLine = !/\n\s*\n/.test(firstAdjacentSibling.value);
if (isBlockCommentInCurlyBraces(element)) return;
-
if (
allowMultilines
&& (
diff --git a/tests/lib/rules/jsx-newline.js b/tests/lib/rules/jsx-newline.js
index d0daf68f86..201656f81e 100644
--- a/tests/lib/rules/jsx-newline.js
+++ b/tests/lib/rules/jsx-newline.js
@@ -649,5 +649,76 @@ new RuleTester({ parserOptions }).run('jsx-newline', rule, {
],
options: [{ prevent: true, allowMultilines: true }],
},
+ {
+ code: `
+ const frag: DocumentFragment = (
+
+ this.onClickNavigate('forward') }
+ />
+ this.onClickNavigate('left') }
+ />
+
+ this.onClickNavigate('right') }
+ />
+
+
+
+ {
+ ...Array.from(this.children)
+ }
+
+ )
+ `,
+ output: `
+ const frag: DocumentFragment = (
+
+ this.onClickNavigate('forward') }
+ />
+
+ this.onClickNavigate('left') }
+ />
+${' '}
+ this.onClickNavigate('right') }
+ />
+
+
+
+ {
+ ...Array.from(this.children)
+ }
+
+ )
+ `,
+ features: ['types'],
+ options: [{ prevent: true, allowMultilines: true }],
+ errors: [
+ { messageId: 'allowMultilines', line: 10 },
+ { messageId: 'prevent', line: 26 },
+ ],
+ },
]),
});