GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [DevTools] add perf regression test page in shell (#25078) · react/react@ff9f943

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages/react-devtools-shell
    • index.html
    • perf-regression.html
    • src
      • e2e-regression
        • devtools.js
      • perf-regression
        • app.js
        • apps
          • LargeSubtree.js
          • index.js
        • devtools.js
    • webpack.config.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/react-devtools-shell/index.html‎

Copy file name to clipboardExpand all lines: packages/react-devtools-shell/index.html
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@
5151
<a href="/multi.html">multi DevTools</a>
5252
|
5353
<a href="/e2e.html">e2e tests</a>
54+
|
5455
<a href="/e2e-regression.html">e2e regression tests</a>
56+
|
57+
<a href="/perf-regression.html">perf regression tests</a>
5558
</span>
5659
</div>
5760

Collapse file

‎packages/react-devtools-shell/perf-regression.html‎

Copy file name to clipboard
+45Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<meta charset="utf8">
5+
<title>React DevTools</title>
6+
<meta name="viewport" content="width=device-width, initial-scale=1">
7+
<style>
8+
* {
9+
box-sizing: border-box;
10+
}
11+
body {
12+
margin: 0;
13+
padding: 0;
14+
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Helvetica, Arial,
15+
sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol;
16+
font-size: 12px;
17+
line-height: 1.5;
18+
}
19+
#iframe {
20+
position: absolute;
21+
top: 0;
22+
left: 0;
23+
width: 100vw;
24+
height: 60vh;
25+
}
26+
#devtools {
27+
position: absolute;
28+
bottom: 0;
29+
left: 0;
30+
width: 100vw;
31+
height: 40vh;
32+
}
33+
#load-devtools {
34+
margin: 20px;
35+
}
36+
</style>
37+
</head>
38+
<body>
39+
<iframe id="iframe"></iframe>
40+
<div id="devtools">
41+
<button id="load-devtools">Load DevTools</button>
42+
</div>
43+
<script src="dist/perf-regression-devtools.js"></script>
44+
</body>
45+
</html>
Collapse file

‎packages/react-devtools-shell/src/e2e-regression/devtools.js‎

Copy file name to clipboardExpand all lines: packages/react-devtools-shell/src/e2e-regression/devtools.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {initialize as createDevTools} from 'react-devtools-inline/frontend';
99

1010
// This is a pretty gross hack to make the runtime loaded named-hooks-code work.
1111
// TODO (Webpack 5) Hoepfully we can remove this once we upgrade to Webpack 5.
12-
// $FlowFixMer
12+
// $FlowFixMe
1313
__webpack_public_path__ = '/dist/'; // eslint-disable-line no-undef
1414

1515
// TODO (Webpack 5) Hopefully we can remove this prop after the Webpack 5 migration.
Collapse file

‎packages/react-devtools-shell/src/perf-regression/app.js‎

Copy file name to clipboard
+22Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/** @flow */
2+
3+
// This test harness mounts each test app as a separate root to test multi-root applications.
4+
5+
import * as React from 'react';
6+
import {createRoot} from 'react-dom/client';
7+
import App from './apps/index';
8+
9+
function mountApp() {
10+
const container = document.createElement('div');
11+
12+
((document.body: any): HTMLBodyElement).appendChild(container);
13+
14+
const root = createRoot(container);
15+
root.render(
16+
<React.StrictMode>
17+
<App />
18+
</React.StrictMode>,
19+
);
20+
}
21+
22+
mountApp();
Collapse file

‎packages/react-devtools-shell/src/perf-regression/apps/LargeSubtree.js‎

Copy file name to clipboard
+44Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
import * as React from 'react';
11+
12+
function generateArray(size) {
13+
return Array.from({length: size}, () => Math.floor(Math.random() * size));
14+
}
15+
16+
const arr = generateArray(50000);
17+
18+
export default function LargeSubtree() {
19+
const [showList, setShowList] = React.useState(false);
20+
const toggleList = () => {
21+
const startTime = performance.now();
22+
setShowList(!showList);
23+
// requestAnimationFrame should happen after render+commit is done
24+
window.requestAnimationFrame(() => {
25+
const afterRenderTime = performance.now();
26+
console.log(
27+
`Time spent on ${
28+
showList ? 'unmounting' : 'mounting'
29+
} the subtree: ${afterRenderTime - startTime}ms`,
30+
);
31+
});
32+
};
33+
return (
34+
<div>
35+
<h2>Mount/Unmount a large subtree</h2>
36+
<p>Click the button to toggle the state. Open console for results.</p>
37+
<button onClick={toggleList}>toggle</button>
38+
<ul>
39+
<li key="dummy">dummy item</li>
40+
{showList && arr.map((num, idx) => <li key={idx}>{num}</li>)}
41+
</ul>
42+
</div>
43+
);
44+
}
Collapse file

‎packages/react-devtools-shell/src/perf-regression/apps/index.js‎

Copy file name to clipboard
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
import * as React from 'react';
11+
import LargeSubtree from './LargeSubtree';
12+
13+
export default function Home() {
14+
return (
15+
<div>
16+
<LargeSubtree />
17+
</div>
18+
);
19+
}
Collapse file

‎packages/react-devtools-shell/src/perf-regression/devtools.js‎

Copy file name to clipboard
+55Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import * as React from 'react';
2+
import {createRoot} from 'react-dom/client';
3+
import {
4+
activate as activateBackend,
5+
initialize as initializeBackend,
6+
} from 'react-devtools-inline/backend';
7+
import {initialize as createDevTools} from 'react-devtools-inline/frontend';
8+
9+
// This is a pretty gross hack to make the runtime loaded named-hooks-code work.
10+
// TODO (Webpack 5) Hoepfully we can remove this once we upgrade to Webpack 5.
11+
// $FlowFixMe
12+
__webpack_public_path__ = '/dist/'; // eslint-disable-line no-undef
13+
14+
// TODO (Webpack 5) Hopefully we can remove this prop after the Webpack 5 migration.
15+
function hookNamesModuleLoaderFunction() {
16+
return import('react-devtools-inline/hookNames');
17+
}
18+
19+
function inject(contentDocument, sourcePath) {
20+
const script = contentDocument.createElement('script');
21+
script.src = sourcePath;
22+
23+
((contentDocument.body: any): HTMLBodyElement).appendChild(script);
24+
}
25+
26+
function init(
27+
appSource: string,
28+
appIframe: HTMLIFrameElement,
29+
devtoolsContainer: HTMLElement,
30+
loadDevToolsButton: HTMLButtonElement,
31+
) {
32+
const {contentDocument, contentWindow} = appIframe;
33+
34+
initializeBackend(contentWindow);
35+
36+
inject(contentDocument, appSource);
37+
38+
loadDevToolsButton.addEventListener('click', () => {
39+
const DevTools = createDevTools(contentWindow);
40+
createRoot(devtoolsContainer).render(
41+
<DevTools
42+
hookNamesModuleLoaderFunction={hookNamesModuleLoaderFunction}
43+
showTabBar={true}
44+
/>,
45+
);
46+
activateBackend(contentWindow);
47+
});
48+
}
49+
50+
init(
51+
'dist/perf-regression-app.js',
52+
document.getElementById('iframe'),
53+
document.getElementById('devtools'),
54+
document.getElementById('load-devtools'),
55+
);
Collapse file

‎packages/react-devtools-shell/webpack.config.js‎

Copy file name to clipboardExpand all lines: packages/react-devtools-shell/webpack.config.js
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ const app = makeConfig(
157157
'multi-devtools': './src/multi/devtools.js',
158158
'multi-right': './src/multi/right.js',
159159
'e2e-regression': './src/e2e-regression/app.js',
160+
'perf-regression-app': './src/perf-regression/app.js',
161+
'perf-regression-devtools': './src/perf-regression/devtools.js',
160162
},
161163
{
162164
react: resolve(builtModulesDir, 'react'),

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.