Skip to content

Commit c8cc4f9

Browse files
Skn0ttmxschmitt
andauthored
chore(ui): update to react 18 (#32079)
Part of #31863. Updates most of our React usage to React 18. `recorder` doesn't seem to like it yet. I suspect that some of our code isn't compatible with concurrent mode, i've investigated that in #32101. --------- Signed-off-by: Simon Knott <[email protected]> Co-authored-by: Max Schmitt <[email protected]>
1 parent a30a880 commit c8cc4f9

File tree

7 files changed

+23
-20
lines changed

7 files changed

+23
-20
lines changed

packages/html-reporter/src/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import type zip from '@zip.js/zip.js';
1919
// @ts-ignore
2020
import * as zipImport from '@zip.js/zip.js/lib/zip-no-worker-inflate.js';
2121
import * as React from 'react';
22-
import * as ReactDOM from 'react-dom';
22+
import * as ReactDOM from 'react-dom/client';
2323
import './colors.css';
2424
import type { LoadedReport } from './loadedReport';
2525
import { ReportView } from './reportView';
@@ -44,7 +44,7 @@ const ReportLoader: React.FC = () => {
4444
};
4545

4646
window.onload = () => {
47-
ReactDOM.render(<ReportLoader />, document.querySelector('#root'));
47+
ReactDOM.createRoot(document.querySelector('#root')!).render(<ReportLoader />);
4848
};
4949

5050
class ZipReport implements LoadedReport {

packages/trace-viewer/src/embedded.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import '@web/common.css';
1818
import { applyTheme } from '@web/theme';
1919
import '@web/third_party/vscode/codicon.css';
20-
import * as ReactDOM from 'react-dom';
20+
import * as ReactDOM from 'react-dom/client';
2121
import { EmbeddedWorkbenchLoader } from './ui/embeddedWorkbenchLoader';
2222

2323
(async () => {
@@ -56,5 +56,5 @@ import { EmbeddedWorkbenchLoader } from './ui/embeddedWorkbenchLoader';
5656
setInterval(function() { fetch('ping'); }, 10000);
5757
}
5858

59-
ReactDOM.render(<EmbeddedWorkbenchLoader />, document.querySelector('#root'));
59+
ReactDOM.createRoot(document.querySelector('#root')!).render(<EmbeddedWorkbenchLoader />);
6060
})();

packages/trace-viewer/src/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import '@web/common.css';
1818
import { applyTheme } from '@web/theme';
1919
import '@web/third_party/vscode/codicon.css';
20-
import * as ReactDOM from 'react-dom';
20+
import * as ReactDOM from 'react-dom/client';
2121
import { WorkbenchLoader } from './ui/workbenchLoader';
2222

2323
(async () => {
@@ -38,5 +38,5 @@ import { WorkbenchLoader } from './ui/workbenchLoader';
3838
setInterval(function() { fetch('ping'); }, 10000);
3939
}
4040

41-
ReactDOM.render(<WorkbenchLoader/>, document.querySelector('#root'));
41+
ReactDOM.createRoot(document.querySelector('#root')!).render(<WorkbenchLoader/>);
4242
})();

packages/trace-viewer/src/ui/uiModeTestListView.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export const TestListView: React.FC<{
4040
testServerConnection: TestServerConnection | undefined,
4141
testModel?: TestModel,
4242
runTests: (mode: 'bounce-if-busy' | 'queue-if-busy', testIds: Set<string>) => void,
43-
runningState?: { testIds: Set<string>, itemSelectedByUser?: boolean },
43+
runningState?: { testIds: Set<string>, itemSelectedByUser?: boolean, completed?: boolean },
4444
watchAll: boolean,
4545
watchedTreeIds: { value: Set<string> },
4646
setWatchedTreeIds: (ids: { value: Set<string> }) => void,
@@ -154,7 +154,7 @@ export const TestListView: React.FC<{
154154
</div>
155155
{!!treeItem.duration && treeItem.status !== 'skipped' && <div className='ui-mode-list-item-time'>{msToString(treeItem.duration)}</div>}
156156
<Toolbar noMinHeight={true} noShadow={true}>
157-
<ToolbarButton icon='play' title='Run' onClick={() => runTreeItem(treeItem)} disabled={!!runningState}></ToolbarButton>
157+
<ToolbarButton icon='play' title='Run' onClick={() => runTreeItem(treeItem)} disabled={!!runningState && !runningState.completed}></ToolbarButton>
158158
<ToolbarButton icon='go-to-file' title='Show source' onClick={onRevealSource} style={(treeItem.kind === 'group' && treeItem.subKind === 'folder') ? { visibility: 'hidden' } : {}}></ToolbarButton>
159159
{!watchAll && <ToolbarButton icon='eye' title='Watch' onClick={() => {
160160
if (watchedTreeIds.value.has(treeItem.id))

packages/trace-viewer/src/ui/uiModeView.tsx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ export const UIModeView: React.FC<{}> = ({
8585
const [selectedItem, setSelectedItem] = React.useState<{ treeItem?: TreeItem, testFile?: SourceLocation, testCase?: reporterTypes.TestCase }>({});
8686
const [visibleTestIds, setVisibleTestIds] = React.useState<Set<string>>(new Set());
8787
const [isLoading, setIsLoading] = React.useState<boolean>(false);
88-
const [runningState, setRunningState] = React.useState<{ testIds: Set<string>, itemSelectedByUser?: boolean } | undefined>();
88+
const [runningState, setRunningState] = React.useState<{ testIds: Set<string>, itemSelectedByUser?: boolean, completed?: boolean } | undefined>();
89+
const isRunningTest = runningState && !runningState.completed;
90+
8991
const [watchAll, setWatchAll] = useSetting<boolean>('watch-all', false);
9092
const [watchedTreeIds, setWatchedTreeIds] = React.useState<{ value: Set<string> }>({ value: new Set() });
9193
const commandQueue = React.useRef(Promise.resolve());
@@ -251,29 +253,29 @@ export const UIModeView: React.FC<{}> = ({
251253

252254
// Update progress.
253255
React.useEffect(() => {
254-
if (runningState && testModel?.progress)
256+
if (isRunningTest && testModel?.progress)
255257
setProgress(testModel.progress);
256258
else if (!testModel)
257259
setProgress(undefined);
258-
}, [testModel, runningState]);
260+
}, [testModel, isRunningTest]);
259261

260262
// Test tree is built from the model and filters.
261263
const { testTree } = React.useMemo(() => {
262264
if (!testModel)
263265
return { testTree: new TestTree('', new TeleSuite('', 'root'), [], projectFilters, pathSeparator) };
264266
const testTree = new TestTree('', testModel.rootSuite, testModel.loadErrors, projectFilters, pathSeparator);
265-
testTree.filterTree(filterText, statusFilters, runningState?.testIds);
267+
testTree.filterTree(filterText, statusFilters, isRunningTest ? runningState?.testIds : undefined);
266268
testTree.sortAndPropagateStatus();
267269
testTree.shortenRoot();
268270
testTree.flattenForSingleProject();
269271
setVisibleTestIds(testTree.testIds());
270272
return { testTree };
271-
}, [filterText, testModel, statusFilters, projectFilters, setVisibleTestIds, runningState]);
273+
}, [filterText, testModel, statusFilters, projectFilters, setVisibleTestIds, runningState, isRunningTest]);
272274

273275
const runTests = React.useCallback((mode: 'queue-if-busy' | 'bounce-if-busy', testIds: Set<string>) => {
274276
if (!testServerConnection || !testModel)
275277
return;
276-
if (mode === 'bounce-if-busy' && runningState)
278+
if (mode === 'bounce-if-busy' && isRunningTest)
277279
return;
278280

279281
runTestBacklog.current = new Set([...runTestBacklog.current, ...testIds]);
@@ -320,9 +322,9 @@ export const UIModeView: React.FC<{}> = ({
320322
test.results = [];
321323
}
322324
setTestModel({ ...testModel });
323-
setRunningState(undefined);
325+
setRunningState(oldState => oldState ? ({ ...oldState, completed: true }) : undefined);
324326
});
325-
}, [projectFilters, runningState, testModel, testServerConnection, runWorkers, runHeaded, runUpdateSnapshots]);
327+
}, [projectFilters, isRunningTest, testModel, testServerConnection, runWorkers, runHeaded, runUpdateSnapshots]);
326328

327329
React.useEffect(() => {
328330
if (!testServerConnection || !teleSuiteUpdater)
@@ -396,7 +398,6 @@ export const UIModeView: React.FC<{}> = ({
396398
};
397399
}, [runTests, reloadTests, testServerConnection, visibleTestIds, isShowingOutput]);
398400

399-
const isRunningTest = !!runningState;
400401
const dialogRef = React.useRef<HTMLDialogElement>(null);
401402
const openInstallDialog = React.useCallback((e: React.MouseEvent) => {
402403
e.preventDefault();

packages/trace-viewer/src/uiMode.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import '@web/common.css';
1818
import { applyTheme } from '@web/theme';
1919
import '@web/third_party/vscode/codicon.css';
20-
import * as ReactDOM from 'react-dom';
20+
import * as ReactDOM from 'react-dom/client';
2121
import { UIModeView } from './ui/uiModeView';
2222

2323
(async () => {
@@ -38,5 +38,5 @@ import { UIModeView } from './ui/uiModeView';
3838
setInterval(function() { fetch('ping'); }, 10000);
3939
}
4040

41-
ReactDOM.render(<UIModeView></UIModeView>, document.querySelector('#root'));
41+
ReactDOM.createRoot(document.querySelector('#root')!).render(<UIModeView/>);
4242
})();

tests/playwright-test/ui-mode-test-run.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,9 @@ test('should run by project', async ({ runUITest }) => {
174174
await expect.poll(dumpTestTree(page)).toBe(`
175175
▼ ❌ a.test.ts
176176
► ◯ passes
177-
► ❌ fails <=
177+
▼ ❌ fails
178+
❌ foo <=
179+
◯ bar
178180
► ❌ suite
179181
▼ ❌ b.test.ts
180182
► ◯ passes

0 commit comments

Comments
 (0)