francoischalifour / medium-zoom

🔎🖼 A JavaScript library for zooming images like Medium
https://medium-zoom.francoischalifour.com
MIT License
3.58k stars 162 forks source link

Access window and documents in function scope #94

Closed meteorlxy closed 5 years ago

meteorlxy commented 5 years ago

Bug description

In v0.4.0, we only try to access window / document in the function scope, i.e. all related code is wraped in the mediumZoom function:

https://github.com/francoischalifour/medium-zoom/blob/8617c954d5690de3c692560e7ddcc02016c232ac/src/medium-zoom.js#L29-L39

In v1.x, we access window / document outside the mediumZoom function:

https://github.com/francoischalifour/medium-zoom/blob/e1b85df73d4642fb51f82a21242b24c92ded4005/src/medium-zoom.js#L104-L111

I'm using medium-zoom in a server-rendered project, but window / document can only be accessed in client. The differences cause errors when I try to migrate to v1.x from v0.4.0.

If it won't be fixed, I think it is one of the breaking changes that should be listed.

francoischalifour commented 5 years ago

Thanks for filing an issue.

There's a simple fix to this without actual tradeoff so we might actually want to add support for SSR here.

Would you mind opening a PR?

meteorlxy commented 5 years ago

With pleasure 😄