Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
claus opened this issue Aug 2, 2023 · 3 comments
Open

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

claus opened this issue Aug 2, 2023 · 3 comments

Comments

@claus
Copy link

claus commented Aug 2, 2023

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.

@claus claus changed the title ESM build broken ESM build broken, causes scroll-to-top on iOS Aug 2, 2023
@ondrakoupil
Copy link

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
Copy link

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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants