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

refactor: upgrade to react 18 #3171

Merged
merged 46 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
a692895
feat: react 18
Aaaaash Apr 18, 2022
2077e6e
fix: comments test cases
Aaaaash Jun 29, 2022
655664e
fix: debug test case
Aaaaash Jul 4, 2022
3236f27
fix: reset scm code
Ricbet Jun 29, 2023
937a241
fix: debug module createRoot api
Ricbet Jun 29, 2023
59a2cf9
fix: ci
Ricbet Jun 30, 2023
39e91b1
fix: ci
Ricbet Jul 3, 2023
fd856bf
fix: ci
Ricbet Jul 11, 2023
2551713
fix: ci
Ricbet Jul 12, 2023
a7c746e
fix: ci
Ricbet Aug 2, 2023
6f118af
Merge branch 'main' into refactor/upgrade-to-react-18-next
erha19 Nov 20, 2023
4cbc596
Merge branch 'main' into refactor/upgrade-to-react-18-next
erha19 Nov 27, 2023
81b737c
chore: fix debug model test
erha19 Nov 27, 2023
b92c60a
style: improve debug style
erha19 Nov 27, 2023
b90e8c0
chore: fix comment test
erha19 Nov 27, 2023
dadc7af
chore: mock document body
erha19 Nov 27, 2023
8b41ae6
chore: test
erha19 Nov 27, 2023
8e2f7e5
chore: test
erha19 Nov 28, 2023
69200e3
chore: add diskFileProvider service mock
erha19 Nov 28, 2023
2f28d13
chore: fix happy test
erha19 Nov 28, 2023
8dca127
chore: upgrade codecov-action
erha19 Nov 28, 2023
5e6c545
chore: add body env
erha19 Nov 30, 2023
23d55d4
chore: update jsdom env
erha19 Nov 30, 2023
1e32417
chore: remove some test
erha19 Nov 30, 2023
b457124
chore: remove test
erha19 Nov 30, 2023
b1b9f5e
chore: remove tests
erha19 Dec 1, 2023
84dddec
chore: add some test
erha19 Dec 1, 2023
e8a85c0
chore: add test
erha19 Dec 1, 2023
22a6ef2
chore: add more test
erha19 Dec 1, 2023
5bc42c6
chore: fix happy test
erha19 Dec 1, 2023
039f751
chore: fix e2e test
erha19 Dec 1, 2023
22c4547
chore: fix e2e test
erha19 Dec 1, 2023
302fa4b
chore: add extension test
erha19 Dec 1, 2023
9c2aa17
chore: add more test
erha19 Dec 1, 2023
c3d4f9a
chore: fix e2e test
erha19 Dec 1, 2023
5c23cb7
chore: add more test
erha19 Dec 1, 2023
2b7e02d
chore: test
erha19 Dec 1, 2023
a7a1543
chore: add monaco test
erha19 Dec 1, 2023
4475c37
chore: add test
erha19 Dec 4, 2023
dfb47c9
chore: add all monaco test
erha19 Dec 4, 2023
2a01baa
chore: fix merge-editor test
erha19 Dec 4, 2023
f9cff96
chore: fix explorer test
erha19 Dec 4, 2023
500652a
chore: remove some change
erha19 Dec 5, 2023
46beb28
chore: add more timeout test
erha19 Dec 5, 2023
8ccb18b
chore: fix test
erha19 Dec 5, 2023
9be7584
chore: remove useless code
erha19 Dec 7, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:

