Skip to content

Commit 605ae13

Browse files
authored
fix: attempt to prevent exceeding ResizeObserver loop limit (#65)
1 parent d7905f1 commit 605ae13

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

cmdk/src/index.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -738,12 +738,18 @@ const List = React.forwardRef<HTMLDivElement, ListProps>((props, forwardedRef) =
738738
if (height.current && ref.current) {
739739
const el = height.current
740740
const wrapper = ref.current
741+
let animationFrame
741742
const observer = new ResizeObserver(() => {
742-
const height = el.getBoundingClientRect().height
743-
wrapper.style.setProperty(`--cmdk-list-height`, height.toFixed(1) + 'px')
743+
animationFrame = requestAnimationFrame(() => {
744+
const height = el.getBoundingClientRect().height
745+
wrapper.style.setProperty(`--cmdk-list-height`, height.toFixed(1) + 'px')
746+
})
744747
})
745748
observer.observe(el)
746-
return () => observer.unobserve(el)
749+
return () => {
750+
cancelAnimationFrame(animationFrame)
751+
observer.unobserve(el)
752+
}
747753
}
748754
}, [])
749755

0 commit comments

Comments
 (0)