willmcpo / body-scroll-lock

Body scroll locking that just works with everything 😏
MIT License
4.04k stars 338 forks source link

iOS Devices: "restorePositionSetting" can run before "setPositionFixed" #247

Open dafcoe opened 2 years ago

dafcoe commented 2 years ago

In some situations it can happen that "restorePositionSetting" runs before "setPositionFixed" when calling "enableBodyScroll" right after "enableBodyScroll" and therefore the scroll lock is not being released due to fixed positioning on target element.

Example: https://codesandbox.io/s/wizardly-sound-53xgy

Possible fix: by wrapping restorePositionSetting logic on a requestAnimationFrame method queues the execution and prevent this issue to happen since setPositionFixed is already using requestAnimationFrame. Created a pull request with this change.