magic-akari / seamless-scroll-polyfill

Scroll Behavior polyfill
https://www.npmjs.com/package/seamless-scroll-polyfill
MIT License
159 stars 12 forks source link

Next build not works #131

Closed bezzskilla closed 2 years ago

bezzskilla commented 2 years ago

i was using old your API for a long time. Now i decided to upd it to 2.1.6. So I rewrite method windowScrollTo

My code: import { windowScrollTo } from 'seamless-scroll-polyfill';

<div onClick={handleScroll} className={className}> {children} </div> and handleScroll is calculating offsetPosition and scroll in the end: window && windowScrollTo(window, { top: offsetPosition, behavior: "smooth", });

All is perfect when i check next dev in Next.js, but it not works, when I use next build I tryied another methods like windowScroll or do it in try-catch or check isWindow but without success

magic-akari commented 2 years ago

Thank you for your feedback. Can you provide a minimal reproduction to help me locate the issue?

bezzskilla commented 2 years ago

yep, some time

bezzskilla commented 2 years ago

https://codesandbox.io/embed/next-js-forked-77c1t0?fontsize=14&hidenavigation=1&theme=dark

code like this but u shold do next build and next start for my case. I think sandbox couldnt do it

magic-akari commented 2 years ago

Are you using the next@3?

magic-akari commented 2 years ago

Test on next@12 and everything is OK. So the issue may be that next@3 can not select esm/cjs correctly.

nextjs-blog.zip

bezzskilla commented 2 years ago

i use next 11

magic-akari commented 2 years ago

seamless-scroll-polyfill@2.1.6 works well on both next@11 and next@12. There are some compatibility issues in next@10. I have just released 2.1.7 to improve compatibility. I test it from next@8 to next@12, it works well. For versions below next@8, I couldn't continue testing because of some compatibility issues between React and next.

magic-akari commented 2 years ago

Since you are using next 11 so you may be experiencing a different issue. But it's still worth trying to upgrade to 2.1.7.

bezzskilla commented 2 years ago

so, i locally created next app. On last version all is okey. But on next 11.1.3its not working. I can give u repository with code if u want. i was using scroll 2.1.7 I also understand that this is not the latest version, so it may not be rational to fix something on it, I just inform you

bezzskilla commented 2 years ago

By the way 11.1.3 is the latest version of 11 next

magic-akari commented 2 years ago

Does the 2.1.7 version works on next@11.1.3 ?

bezzskilla commented 2 years ago

no, check it pls https://github.com/bezzskilla/scroll-bug

dev - works build + start - not works

scroll api - 2.1.7 next - 11.1.3

magic-akari commented 2 years ago

Thanks, it helps a lot. I will check it out in depth.

magic-akari commented 2 years ago

The webpack in next@11 cannot handle ?? logic correctly. The following code will be inlined and transformed into wrong result.

https://github.com/magic-akari/seamless-scroll-polyfill/blob/8c0841374ba6b824024486a357141878ab844276/src/scroll.ts#L21-L28

This issue will be bypassed in these cases.

I just released 2.1.8. which downgraded the build target to es6.

bezzskilla commented 2 years ago

nice! thx, i'll check it in the evening

bezzskilla commented 2 years ago

thx again, all works perfect!