Skip to content

Commit b76b4bd

Browse files
authored
improve performance, don't read offsetWidth when popup is not shown (#455)
* improve performance, don't read offsetWidth when popup is not shown * update test snapshot
1 parent 2373b45 commit b76b4bd

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/generate.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -895,11 +895,13 @@ export default function generateSelector<
895895
const [containerWidth, setContainerWidth] = React.useState(null);
896896

897897
useLayoutEffect(() => {
898-
const newWidth = Math.ceil(containerRef.current.offsetWidth);
899-
if (containerWidth !== newWidth) {
900-
setContainerWidth(newWidth);
898+
if (triggerOpen) {
899+
const newWidth = Math.ceil(containerRef.current.offsetWidth);
900+
if (containerWidth !== newWidth) {
901+
setContainerWidth(newWidth);
902+
}
901903
}
902-
});
904+
}, [triggerOpen]);
903905

904906
const popupNode = (
905907
<OptionList

tests/__snapshots__/Tags.test.tsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ exports[`Select.Tags OptGroup renders correctly 1`] = `
7878
<div>
7979
<div
8080
class="rc-select-dropdown"
81-
style="width: 0px; opacity: 0;"
81+
style="opacity: 0; width: 0px;"
8282
>
8383
<div>
8484
<div

0 commit comments

Comments
 (0)