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

chore: gate legacy apis for react-devtools-shell #28273

Merged
Show file tree
Hide file tree
Changes from all 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
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