Skip to content

Commit 1f281be

Browse files
authored
Merge branch 'facebook:main' into main
2 parents f663bb0 + 9627d71 commit 1f281be

34 files changed

+2205
-1516
lines changed

compiler/packages/react-compiler-runtime/scripts/build.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const config = {
2929
outfile: path.join(__dirname, '../dist/index.js'),
3030
bundle: true,
3131
external: ['react'],
32-
format: argv.p === 'browser' ? 'esm' : 'cjs',
32+
format: 'cjs',
3333
platform: argv.p,
3434
target: 'es6',
3535
banner: {

packages/eslint-plugin-react-hooks/__tests__/ESLintRuleExhaustiveDeps-test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8300,6 +8300,7 @@ describe('rules-of-hooks/exhaustive-deps', () => {
83008300
ecmaVersion: 6,
83018301
sourceType: 'module',
83028302
};
8303+
83038304
const languageOptionsV9 = {
83048305
ecmaVersion: 6,
83058306
sourceType: 'module',
@@ -8442,7 +8443,7 @@ describe('rules-of-hooks/exhaustive-deps', () => {
84428443
parser: require('@typescript-eslint/parser-v5'),
84438444
},
84448445
}).run(
8445-
'eslint: v9, parser: @typescript-eslint/parser@^5.0.0-0',
8446+
'eslint: v9, parser: @typescript-eslint/parser@^5.0.0',
84468447
ReactHooksESLintRule,
84478448
{
84488449
valid: [

packages/eslint-plugin-react-hooks/__tests__/ESLintRulesOfHooks-test.js

Lines changed: 108 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
const ESLintTesterV7 = require('eslint-v7').RuleTester;
1313
const ESLintTesterV9 = require('eslint-v9').RuleTester;
1414
const ReactHooksESLintPlugin = require('eslint-plugin-react-hooks');
15-
const BabelEslintParser = require('@babel/eslint-parser');
1615
const ReactHooksESLintRule = ReactHooksESLintPlugin.rules['rules-of-hooks'];
1716

1817
/**
@@ -1561,19 +1560,117 @@ if (!process.env.CI) {
15611560
}
15621561

15631562
describe('rules-of-hooks/rules-of-hooks', () => {
1564-
new ESLintTesterV7({
1565-
parser: require.resolve('babel-eslint'),
1563+
const parserOptionsV7 = {
1564+
ecmaFeatures: {
1565+
jsx: true,
1566+
},
1567+
ecmaVersion: 6,
1568+
sourceType: 'module',
1569+
};
1570+
1571+
const languageOptionsV9 = {
1572+
ecmaVersion: 6,
1573+
sourceType: 'module',
15661574
parserOptions: {
1567-
ecmaVersion: 6,
1568-
sourceType: 'module',
1575+
ecmaFeatures: {
1576+
jsx: true,
1577+
},
15691578
},
1570-
}).run('eslint: v7', ReactHooksESLintRule, tests);
1579+
};
1580+
1581+
new ESLintTesterV7({
1582+
parser: require.resolve('babel-eslint'),
1583+
parserOptions: parserOptionsV7,
1584+
}).run('eslint: v7, parser: babel-eslint', ReactHooksESLintRule, tests);
15711585

15721586
new ESLintTesterV9({
15731587
languageOptions: {
1574-
parser: BabelEslintParser,
1575-
ecmaVersion: 6,
1576-
sourceType: 'module',
1577-
},
1578-
}).run('eslint: v9', ReactHooksESLintRule, tests);
1588+
...languageOptionsV9,
1589+
parser: require('@babel/eslint-parser'),
1590+
},
1591+
}).run(
1592+
'eslint: v9, parser: @babel/eslint-parser',
1593+
ReactHooksESLintRule,
1594+
tests
1595+
);
1596+
1597+
new ESLintTesterV7({
1598+
parser: require.resolve('@typescript-eslint/parser-v2'),
1599+
parserOptions: parserOptionsV7,
1600+
}).run(
1601+
'eslint: v7, parser: @typescript-eslint/parser@2.x',
1602+
ReactHooksESLintRule,
1603+
tests
1604+
);
1605+
1606+
new ESLintTesterV9({
1607+
languageOptions: {
1608+
...languageOptionsV9,
1609+
parser: require('@typescript-eslint/parser-v2'),
1610+
},
1611+
}).run(
1612+
'eslint: v9, parser: @typescript-eslint/parser@2.x',
1613+
ReactHooksESLintRule,
1614+
tests
1615+
);
1616+
1617+
new ESLintTesterV7({
1618+
parser: require.resolve('@typescript-eslint/parser-v3'),
1619+
parserOptions: parserOptionsV7,
1620+
}).run(
1621+
'eslint: v7, parser: @typescript-eslint/parser@3.x',
1622+
ReactHooksESLintRule,
1623+
tests
1624+
);
1625+
1626+
new ESLintTesterV9({
1627+
languageOptions: {
1628+
...languageOptionsV9,
1629+
parser: require('@typescript-eslint/parser-v3'),
1630+
},
1631+
}).run(
1632+
'eslint: v9, parser: @typescript-eslint/parser@3.x',
1633+
ReactHooksESLintRule,
1634+
tests
1635+
);
1636+
1637+
new ESLintTesterV7({
1638+
parser: require.resolve('@typescript-eslint/parser-v4'),
1639+
parserOptions: parserOptionsV7,
1640+
}).run(
1641+
'eslint: v7, parser: @typescript-eslint/parser@4.x',
1642+
ReactHooksESLintRule,
1643+
tests
1644+
);
1645+
1646+
new ESLintTesterV9({
1647+
languageOptions: {
1648+
...languageOptionsV9,
1649+
parser: require('@typescript-eslint/parser-v4'),
1650+
},
1651+
}).run(
1652+
'eslint: v9, parser: @typescript-eslint/parser@4.x',
1653+
ReactHooksESLintRule,
1654+
tests
1655+
);
1656+
1657+
new ESLintTesterV7({
1658+
parser: require.resolve('@typescript-eslint/parser-v5'),
1659+
parserOptions: parserOptionsV7,
1660+
}).run(
1661+
'eslint: v7, parser: @typescript-eslint/parser@^5.0.0-0',
1662+
ReactHooksESLintRule,
1663+
tests
1664+
);
1665+
1666+
new ESLintTesterV9({
1667+
languageOptions: {
1668+
...languageOptionsV9,
1669+
parser: require('@typescript-eslint/parser-v5'),
1670+
},
1671+
}).run(
1672+
'eslint: v9, parser: @typescript-eslint/parser@^5.0.0',
1673+
ReactHooksESLintRule,
1674+
tests
1675+
);
15791676
});

packages/eslint-plugin-react-hooks/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"@typescript-eslint/parser-v2": "npm:@typescript-eslint/parser@^2.26.0",
3636
"@typescript-eslint/parser-v3": "npm:@typescript-eslint/parser@^3.10.0",
3737
"@typescript-eslint/parser-v4": "npm:@typescript-eslint/parser@^4.1.0",
38-
"@typescript-eslint/parser-v5": "npm:@typescript-eslint/parser@^5.0.0-0",
38+
"@typescript-eslint/parser-v5": "npm:@typescript-eslint/parser@^5.62.0",
3939
"babel-eslint": "^10.0.3",
4040
"eslint-v7": "npm:eslint@^7.7.0",
4141
"eslint-v9": "npm:eslint@^9.0.0"

packages/eslint-plugin-react-hooks/src/RulesOfHooks.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,8 @@ export default {
549549
} else if (
550550
codePathNode.parent &&
551551
(codePathNode.parent.type === 'MethodDefinition' ||
552-
codePathNode.parent.type === 'ClassProperty') &&
552+
codePathNode.parent.type === 'ClassProperty' ||
553+
codePathNode.parent.type === 'PropertyDefinition') &&
553554
codePathNode.parent.value === codePathNode
554555
) {
555556
// Custom message for hooks inside a class

packages/react-dom/src/__tests__/ReactDOMInvalidARIAHook-test.js

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@ describe('ReactDOMInvalidARIAHook', () => {
1414
let ReactDOMClient;
1515
let mountComponent;
1616
let act;
17+
let assertConsoleErrorDev;
1718

1819
beforeEach(() => {
1920
jest.resetModules();
2021
React = require('react');
2122
ReactDOMClient = require('react-dom/client');
2223
act = require('internal-test-utils').act;
24+
assertConsoleErrorDev =
25+
require('internal-test-utils').assertConsoleErrorDev;
2326

2427
mountComponent = async function (props) {
2528
const container = document.createElement('div');
@@ -35,46 +38,52 @@ describe('ReactDOMInvalidARIAHook', () => {
3538
await mountComponent({'aria-label': 'Bumble bees'});
3639
});
3740
it('should warn for one invalid aria-* prop', async () => {
38-
await expect(() => mountComponent({'aria-badprop': 'maybe'})).toErrorDev(
41+
await mountComponent({'aria-badprop': 'maybe'});
42+
assertConsoleErrorDev([
3943
'Invalid aria prop `aria-badprop` on <div> tag. ' +
40-
'For details, see https://react.dev/link/invalid-aria-props',
41-
);
44+
'For details, see https://react.dev/link/invalid-aria-props\n' +
45+
' in div (at **)',
46+
]);
4247
});
4348
it('should warn for many invalid aria-* props', async () => {
44-
await expect(() =>
45-
mountComponent({
46-
'aria-badprop': 'Very tall trees',
47-
'aria-malprop': 'Turbulent seas',
48-
}),
49-
).toErrorDev(
49+
await mountComponent({
50+
'aria-badprop': 'Very tall trees',
51+
'aria-malprop': 'Turbulent seas',
52+
});
53+
assertConsoleErrorDev([
5054
'Invalid aria props `aria-badprop`, `aria-malprop` on <div> ' +
51-
'tag. For details, see https://react.dev/link/invalid-aria-props',
52-
);
55+
'tag. For details, see https://react.dev/link/invalid-aria-props\n' +
56+
' in div (at **)',
57+
]);
5358
});
5459
it('should warn for an improperly cased aria-* prop', async () => {
5560
// The valid attribute name is aria-haspopup.
56-
await expect(() => mountComponent({'aria-hasPopup': 'true'})).toErrorDev(
61+
await mountComponent({'aria-hasPopup': 'true'});
62+
assertConsoleErrorDev([
5763
'Unknown ARIA attribute `aria-hasPopup`. ' +
58-
'Did you mean `aria-haspopup`?',
59-
);
64+
'Did you mean `aria-haspopup`?\n' +
65+
' in div (at **)',
66+
]);
6067
});
6168

6269
it('should warn for use of recognized camel case aria attributes', async () => {
6370
// The valid attribute name is aria-haspopup.
64-
await expect(() => mountComponent({ariaHasPopup: 'true'})).toErrorDev(
71+
await mountComponent({ariaHasPopup: 'true'});
72+
assertConsoleErrorDev([
6573
'Invalid ARIA attribute `ariaHasPopup`. ' +
66-
'Did you mean `aria-haspopup`?',
67-
);
74+
'Did you mean `aria-haspopup`?\n' +
75+
' in div (at **)',
76+
]);
6877
});
6978

7079
it('should warn for use of unrecognized camel case aria attributes', async () => {
7180
// The valid attribute name is aria-haspopup.
72-
await expect(() =>
73-
mountComponent({ariaSomethingInvalid: 'true'}),
74-
).toErrorDev(
81+
await mountComponent({ariaSomethingInvalid: 'true'});
82+
assertConsoleErrorDev([
7583
'Invalid ARIA attribute `ariaSomethingInvalid`. ARIA ' +
76-
'attributes follow the pattern aria-* and must be lowercase.',
77-
);
84+
'attributes follow the pattern aria-* and must be lowercase.\n' +
85+
' in div (at **)',
86+
]);
7887
});
7988
});
8089
});

packages/react-dom/src/__tests__/ReactDOMLegacyComponentTree-test.internal.js

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@ describe('ReactDOMComponentTree', () => {
1313
let React;
1414
let ReactDOM;
1515
let container;
16+
let assertConsoleErrorDev;
1617

1718
beforeEach(() => {
1819
React = require('react');
1920
ReactDOM = require('react-dom');
21+
assertConsoleErrorDev =
22+
require('internal-test-utils').assertConsoleErrorDev;
2023

2124
container = document.createElement('div');
2225
document.body.appendChild(container);
@@ -31,11 +34,14 @@ describe('ReactDOMComponentTree', () => {
3134
it('finds instance of node that is attempted to be unmounted', () => {
3235
const component = <div />;
3336
const node = ReactDOM.render(<div>{component}</div>, container);
34-
expect(() => ReactDOM.unmountComponentAtNode(node)).toErrorDev(
35-
"unmountComponentAtNode(): The node you're attempting to unmount " +
36-
'was rendered by React and is not a top-level container. You may ' +
37-
'have accidentally passed in a React root node instead of its ' +
38-
'container.',
37+
ReactDOM.unmountComponentAtNode(node);
38+
assertConsoleErrorDev(
39+
[
40+
"unmountComponentAtNode(): The node you're attempting to unmount " +
41+
'was rendered by React and is not a top-level container. You may ' +
42+
'have accidentally passed in a React root node instead of its ' +
43+
'container.',
44+
],
3945
{withoutStack: true},
4046
);
4147
});
@@ -49,11 +55,14 @@ describe('ReactDOMComponentTree', () => {
4955
);
5056
const anotherComponent = <div />;
5157
const instance = ReactDOM.render(component, container);
52-
expect(() => ReactDOM.render(anotherComponent, instance)).toErrorDev(
53-
'Replacing React-rendered children with a new root ' +
54-
'component. If you intended to update the children of this node, ' +
55-
'you should instead have the existing children update their state ' +
56-
'and render the new components instead of calling ReactDOM.render.',
58+
ReactDOM.render(anotherComponent, instance);
59+
assertConsoleErrorDev(
60+
[
61+
'Replacing React-rendered children with a new root ' +
62+
'component. If you intended to update the children of this node, ' +
63+
'you should instead have the existing children update their state ' +
64+
'and render the new components instead of calling ReactDOM.render.',
65+
],
5766
{withoutStack: true},
5867
);
5968
});

0 commit comments

Comments
 (0)