Skip to content

Commit a82d806

Browse files
committed
chore(FR-1557): apply react compiler (#4404)
resolves #4400 (FR-1557) This PR updates the ESLint configuration and fixes linting issues across the codebase: 1. Removes the Storybook ESLint plugin from the root config 2. Adds multiple tsconfig paths to the ESLint parser options 3. Disables several ESLint rules that were causing noise 4. Moves React-specific ESLint rules to the appropriate package configs 5. Updates the lint command in CI workflow 6. Adds Zod v4 override in package.json 7. Enhances package-specific ESLint configurations with better rules 8. Adds React Compiler support via babel-plugin-react-compiler 9. Fixes various linting issues: - Removes unused variables and parameters - Fixes React hooks linting issues - Adds 'use memo' annotations for components - Improves type safety - Fixes potential memory leaks 10. For `no_unused_var`, I have configured it to ignore variables starting with `_`. `./react/package.json` **how to test** I added "use memo" in the `BAITableSettingModal.tsx` and `AgentList.tsx`. When you build the webui and examine the built files, you can find `react.memo_cache_sentinel`. **Checklist:** (if applicable) - [ ] Documentation - [ ] Minium required manager version - [ ] Specific setting for review (eg., KB link, endpoint or how to setup) - [ ] Minimum requirements to check during review - [ ] Test case(s) to demonstrate the difference of before/after
1 parent e442f89 commit a82d806

File tree

135 files changed

+536
-687
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

135 files changed

+536
-687
lines changed

.eslintrc.json

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
"plugin:wc/recommended",
1010
"plugin:lit-a11y/recommended",
1111
"plugin:@typescript-eslint/recommended",
12-
"plugin:wc/best-practice",
13-
"plugin:storybook/recommended"
12+
"plugin:wc/best-practice"
1413
],
1514
"parser": "@typescript-eslint/parser",
1615
"parserOptions": {
@@ -19,41 +18,34 @@
1918
"ecmaFeatures": {
2019
"jsx": true
2120
},
22-
"project": "tsconfig.json",
21+
"project": [
22+
"tsconfig.json",
23+
"react/tsconfig.json",
24+
"packages/backend.ai-ui/tsconfig.json"
25+
],
2326
"extraFileExtensions": [".json"]
2427
},
25-
"plugins": [
26-
"@typescript-eslint",
27-
"lit-a11y",
28-
"wc",
29-
"react-hooks",
30-
"json-schema-validator"
31-
],
28+
"plugins": ["@typescript-eslint", "lit-a11y", "wc", "json-schema-validator"],
3229
"rules": {
3330
"object-curly-spacing": "off",
31+
"curly": "off",
3432
"operator-linebreak": "off",
3533
"indent": "off",
36-
"no-unused-vars": "off",
3734
"no-undef": "off",
3835
"no-constant-condition": "off",
3936
"no-inner-declarations": "off",
4037
"no-irregular-whitespace": "off",
4138
"max-len": "off",
4239
"@typescript-eslint/no-explicit-any": "off",
40+
"@typescript-eslint/ban-ts-comment": "off",
4341
"require-jsdoc": "off",
42+
"valid-jsdoc": "off",
4443
"camelcase": "off",
4544
"no-empty": "off",
4645
"no-empty-function": "off",
4746
"no-invalid-this": "off",
4847
"wc/guard-super-call": "off",
4948
"lit-a11y/alt-text": "off",
50-
"react-hooks/rules-of-hooks": "error",
51-
"react-hooks/exhaustive-deps": [
52-
"warn",
53-
{
54-
"additionalHooks": "useRecoilCallback"
55-
}
56-
],
5749
"spaced-comment": "off",
5850
"quotes": "off",
5951
"quote-props": "off",
@@ -65,5 +57,10 @@
6557
"parser": "jsonc-eslint-parser",
6658
"extends": ["plugin:json-schema-validator/recommended"]
6759
}
68-
]
60+
],
61+
"settings": {
62+
"react": {
63+
"version": "19.2"
64+
}
65+
}
6966
}

.github/workflows/jest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ jobs:
6767
- name: Install dependencies
6868
run: pnpm install
6969
- name: Run ESLint on React
70-
run: pnpm eslint ./src --ignore-pattern '*.test.*' --max-warnings=0
70+
run: pnpm run lint
7171
- name: run relay-compiler
7272
run: pnpm run relay
7373
- name: Jest report

