Skip to content

Commit

Permalink
chore: gate legacy apis for react-devtools-shell (facebook#28273)
Browse files Browse the repository at this point in the history
- `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
  • Loading branch information
hoxyq authored and AndyPengc12 committed Apr 15, 2024
1 parent cdc8ee9 commit 1b03e3d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
15 changes: 13 additions & 2 deletions packages/react-devtools-shell/src/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

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

import semver from 'semver';

import {createElement} from 'react';
import {createRoot} from 'react-dom/client';
import {render, unmountComponentAtNode} from 'react-dom';

import DeeplyNestedComponents from './DeeplyNestedComponents';
import Iframe from './Iframe';
import EditableProps from './EditableProps';
Expand Down Expand Up @@ -67,6 +69,8 @@ function mountStrictApp(App) {
}

function mountLegacyApp(App: () => React$Node) {
const {render, unmountComponentAtNode} = require('react-dom');

function LegacyRender() {
return createElement(App);
}
Expand All @@ -78,6 +82,10 @@ function mountLegacyApp(App: () => React$Node) {
unmountFunctions.push(() => unmountComponentAtNode(container));
}

const shouldRenderLegacy = semver.lte(
process.env.E2E_APP_REACT_VERSION,
'18.2.0',
);
function mountTestApp() {
mountStrictApp(ToDoList);
mountApp(InspectableElements);
Expand All @@ -90,7 +98,10 @@ function mountTestApp() {
mountApp(SuspenseTree);
mountApp(DeeplyNestedComponents);
mountApp(Iframe);
mountLegacyApp(PartiallyStrictApp);

if (shouldRenderLegacy) {
mountLegacyApp(PartiallyStrictApp);
}
}

function unmountTestApp() {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-devtools-shell/src/multi/left.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import * as React from 'react';
import {useState} from 'react';
import {createRoot} from 'react-dom';
import {createRoot} from 'react-dom/client';

function createContainer() {
const container = document.createElement('div');
Expand Down
4 changes: 2 additions & 2 deletions packages/react-devtools-shell/src/multi/right.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

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

function createContainer() {
const container = document.createElement('div');
Expand Down Expand Up @@ -37,4 +37,4 @@ function EffectWithState() {
);
}

render(<EffectWithState />, createContainer());
createRoot(createContainer()).render(<EffectWithState />);
6 changes: 1 addition & 5 deletions packages/react-devtools-shell/webpack-server.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const {resolve} = require('path');
const Webpack = require('webpack');
const WebpackDevServer = require('webpack-dev-server');
const fs = require('fs');
const {
DARK_MODE_DIMMED_WARNING_COLOR,
DARK_MODE_DIMMED_ERROR_COLOR,
Expand All @@ -17,10 +16,7 @@ const semver = require('semver');

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

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

const NODE_ENV = process.env.NODE_ENV;
if (!NODE_ENV) {
Expand Down

0 comments on commit 1b03e3d

Please sign in to comment.