Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump eslint-plugin-react to ^7.33.2 #38117

Merged
merged 4 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions benchmark/browser/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import * as ReactDOMClient from 'react-dom/client';
import PropTypes from 'prop-types';
import { logReactMetrics } from './utils';

// Get all the scenarios
const requirePerfScenarios = require.context('./scenarios', true, /(js|ts|tsx)$/);

const rootEl = document.getElementById('root');
const root = ReactDOMClient.createRoot(rootEl);

const scenarioSuitePath = window.location.search.replace('?', '');

Expand Down Expand Up @@ -35,11 +36,10 @@ Measure.propTypes = {
children: PropTypes.node,
};

ReactDOM.render(
root.render(
<React.Profiler id={scenarioSuitePath} onRender={logReactMetrics}>
<Measure>
<Component />
</Measure>
</React.Profiler>,
rootEl,
);
7 changes: 4 additions & 3 deletions examples/material-ui-cra-styled-components-ts/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import * as ReactDOMClient from 'react-dom/client';
import CssBaseline from '@mui/material/CssBaseline';
import App from './App';

ReactDOM.render(
const root = ReactDOMClient.createRoot(document.getElementById('root')!);

root.render(
<React.Fragment>
{/* CssBaseline kickstart an elegant, consistent, and simple baseline to build upon. */}
<CssBaseline />
<App />
</React.Fragment>,
document.getElementById('root'),
);
7 changes: 4 additions & 3 deletions examples/material-ui-cra-styled-components/src/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import * as ReactDOMClient from 'react-dom/client';
import CssBaseline from '@mui/material/CssBaseline';
import App from './App';
import * as serviceWorker from './serviceWorker';

ReactDOM.render(
const root = ReactDOMClient.createRoot(document.getElementById('root'));

root.render(
<React.Fragment>
{/* CssBaseline kickstart an elegant, consistent, and simple baseline to build upon. */}
<CssBaseline />
<App />
</React.Fragment>,
document.getElementById('root'),
);

// If you want your app to work offline and load faster, you can change
Expand Down
2 changes: 1 addition & 1 deletion examples/material-ui-express-ssr/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ function Main() {
);
}

ReactDOM.hydrate(<Main />, document.querySelector('#root'));
ReactDOM.hydrateRoot(document.querySelector('#root'), <Main />);
7 changes: 4 additions & 3 deletions examples/material-ui-preact/src/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import * as ReactDOMClient from 'react-dom/client';
import App from './App';

ReactDOM.render(
const root = ReactDOMClient.createRoot(document.getElementById('root'));

root.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('root'),
);
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-jsx-a11y": "^6.7.1",
"eslint-plugin-mocha": "^10.1.0",
"eslint-plugin-react": "^7.32.2",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
"fast-glob": "^3.3.1",
"fs-extra": "^11.1.1",
Expand Down
3 changes: 3 additions & 0 deletions packages/mui-utils/src/elementAcceptingRef.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ describe('elementAcceptingRef', () => {
function testAct() {
checkPropType(element);
if (shouldMount) {
// TODO: replace with React 18 implementation after https://github.com/testing-library/react-testing-library/issues/1216 is closed.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Purely out of curiosity, did you try it with testing-library/react-testing-library#1216 (comment)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it works with that version.

// eslint-disable-next-line react/no-deprecated
ReactDOM.render(
<React.Suspense fallback={<p />}>
{React.cloneElement(element, { ref: React.createRef() })}
Expand All @@ -43,6 +45,7 @@ describe('elementAcceptingRef', () => {
});

afterEach(() => {
// eslint-disable-next-line react/no-deprecated
ReactDOM.unmountComponentAtNode(rootNode);
});

Expand Down
3 changes: 3 additions & 0 deletions packages/mui-utils/src/elementTypeAcceptingRef.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ describe('elementTypeAcceptingRef', () => {
function testAct() {
checkPropType(Component);
if (shouldMount) {
// TODO: replace with React 18 implementation after https://github.com/testing-library/react-testing-library/issues/1216 is closed.
// eslint-disable-next-line react/no-deprecated
ReactDOM.render(
<React.Suspense fallback={<p />}>
<Component ref={React.createRef()} />
Expand All @@ -47,6 +49,7 @@ describe('elementTypeAcceptingRef', () => {
});

afterEach(() => {
// eslint-disable-next-line react/no-deprecated
ReactDOM.unmountComponentAtNode(rootNode);
});

Expand Down
9 changes: 7 additions & 2 deletions packages/mui-utils/src/useIsFocusVisible.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from 'chai';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import * as ReactDOMClient from 'react-dom/client';
import {
act,
createRenderer,
Expand Down Expand Up @@ -67,15 +67,20 @@ describe('useIsFocusVisible', () => {
});

let rootElement;
let reactRoot;

beforeEach(() => {
rootElement = document.createElement('div');
document.body.appendChild(rootElement);
rootElement.attachShadow({ mode: 'open' });
reactRoot = ReactDOMClient.createRoot(rootElement.shadowRoot);
});

afterEach(() => {
ReactDOM.unmountComponentAtNode(rootElement.shadowRoot);
act(() => {
reactRoot.unmount();
});

teardownFocusVisible(rootElement.shadowRoot);
document.body.removeChild(rootElement);
});
Expand Down
40 changes: 23 additions & 17 deletions test/regressions/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import * as ReactDOM from 'react-dom';
import * as ReactDOMClient from 'react-dom/client';
import { BrowserRouter as Router, Routes, Route, Link } from 'react-router-dom';
import webfontloader from 'webfontloader';
import TestViewer from './TestViewer';
Expand Down Expand Up @@ -225,21 +225,31 @@ if (unusedBlacklistPatterns.size > 0) {
const viewerRoot = document.getElementById('test-viewer');

function FixtureRenderer({ component: FixtureComponent }) {
const viewerReactRoot = React.useRef(null);

React.useLayoutEffect(() => {
const children = (
<TestViewer>
<FixtureComponent />
</TestViewer>
);
const renderTimeout = setTimeout(() => {
const children = (
<TestViewer>
<FixtureComponent />
</TestViewer>
);

ReactDOM.render(children, viewerRoot);
}, [FixtureComponent]);
if (viewerReactRoot.current === null) {
viewerReactRoot.current = ReactDOMClient.createRoot(viewerRoot);
}

viewerReactRoot.current.render(children);
});

React.useLayoutEffect(() => {
return () => {
ReactDOM.unmountComponentAtNode(viewerRoot);
clearTimeout(renderTimeout);
setTimeout(() => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

React tree can't be synchronously unmounted during render, so I introduced setTimeout to run this code after React lifecycle completes. Taken from https://stackoverflow.com/questions/73459382/react-18-async-way-to-unmount-root#answer-74445760

viewerReactRoot.current.unmount();
viewerReactRoot.current = null;
});
};
}, []);
}, [FixtureComponent]);

return null;
}
Expand Down Expand Up @@ -354,9 +364,5 @@ App.propTypes = {

const container = document.getElementById('react-root');
const children = <App fixtures={regressionFixtures.concat(demoFixtures)} />;
if (typeof ReactDOM.unstable_createRoot === 'function') {
const root = ReactDOM.unstable_createRoot(container);
root.render(children);
} else {
ReactDOM.render(children, container);
}
const reactRoot = ReactDOMClient.createRoot(container);
reactRoot.render(children);
2 changes: 2 additions & 0 deletions test/utils/createMount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export default function createMount(options: CreateMountOptions = {}) {

afterEach(() => {
ReactDOMTestUtils.act(() => {
// eslint-disable-next-line react/no-deprecated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't make it work. This could be caused by the lack of Enzyme support for React 18.

ReactDOM.unmountComponentAtNode(container!);
});
container!.parentElement!.removeChild(container!);
Expand All @@ -103,6 +104,7 @@ export default function createMount(options: CreateMountOptions = {}) {
);
}
ReactDOMTestUtils.act(() => {
// eslint-disable-next-line react/no-deprecated
ReactDOM.unmountComponentAtNode(container!);
});

Expand Down
Loading