everweij / react-laag

Hooks to build things like tooltips, dropdown menu's and popovers in React
https://www.react-laag.com
MIT License
907 stars 47 forks source link

Stop using requestAnimationFrame #85

Closed simonlindholm closed 2 years ago

simonlindholm commented 2 years ago

When opening a popup I'm seeing the popup first show up at (0, 0) before moving to its correct position. (Demo: click the top-left logo of https://decomp.me/scratch/5MmAZ.) This appears to be because useLayer delays position updates by one frame using requestAnimationFrame -- removing that delay fixes the problem for me. I'm not sure if there's a concrete problem that the requestAnimationFrame is there to fix; I tried to maintain some of the original throttling by using an immediately resolved promise.

Possibly related to #61, #68, #79.

everweij commented 2 years ago

Thanks a lot! I was just learning about tasks vs micro-tasks the other day, so this makes perfect sense :) Don't mind the failing pipeline, that's something I want to fix anyways. Tests etc run ok locally. I will prepare a new release in a bit.