Skip to content

Commit

Permalink
Do not use legacy React functions
Browse files Browse the repository at this point in the history
  • Loading branch information
michaldudak committed Sep 21, 2023
1 parent 62a0a08 commit d9928d4
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 25 deletions.
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'),
);
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.
// 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
16 changes: 6 additions & 10 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 @@ -222,7 +222,7 @@ if (unusedBlacklistPatterns.size > 0) {
);
}

const viewerRoot = document.getElementById('test-viewer');
const viewerRoot = ReactDOMClient.createRoot(document.getElementById('test-viewer'));

function FixtureRenderer({ component: FixtureComponent }) {
React.useLayoutEffect(() => {
Expand All @@ -232,12 +232,12 @@ function FixtureRenderer({ component: FixtureComponent }) {
</TestViewer>
);

ReactDOM.render(children, viewerRoot);
viewerRoot.render(children);
}, [FixtureComponent]);

React.useLayoutEffect(() => {
return () => {
ReactDOM.unmountComponentAtNode(viewerRoot);
viewerRoot.unmount();
};
}, []);

Expand Down Expand Up @@ -354,9 +354,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
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

0 comments on commit d9928d4

Please sign in to comment.