Skip to content

Commit 66ae4c1

Browse files
acustiljharb
authored andcommitted
[Fix] no-unknown-property: support precedence prop in react 19
Fixes #3827
1 parent 233d442 commit 66ae4c1

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
1010
### Fixed
1111
* [`no-danger`]: avoid a crash on a nested component name ([#3833][] @ljharb)
1212
* [Fix] types: correct generated type declaration ([#3840][] @ocavue)
13+
* [`no-unknown-property`]: support `precedence` prop in react 19 ([#3829][] @acusti)
1314

1415
### Changed
1516
* [Tests] [`jsx-no-script-url`]: Improve tests ([#3849][] @radu2147)
@@ -19,6 +20,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
1920
[#3841]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3841
2021
[#3840]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3840
2122
[#3833]: https://github.com/jsx-eslint/eslint-plugin-react/issues/3833
23+
[#3829]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3829
2224

2325
## [7.37.2] - 2024.10.22
2426

lib/rules/no-unknown-property.js

+19-10
Original file line numberDiff line numberDiff line change
@@ -363,16 +363,24 @@ const REACT_ON_PROPS = [
363363
];
364364

365365
function getDOMPropertyNames(context) {
366-
const ALL_DOM_PROPERTY_NAMES = DOM_PROPERTY_NAMES_TWO_WORDS.concat(DOM_PROPERTY_NAMES_ONE_WORD);
367-
// this was removed in React v16.1+, see https://github.com/facebook/react/pull/10823
368-
if (!testReactVersion(context, '>= 16.1.0')) {
369-
return ALL_DOM_PROPERTY_NAMES.concat('allowTransparency');
370-
}
371-
// these were added in React v16.4.0, see https://reactjs.org/blog/2018/05/23/react-v-16-4.html and https://github.com/facebook/react/pull/12507
372-
if (testReactVersion(context, '>= 16.4.0')) {
373-
return ALL_DOM_PROPERTY_NAMES.concat(REACT_ON_PROPS);
374-
}
375-
return ALL_DOM_PROPERTY_NAMES;
366+
return [].concat(
367+
DOM_PROPERTY_NAMES_TWO_WORDS,
368+
DOM_PROPERTY_NAMES_ONE_WORD,
369+
370+
testReactVersion(context, '>= 16.1.0') ? [].concat(
371+
testReactVersion(context, '>= 16.4.0') ? [].concat(
372+
// these were added in React v16.4.0, see https://reactjs.org/blog/2018/05/23/react-v-16-4.html and https://github.com/facebook/react/pull/12507
373+
REACT_ON_PROPS,
374+
testReactVersion(context, '>= 19') ? [
375+
// precedence was added in React v19, see https://react.dev/blog/2024/04/25/react-19#support-for-stylesheets
376+
'precedence',
377+
] : []
378+
) : []
379+
) : [
380+
// this was removed in React v16.1+, see https://github.com/facebook/react/pull/10823
381+
'allowTransparency',
382+
]
383+
);
376384
}
377385

378386
// ------------------------------------------------------------------------------
@@ -501,6 +509,7 @@ function getStandardName(name, context) {
501509
return SVGDOM_ATTRIBUTE_NAMES[/** @type {keyof SVGDOM_ATTRIBUTE_NAMES} */ (name)];
502510
}
503511
const names = getDOMPropertyNames(context);
512+
504513
// Let's find a possible attribute match with a case-insensitive search.
505514
return names.find((element) => element.toLowerCase() === name.toLowerCase());
506515
}

tests/lib/rules/no-unknown-property.js

+6
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ ruleTester.run('no-unknown-property', rule, {
8989
{ code: '<div onPointerDown={this.onDown} onPointerUp={this.onUp} />' },
9090
{ code: '<input type="checkbox" defaultChecked={this.state.checkbox} />' },
9191
{ code: '<div onTouchStart={this.startAnimation} onTouchEnd={this.stopAnimation} onTouchCancel={this.cancel} onTouchMove={this.move} onMouseMoveCapture={this.capture} onTouchCancelCapture={this.log} />' },
92+
{
93+
code: '<link precedence="medium" href="https://foo.bar" rel="canonical" />',
94+
settings: {
95+
react: { version: '19.0.0' },
96+
},
97+
},
9298
// Case ignored attributes, for `charset` discussion see https://github.com/jsx-eslint/eslint-plugin-react/pull/1863
9399
{ code: '<meta charset="utf-8" />;' },
94100
{ code: '<meta charSet="utf-8" />;' },

0 commit comments

Comments
 (0)