package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@
148148
"eslint-plugin-json-schema-validator": "^5.3.1",
149149
"eslint-plugin-lit-a11y": "^4.1.4",
150150
"eslint-plugin-prettier": "^5.2.1",
151-
"eslint-plugin-react-hooks": "^4.6.2",
152151
"eslint-plugin-wc": "^2.1.0",
153152
"express": "^4.19.2",
154153
"husky": "^9.1.4",
@@ -186,6 +185,11 @@
186185
"overrides": {
187186
"eslint": "^8.57.0"
188187
},
188+
"pnpm": {
189+
"overrides": {
190+
"zod": "^4.0.0"
191+
}
192+
},
189193
"vaadin": {
190194
"disableUsageStatistics": true
191195
},
@@ -194,11 +198,11 @@
194198
"prettier --write"
195199
],
196200
"react/src/**/*.{js,jsx,ts,tsx,json,css,scss,md}": [
197-
"eslint --max-warnings=0 --cache",
201+
"pnpm run --prefix ./react lint --cache",
198202
"prettier --write"
199203
],
200204
"packages/backend.ai-ui/src/**/*.{js,jsx,ts,tsx,json,css,scss,md}": [
201-
"eslint --max-warnings=0 --cache",
205+
"pnpm run --prefix ./packages/backend.ai-ui lint --cache",
202206
"prettier --write"
203207
],
204208
"e2e/**/*.{js,ts}": [

packages/backend.ai-ui/package.json

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@
2828
},
2929
"eslintConfig": {
3030
"extends": [
31-
"react-app",
32-
"react-app/jest",
3331
"plugin:storybook/recommended",
34-
"plugin:react/recommended"
32+
"plugin:react/recommended",
33+
"plugin:react-hooks/recommended"
3534
],
3635
"plugins": [
37-
"json-schema-validator"
36+
"json-schema-validator",
37+
"react-hooks",
38+
"import"
3839
],
3940
"overrides": [
4041
{
@@ -45,12 +46,38 @@
4546
"extends": [
4647
"plugin:json-schema-validator/recommended"
4748
]
49+
},
50+
{
51+
"files": [
52+
"**/*.stories.tsx"
53+
],
54+
"rules": {
55+
"react-hooks/rules-of-hooks": "off"
56+
}
4857
}
4958
],
5059
"rules": {
5160
"react/react-in-jsx-scope": "off",
5261
"react/prop-types": "off",
53-
"import/no-duplicates": "error"
62+
"import/no-duplicates": "error",
63+
"no-useless-catch": "off",
64+
"prefer-promise-reject-errors": "off",
65+
"func-call-spacing": "off",
66+
"@typescript-eslint/no-unused-vars": [
67+
"error",
68+
{
69+
"args": "all",
70+
"argsIgnorePattern": "^_",
71+
"varsIgnorePattern": "^_"
72+
}
73+
],
74+
"react-hooks/rules-of-hooks": "error",
75+
"react-hooks/exhaustive-deps": [
76+
"warn",
77+
{
78+
"additionalHooks": "useRecoilCallback"
79+
}
80+
]
5481
}
5582
},
5683
"peerDependencies": {
@@ -106,10 +133,11 @@
106133
"@types/relay-runtime": "^19.0.3",
107134
"@types/relay-test-utils": "^19.0.0",
108135
"@vitejs/plugin-react": "^4.5.0",
109-
"eslint": "^8.57.1",
110-
"eslint-config-react-app": "^7.0.1",
136+
"babel-plugin-react-compiler": "^1.0.0",
137+
"eslint": "^8.57.0",
111138
"eslint-plugin-import": "^2.31.0",
112139
"eslint-plugin-react": "^7.37.4",
140+
"eslint-plugin-react-hooks": "^7.0.0",
113141
"eslint-plugin-storybook": "^9.1.1",
114142
"fast-glob": "^3.3.3",
115143
"jest": "^29.7.0",
@@ -118,7 +146,7 @@
118146
"relay-test-utils": "^20.1.1",
119147
"storybook": "^9.1.1",
120148
"ts-jest": "^29.2.5",
121-
"typescript": "^5.7.2",
149+
"typescript": "^5.8.2",
122150
"vite": "^6.3.5",
123151
"vite-plugin-dts": "^4.5.4",
124152
"vite-plugin-relay-lite": "^0.11.0",

packages/backend.ai-ui/src/components/BAIConfirmModalWithInput.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import BAIFlex from './BAIFlex';
22
import BAIModal, { BAIModalProps } from './BAIModal';
33
import { ExclamationCircleFilled } from '@ant-design/icons';
44
import { Form, Input, Typography } from 'antd';
5-
import _ from 'lodash';
65
import React from 'react';
76
import { useTranslation } from 'react-i18next';
87

@@ -47,11 +46,11 @@ const BAIConfirmModalWithInput: React.FC<BAIConfirmModalWithInputProps> = ({
4746
}
4847
onOk={(e) => {
4948
form.resetFields();
50-
_.isFunction(onOk) && onOk(e);
49+
onOk?.(e);
5150
}}
5251
onCancel={(e) => {
5352
form.resetFields();
54-
_.isFunction(onCancel) && onCancel(e);
53+
onCancel?.(e);
5554
}}
5655
{...props}
5756
okButtonProps={{

packages/backend.ai-ui/src/components/BAIGraphQLPropertyFilter.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export type FilterOperator =
8383
| 'in'
8484
| 'notIn'
8585
// Allow custom operators
86-
| (string & {});
86+
| (string & NonNullable<unknown>);
8787

8888
type BaseFilterProperty = {
8989
key: string;
@@ -325,7 +325,6 @@ const BAIGraphQLPropertyFilter: React.FC<BAIGraphQLPropertyFilterProps> = ({
325325
value: propValue,
326326
onChange: propOnChange,
327327
defaultValue,
328-
loading,
329328
combinationMode = 'AND',
330329
...containerProps
331330
}) => {

packages/backend.ai-ui/src/components/BAIModal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const BAIModal: React.FC<BAIModalProps> = ({ className, ...modalProps }) => {
4242
right: 0,
4343
}); //draggable space
4444
const draggleRef = useRef<HTMLDivElement>(null);
45-
const handleDrag = (e: DraggableEvent, uiData: DraggableData) => {
45+
const handleDrag = (_e: DraggableEvent, uiData: DraggableData) => {
4646
const { clientWidth, clientHeight } = window.document.documentElement; //browserWidth, browserHeight
4747
const targetRect = draggleRef.current?.getBoundingClientRect(); //Modal size and viewport
4848
if (!targetRect) {

packages/backend.ai-ui/src/components/BAIPropertyFilter.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export function mergeFilterValues(
9898
_.map(filterOutEmpty(filterStrings), (str) => `(${str})`),
9999
operator,
100100
);
101-
return !!mergedFilter ? mergedFilter : undefined;
101+
return mergedFilter ? mergedFilter : undefined;
102102
}
103103

104104
/**
@@ -203,7 +203,6 @@ const BAIPropertyFilter: React.FC<BAIPropertyFilterProps> = ({
203203
value: propValue,
204204
onChange: propOnChange,
205205
defaultValue,
206-
loading,
207206
...containerProps
208207
}) => {
209208
const [search, setSearch] = useState<string>();
@@ -332,7 +331,7 @@ const BAIPropertyFilter: React.FC<BAIPropertyFilterProps> = ({
332331
popupMatchSelectWidth={false}
333332
options={options}
334333
value={selectedProperty.key}
335-
onChange={(value, options) => {
334+
onChange={(_value, options) => {
336335
setSelectedProperty(_.castArray(options)[0].filter);
337336
}}
338337
onSelect={() => {

packages/backend.ai-ui/src/components/BAISelect.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ function BAISelect<
6868
tooltip = '',
6969
atBottomThreshold = 30,
7070
atBottomStateChange,
71-
bottomLoading,
7271
footer,
7372
endReached, // Destructure the new prop
7473
...selectProps

packages/backend.ai-ui/src/components/BAIUnmountAfterClose.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const BAIUnmountAfterClose: React.FC<BAIUnmountModalAfterCloseProps> = ({
3737
// Update internal state when the child's open prop becomes true
3838
useLayoutEffect(() => {
3939
if (isOpen) {
40+
// eslint-disable-next-line react-hooks/set-state-in-effect
4041
setIsMount(true);
4142
}
4243
}, [isOpen]);

0 commit comments

Comments
 (0)