Skip to content

Commit 1b03e3d

Browse files
hoxyqAndyPengc12
authored andcommitted
chore: gate legacy apis for react-devtools-shell (facebook#28273)
- `react-devtools-shell` is only used for e2e tests - Based on the React version we testing against, we will show/hide roots using legacy render
1 parent cdc8ee9 commit 1b03e3d

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

packages/react-devtools-shell/src/app/index.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
// This test harness mounts each test app as a separate root to test multi-root applications.
44

5+
import semver from 'semver';
6+
57
import {createElement} from 'react';
68
import {createRoot} from 'react-dom/client';
7-
import {render, unmountComponentAtNode} from 'react-dom';
9+
810
import DeeplyNestedComponents from './DeeplyNestedComponents';
911
import Iframe from './Iframe';
1012
import EditableProps from './EditableProps';
@@ -67,6 +69,8 @@ function mountStrictApp(App) {
6769
}
6870

6971
function mountLegacyApp(App: () => React$Node) {
72+
const {render, unmountComponentAtNode} = require('react-dom');
73+
7074
function LegacyRender() {
7175
return createElement(App);
7276
}
@@ -78,6 +82,10 @@ function mountLegacyApp(App: () => React$Node) {
7882
unmountFunctions.push(() => unmountComponentAtNode(container));
7983
}
8084

85+
const shouldRenderLegacy = semver.lte(
86+
process.env.E2E_APP_REACT_VERSION,
87+
'18.2.0',
88+
);
8189
function mountTestApp() {
8290
mountStrictApp(ToDoList);
8391
mountApp(InspectableElements);
@@ -90,7 +98,10 @@ function mountTestApp() {
9098
mountApp(SuspenseTree);
9199
mountApp(DeeplyNestedComponents);
92100
mountApp(Iframe);
93-
mountLegacyApp(PartiallyStrictApp);
101+
102+
if (shouldRenderLegacy) {
103+
mountLegacyApp(PartiallyStrictApp);
104+
}
94105
}
95106

96107
function unmountTestApp() {

packages/react-devtools-shell/src/multi/left.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import * as React from 'react';
99
import {useState} from 'react';
10-
import {createRoot} from 'react-dom';
10+
import {createRoot} from 'react-dom/client';
1111

1212
function createContainer() {
1313
const container = document.createElement('div');

packages/react-devtools-shell/src/multi/right.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import * as React from 'react';
99
import {useLayoutEffect, useRef, useState} from 'react';
10-
import {render} from 'react-dom';
10+
import {createRoot} from 'react-dom/client';
1111

1212
function createContainer() {
1313
const container = document.createElement('div');
@@ -37,4 +37,4 @@ function EffectWithState() {
3737
);
3838
}
3939

40-
render(<EffectWithState />, createContainer());
40+
createRoot(createContainer()).render(<EffectWithState />);

packages/react-devtools-shell/webpack-server.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const {resolve} = require('path');
22
const Webpack = require('webpack');
33
const WebpackDevServer = require('webpack-dev-server');
4-
const fs = require('fs');
54
const {
65
DARK_MODE_DIMMED_WARNING_COLOR,
76
DARK_MODE_DIMMED_ERROR_COLOR,
@@ -17,10 +16,7 @@ const semver = require('semver');
1716

1817
const {SUCCESSFUL_COMPILATION_MESSAGE} = require('./constants');
1918

20-
const ReactVersionSrc = fs.readFileSync(require.resolve('shared/ReactVersion'));
21-
const currentReactVersion = /export default '([^']+)';/.exec(
22-
ReactVersionSrc,
23-
)[1];
19+
const {ReactVersion: currentReactVersion} = require('../../ReactVersions');
2420

2521
const NODE_ENV = process.env.NODE_ENV;
2622
if (!NODE_ENV) {

0 commit comments

Comments
 (0)