Skip to content

Commit 5f3574b

Browse files
committed
🤖 fix: prevent infinite render loop in KebabMenu dropdown positioning
1 parent 99759d1 commit 5f3574b

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/browser/components/KebabMenu.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,18 @@ export const KebabMenu: React.FC<KebabMenuProps> = ({ items, className }) => {
3434

3535
// Calculate dropdown position when menu opens
3636
useEffect(() => {
37-
if (isOpen && buttonRef.current) {
38-
const rect = buttonRef.current.getBoundingClientRect();
39-
setDropdownPosition({
40-
top: rect.bottom + 4, // 4px gap below button
41-
left: rect.right - 160, // Align right edge (160px = min-width)
42-
});
43-
}
37+
if (!isOpen || !buttonRef.current) return;
38+
39+
const rect = buttonRef.current.getBoundingClientRect();
40+
const nextPosition = {
41+
top: rect.bottom + 4, // 4px gap below button
42+
left: rect.right - 160, // Align right edge (160px = min-width)
43+
};
44+
45+
// Only update when position actually changes to avoid render loops
46+
setDropdownPosition((prev) =>
47+
prev.top === nextPosition.top && prev.left === nextPosition.left ? prev : nextPosition
48+
);
4449
}, [isOpen]);
4550

4651
// Close menu when clicking outside

0 commit comments

Comments
 (0)