- if: ${{ matrix.node-version == '16.x' && matrix.os == 'ubuntu-latest' }}
name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CORE_CODECOV_TOKEN }}
flags: ${{ matrix.ci-project }}
Expand Down
4 changes: 3 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ module.exports = {
testEnvironment: 'jsdom',
testEnvironmentOptions: {
html: `<html>
<div id="main"></div>
<body>
<div id="main"></div>
</body>
</html>`,
runScripts: 'dangerously',
url: 'http://localhost/?id=1',
Expand Down
2 changes: 2 additions & 0 deletions jest.setup.jsdom.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ global.clearImmediate = timer.clearImmediate;
// packages/extension/__tests__/browser/main.thread.env.test.ts
// MainThreadEnvAPI Test Suites › can read/write text via clipboard
let text = '';
global.IS_REACT_ACT_ENVIRONMENT = true;

window.navigator = Object.assign(window.navigator, {
clipboard: {
writeText(value) {
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@
"@types/lodash": "^4.14.182",
"@types/node": "^10.14.6",
"@types/node-fetch": "^2.6.1",
"@types/react": "^16.9.33",
"@types/react-dom": "^16.9.5",
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
"@types/react-is": "^16.7.1",
"@types/socket.io-client": "^1.4.32",
"@types/temp": "^0.9.1",
Expand All @@ -116,7 +116,7 @@
"is-git-clean": "^1.1.0",
"jest": "^29.7.0",
"jest-canvas-mock": "^2.4.0",
"jest-environment-jsdom": "^28.0.2",
"jest-environment-jsdom": "29.7.0",
"jest-fetch-mock": "^3.0.3",
"jest-jasmine2": "^28.0.3",
"jsdom": "^20.0.0",
Expand Down
17 changes: 9 additions & 8 deletions packages/comments/__test__/browser/comment-thread.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('comment service test', () => {
author: {
name: 'User',
},
body: '评论内容1',
body: 'Comment Text',
},
],
});
Expand All @@ -66,7 +66,7 @@ describe('comment service test', () => {
author: {
name: 'User',
},
body: '评论内容1',
body: 'Comment Text',
data: {
b: 1,
},
Expand All @@ -89,14 +89,14 @@ describe('comment service test', () => {
author: {
name: 'User',
},
body: '评论内容1',
body: 'Comment Text',
},
{
mode: CommentMode.Editor,
author: {
name: 'User',
},
body: '评论内容2',
body: 'Comment Text 2',
},
);
expect(thread.comments.length).toBe(2);
Expand All @@ -112,14 +112,14 @@ describe('comment service test', () => {
author: {
name: 'User',
},
body: '评论内容1',
body: 'Comment Text',
},
{
mode: CommentMode.Editor,
author: {
name: 'User',
},
body: '评论内容2',
body: 'Comment Text 2',
},
);
thread.dispose();
Expand All @@ -129,10 +129,11 @@ describe('comment service test', () => {
it('thread context service', () => {
const uri = URI.file('/test');
expect(commentsService.commentsThreads.length).toBe(0);
const contextValue = 'isDraft';
const thread = commentsService.createThread(uri, positionToRange(1), {
contextValue: 'aaa',
contextValue,
});
expect(thread.contextKeyService.getContextValue('thread')).toBe('aaa');
expect(thread.contextKeyService.getContextValue('thread')).toBe(contextValue);
expect(thread.contextKeyService.getContextValue('threadsLength')).toBe(1);
commentsService.createThread(uri, positionToRange(2));
// 同一个 uri 的 threadsLength 会变为 2
Expand Down
59 changes: 30 additions & 29 deletions packages/comments/__test__/browser/comment.service.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { act } from 'react-dom/test-utils';

import { Injector } from '@opensumi/di';
import {
CommentContentNode,
Expand All @@ -14,7 +16,6 @@ import { IconService } from '@opensumi/ide-theme/lib/browser';

import { createBrowserInjector } from '../../../../tools/dev-tool/src/injector-helper';
import { MockInjector, mockService } from '../../../../tools/dev-tool/src/mock-injector';
import { createMockedMonaco } from '../../../monaco/__mocks__/monaco';
import { MockContextKeyService } from '../../../monaco/__mocks__/monaco.context-key.service';
import { CommentsModule } from '../../src/browser';
import { ICommentsService, CommentMode } from '../../src/common';
Expand All @@ -24,7 +25,6 @@ describe('comment service test', () => {
let commentsService: ICommentsService;
let currentEditor: IEditor;
beforeAll(() => {
(global as any).monaco = createMockedMonaco() as any;
const monacoEditor = mockService({
getConfiguration: () => ({
lineHeight: 20,
Expand Down Expand Up @@ -77,27 +77,22 @@ describe('comment service test', () => {
},
]),
);
});

beforeEach(() => {
commentsService = injector.get<ICommentsService>(ICommentsService);
commentsService.init();
});

afterEach(() => {
commentsService.dispose();
});

afterAll(() => {
(global as any).monaco = undefined;
commentsService['threads'].clear();
});

it('create thread', () => {
const uri = URI.file('/test');
const [thread] = createTestThreads(uri);
expect(thread.uri.isEqual(uri));
expect(thread.range.startLineNumber).toBe(1);
expect(thread.comments[0].body).toBe('评论内容');
act(() => {
const [thread] = createTestThreads(uri);
expect(thread.uri.isEqual(uri));
expect(thread.range.startLineNumber).toBe(1);
expect(thread.comments[0].body).toBe('Comment Text');
});
});

it('get commentsThreads', () => {
Expand Down Expand Up @@ -163,7 +158,7 @@ describe('comment service test', () => {
author: {
name: 'User',
},
body: '评论内容',
body: 'Comment Text',
},
],
});
Expand All @@ -182,7 +177,7 @@ describe('comment service test', () => {
author: {
name: 'User',
},
body: '评论内容',
body: 'Comment Text',
},
],
});
Expand All @@ -192,11 +187,13 @@ describe('comment service test', () => {
it('unvisible widget not to be called with showWidgetsIfShowed method', async () => {
const uri = URI.file('/test');
const [thread] = createTestThreads(uri);
currentEditor.currentUri = uri;
// 生成一个 widget
thread.show(currentEditor);
// 调用隐藏方法,此时 isShow 为 false
thread.hide();
act(() => {
currentEditor.currentUri = uri;
// 生成一个 widget
thread.show(currentEditor);
// 调用隐藏方法,此时 isShow 为 false
thread.hide();
});
const widget = thread.getWidgetByEditor(currentEditor);
expect(widget?.isShow).toBeFalsy();
const onShow = jest.fn();
Expand All @@ -211,10 +208,12 @@ describe('comment service test', () => {
const uri = URI.file('/test');
const [thread] = createTestThreads(uri);
currentEditor.currentUri = uri;
// 生成一个 widget
thread.show(currentEditor);
// 先通过 dispose 方式隐藏,此时 isShow 仍为 true
thread.hideWidgetsByDispose();
act(() => {
// 生成一个 widget
thread.show(currentEditor);
// 先通过 dispose 方式隐藏,此时 isShow 仍为 true
thread.hideWidgetsByDispose();
});
const widget = thread.getWidgetByEditor(currentEditor);
expect(widget?.isShow).toBeTruthy();
const onShow = jest.fn();
Expand All @@ -227,8 +226,10 @@ describe('comment service test', () => {
const uri = URI.file('/test');
const [thread] = createTestThreads(uri);
currentEditor.currentUri = uri;
// 生成一个 widget
thread.show(currentEditor);
act(() => {
// 生成一个 widget
thread.show(currentEditor);
});
const widget = thread.getWidgetByEditor(currentEditor);
expect(widget?.isShow).toBeTruthy();
thread.hideWidgetsByDispose();
Expand Down Expand Up @@ -256,7 +257,7 @@ describe('comment service test', () => {
author: {
name: 'User',
},
body: '评论内容',
body: 'Comment Text',
},
],
}),
Expand All @@ -267,7 +268,7 @@ describe('comment service test', () => {
author: {
name: 'User',
},
body: '评论内容2',
body: 'Comment Text 2',
},
],
}),
Expand Down
2 changes: 1 addition & 1 deletion packages/comments/src/browser/comments-item.view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ const ReplyItem: React.FC<{
{timestamp && <Timestamp timestamp={timestamp} />}
{typeof label === 'string' ? <span className={styles.comment_item_label}>{label}</span> : label}
{' : '}
<span className={styles.comment_item_body}>{body}</span>
<span className={styles.comment_item_body}>{typeof body === 'string' ? body : body.value}</span>
{reply.reactions && reply.reactions.length > 0 && (
<CommentReactionSwitcher className={styles.reply_item_title} thread={thread} comment={reply} />
)}
Expand Down
5 changes: 2 additions & 3 deletions packages/comments/src/browser/comments-zone.view.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import clx from 'classnames';
import { observer } from 'mobx-react-lite';
import React from 'react';
import ReactDOM from 'react-dom';
import ReactDOM from 'react-dom/client';

import { INJECTOR_TOKEN, Injectable, Autowired } from '@opensumi/di';
import { ConfigProvider, localize, AppConfig, useInjectable, Event, Emitter } from '@opensumi/ide-core-browser';
Expand Down Expand Up @@ -160,11 +160,10 @@ export class CommentsZoneWidget extends ResizeZoneWidget implements ICommentsZon
this._container.appendChild(this._wrapper);
this.observeContainer(this._wrapper);
const customRender = this.commentsFeatureRegistry.getZoneWidgetRender();
ReactDOM.render(
ReactDOM.createRoot(this._wrapper).render(
<ConfigProvider value={this.appConfig}>
{customRender ? customRender(thread, this) : <CommentsZone thread={thread} widget={this} />}
</ConfigProvider>,
this._wrapper,
);
}

Expand Down
4 changes: 2 additions & 2 deletions packages/components/src/dropdown/dropdown.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import RightOutlined from '@ant-design/icons/RightOutlined';
import classNames from 'classnames';
import RCDropdown from 'rc-dropdown';
import React from 'react';
import React, { PropsWithChildren } from 'react';

import { tuple } from '../utils/type';
import { warning } from '../utils/warning';
Expand Down Expand Up @@ -44,7 +44,7 @@ export interface DropDownProps {
openClassName?: string;
}

export default class Dropdown extends React.Component<DropDownProps, any> {
export default class Dropdown extends React.Component<PropsWithChildren<DropDownProps>, any> {
static defaultProps = {
mouseEnterDelay: 0.15,
mouseLeaveDelay: 0.1,
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/icon/iconfont-cn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const svgBaseProps = {
fill: 'currentColor',
};

export function createFromIconfontCN<T>(options: CustomIconOptions = {}): React.SFC<IconFontProps<T>> {
export function createFromIconfontCN<T>(options: CustomIconOptions = {}) {
const { scriptUrl, extraCommonProps = {} } = options;

/**
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/menu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export interface MenuProps {
getPopupContainer?: (triggerNode: HTMLElement) => HTMLElement;
overflowedIndicator?: React.ReactNode;
forceSubMenuRender?: boolean;
children?: React.ReactNode;
}

type InternalMenuProps = MenuProps;
Expand Down
5 changes: 2 additions & 3 deletions packages/components/src/modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ import classNames from 'classnames';
import PropTypes from 'prop-types';
import Dialog from 'rc-dialog';
import addEventListener from 'rc-util/lib/Dom/addEventListener';
import React from 'react';
import React, { PropsWithChildren } from 'react';

import { Button } from '../button';
import type { ButtonType, ButtonProps } from '../button';

import { getConfirmLocale, ModalLocale } from './locale';


let mousePosition: { x: number; y: number } | null;
export const destroyFns: Array<() => void> = [];

Expand Down Expand Up @@ -119,7 +118,7 @@ export type ModalFunc = (props: ModalFuncProps) => {
update: (newConfig: ModalFuncProps) => void;
};

export default class Modal extends React.Component<ModalProps, {}> {
export default class Modal extends React.Component<PropsWithChildren<ModalProps>, {}> {
static info: ModalFunc;

static success: ModalFunc;
Expand Down
4 changes: 2 additions & 2 deletions packages/components/src/overlay/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import clsx from 'classnames';
import React from 'react';
import React, { PropsWithChildren } from 'react';

import { Modal, ModalProps } from '../modal';

Expand All @@ -22,7 +22,7 @@ export interface IOverlayProps {
keyboard?: boolean;
}

export const Overlay: React.FC<IOverlayProps> = ({
export const Overlay: React.FC<PropsWithChildren<IOverlayProps>> = ({
maskClosable = false,
closable = true,
className,
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/recycle-tree/RecycleTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export interface IRecycleTreeSize {
}

export interface IRecycleTreeProps<T = TreeModel> {
children(props: any): React.ReactNode;
model: T;
/**
* 容器高度
Expand Down
Loading
Loading