Skip to content

Commit 5fbda3a

Browse files
authored
chore(effect): add eslint plugin to reduce rerenders (#35223)
1 parent bc0c40c commit 5fbda3a

File tree

4 files changed

+59
-15
lines changed

4 files changed

+59
-15
lines changed

superset-frontend/.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ module.exports = {
8383
'plugin:react-hooks/recommended',
8484
'plugin:react-prefer-function-component/recommended',
8585
'plugin:storybook/recommended',
86+
'plugin:react-you-might-not-need-an-effect/legacy-recommended',
8687
],
8788
parser: '@babel/eslint-parser',
8889
parserOptions: {

superset-frontend/package-lock.json

Lines changed: 50 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

superset-frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@
305305
"eslint-plugin-react": "^7.37.2",
306306
"eslint-plugin-react-hooks": "^4.6.2",
307307
"eslint-plugin-react-prefer-function-component": "^3.3.0",
308+
"eslint-plugin-react-you-might-not-need-an-effect": "^0.5.1",
308309
"eslint-plugin-storybook": "^0.8.0",
309310
"eslint-plugin-testing-library": "^6.4.0",
310311
"eslint-plugin-theme-colors": "file:eslint-rules/eslint-plugin-theme-colors",

superset-frontend/packages/superset-ui-core/src/components/Select/Select.tsx

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -127,25 +127,21 @@ const Select = forwardRef(
127127
const shouldShowSearch = allowNewOptions ? true : showSearch;
128128
const [selectValue, setSelectValue] = useState(value);
129129
const [inputValue, setInputValue] = useState('');
130-
const [isLoading, setIsLoading] = useState(loading);
131130
const [isDropdownVisible, setIsDropdownVisible] = useState(false);
132131
const [isSearching, setIsSearching] = useState(false);
133132
const [visibleOptions, setVisibleOptions] = useState<SelectOptionsType>([]);
134-
const [maxTagCount, setMaxTagCount] = useState(
135-
propsMaxTagCount ?? MAX_TAG_COUNT,
136-
);
137133
const [onChangeCount, setOnChangeCount] = useState(0);
138134
const previousChangeCount = usePrevious(onChangeCount, 0);
139135
const fireOnChange = useCallback(
140136
() => setOnChangeCount(onChangeCount + 1),
141137
[onChangeCount],
142138
);
143139

144-
useEffect(() => {
145-
if (oneLine) {
146-
setMaxTagCount(isDropdownVisible ? 0 : 1);
147-
}
148-
}, [isDropdownVisible, oneLine]);
140+
const maxTagCount = oneLine
141+
? isDropdownVisible
142+
? 0
143+
: 1
144+
: (propsMaxTagCount ?? MAX_TAG_COUNT);
149145

150146
const mappedMode = isSingleMode ? undefined : 'multiple';
151147

@@ -510,6 +506,8 @@ const Select = forwardRef(
510506
],
511507
);
512508

509+
const isLoading = loading ?? false;
510+
513511
const popupRender = (
514512
originNode: ReactElement & { ref?: RefObject<HTMLElement> },
515513
) =>
@@ -536,12 +534,6 @@ const Select = forwardRef(
536534
setVisibleOptions(initialOptions);
537535
}, [initialOptions]);
538536

539-
useEffect(() => {
540-
if (loading !== undefined && loading !== isLoading) {
541-
setIsLoading(loading);
542-
}
543-
}, [isLoading, loading]);
544-
545537
useEffect(() => {
546538
setSelectValue(value);
547539
}, [value]);

0 commit comments

Comments
 (0)