mirror of
https://github.com/zebrajr/react.git
synced 2026-01-15 12:15:22 +00:00
chore: gate legacy apis for react-devtools-shell (#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
This commit is contained in:
15
packages/react-devtools-shell/src/app/index.js
vendored
15
packages/react-devtools-shell/src/app/index.js
vendored
@@ -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';
|
||||
@@ -67,6 +69,8 @@ function mountStrictApp(App) {
|
||||
}
|
||||
|
||||
function mountLegacyApp(App: () => React$Node) {
|
||||
const {render, unmountComponentAtNode} = require('react-dom');
|
||||
|
||||
function LegacyRender() {
|
||||
return createElement(App);
|
||||
}
|
||||
@@ -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);
|
||||
@@ -90,7 +98,10 @@ function mountTestApp() {
|
||||
mountApp(SuspenseTree);
|
||||
mountApp(DeeplyNestedComponents);
|
||||
mountApp(Iframe);
|
||||
mountLegacyApp(PartiallyStrictApp);
|
||||
|
||||
if (shouldRenderLegacy) {
|
||||
mountLegacyApp(PartiallyStrictApp);
|
||||
}
|
||||
}
|
||||
|
||||
function unmountTestApp() {
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -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');
|
||||
@@ -37,4 +37,4 @@ function EffectWithState() {
|
||||
);
|
||||
}
|
||||
|
||||
render(<EffectWithState />, createContainer());
|
||||
createRoot(createContainer()).render(<EffectWithState />);
|
||||
|
||||
@@ -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,
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user