Skip to content

Commit 630e478

Browse files
authored
Fixed IconPicker infinite loop (#12356)
This PR fixes an infinite loop that was appearing on IconPicker, since it was about setting and unsetting the hotkey scope, it wasn't really noticeable. The direct cause was using the mouse enter and mouse leave events to set and unset the hotkey scope, without using a local state to prevent race condition, so this PR just adds this local state. Fixes #12344
1 parent 1144e21 commit 630e478

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

packages/twenty-front/src/modules/ui/input/components/IconPicker.tsx

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,24 @@ export const IconPicker = ({
107107
setHotkeyScopeAndMemorizePreviousScope,
108108
} = usePreviousHotkeyScope();
109109

110+
const [isMouseInsideIconList, setIsMouseInsideIconList] = useState(false);
111+
112+
const handleMouseEnter = () => {
113+
if (!isMouseInsideIconList) {
114+
setIsMouseInsideIconList(true);
115+
setHotkeyScopeAndMemorizePreviousScope({
116+
scope: IconPickerHotkeyScope.IconPicker,
117+
});
118+
}
119+
};
120+
121+
const handleMouseLeave = () => {
122+
if (isMouseInsideIconList) {
123+
setIsMouseInsideIconList(false);
124+
goBackToPreviousHotkeyScope();
125+
}
126+
};
127+
110128
const { closeDropdown } = useDropdown(dropdownId);
111129

112130
const { getIcons, getIcon } = useIcons();
@@ -196,12 +214,8 @@ export const IconPicker = ({
196214
/>
197215
<DropdownMenuSeparator />
198216
<div
199-
onMouseEnter={() => {
200-
setHotkeyScopeAndMemorizePreviousScope({
201-
scope: IconPickerHotkeyScope.IconPicker,
202-
});
203-
}}
204-
onMouseLeave={goBackToPreviousHotkeyScope}
217+
onMouseEnter={handleMouseEnter}
218+
onMouseLeave={handleMouseLeave}
205219
>
206220
<DropdownMenuItemsContainer>
207221
<StyledMenuIconItemsContainer>

0 commit comments

Comments
 (0)