willmcpo / body-scroll-lock

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

ESM build broken, causes scroll-to-top on iOS #271

Open claus opened 11 months ago

claus commented 11 months ago

So the reason this package still has problems on iOS (it does not move the position: fixed body up scrollY pixels; it "scrolls to top" and stays there) is because the ESM build is broken. I haven't debugged what exactly is broken, but if I just grab the source from /src/bodyScrollLock.js and paste it into my project and import from there, the scroll to top problem on iOS is gone, it just works then.

That's probably why Vercel forked and published it without major changes.

ondrakoupil commented 9 months ago

I bumped into this issue as well. The cause is in function setPositionFixed():

      document.body.style.top = -scrollY;
      document.body.style.left = -scrollX;

ScrollX and scrollY are numbers, document.body.style.top expects CSS value with unit. This code practically tries to set invalid unitless value, which is OK in many browsers, but iOS Safari is strict and discards it. Adding unit fixes the issue.

      document.body.style.top = -scrollY + 'px';
      document.body.style.left = -scrollX + 'px';

Current source already has this change implemented, but the published ESM build is stuck to older version for some reason.

minicatsCB commented 8 months ago

A think the bug is partially fixed. This line is still missing the px suffix.

Found these alternatives, both seem to be a fork of the original body-scroll-lock:

rick-liruixin commented 7 months ago

They stopped the repairs. I had to do it myself, in the same way, with a new version of typeScript. And fix these problems for everyone to use. add react hooks、vue3 example

npm i body-scroll-lock-upgrade

repair log,Refer to the releases page.