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

SSR on Next.js doesn't work #32

Closed
yagudaev opened this issue Jun 16, 2021 · 4 comments
Closed

SSR on Next.js doesn't work #32

yagudaev opened this issue Jun 16, 2021 · 4 comments
Labels

Comments

@yagudaev
Copy link

Thank you for this great component 👍 . I can't wait to use it!

I tried to use it on my Next.js project and it complained about:

SyntaxError: Cannot use import statement outside a module

The reason is that node.js assumes you use common.js modules unless you have type: 'modules' in the package.json. I quickly manually changed the code to use commonjs modules (require and module.exports). However, it still requires window.document somewhere in the code.

I'm not sure how other libraries do this, but it seems to work flawlessly with say react-color (https://github.com/casesandberg/react-color). It might be a good place to start to find out.

If you have any quick work arounds that would be great too, I tried the one mentioned here: https://nextjs.org/docs/advanced-features/dynamic-import#with-no-ssr, but since this lib uses named exports it didn't quite work.

@sneas
Copy link
Owner

sneas commented Jun 16, 2021

Hi Michael, thank you for the detailed explanation of the issue. I'll give it a look, hopefully, this week.

And thank you for your kind words and for the ⭐️, this means a lot to me 🥦

@yagudaev
Copy link
Author

yagudaev commented Jun 16, 2021

Workaround:

import dynamic from 'next/dynamic

// Img Comparison Slider cannot be server-side rendered
const ImgComparisonSlider = dynamic(() => import("@img-comparison-slider/react").then((mod) => mod.ImgComparisonSlider), {
  ssr: false
})

This work really well for the time being ^.

There is a thread here about issues with other libraries too: asyncapi/asyncapi-react#177. Would be cool to make the lib SSR compatible.

@sneas sneas closed this as completed in e023ebe Jun 18, 2021
sneas pushed a commit that referenced this issue Jun 18, 2021
## [5.0.2](v5.0.1...v5.0.2) (2021-06-18)

### Bug Fixes

* **react:** align class names between web and react commponents ([d9c7df5](d9c7df5))
* **react:** align tabindex between web and react components ([be8cfdc](be8cfdc))
* consider tabindex attribute ([ebc4a9a](ebc4a9a))
* reevaluate slider position on component's size change ([e03e798](e03e798))
* **react:** ssr ([e023ebe](e023ebe)), closes [#32](#32)
@sneas
Copy link
Owner

sneas commented Jun 18, 2021

🎉 This issue has been resolved in version 5.0.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@sneas sneas added the released label Jun 18, 2021
@sneas
Copy link
Owner

sneas commented Jun 18, 2021

Hi Michael, the issue has been resolved in @img-comparison-slider/react version 5.0.2.

The component could be used as described in the documentation https://github.com/sneas/img-comparison-slider/blob/master/bindings/react/README.md

Cheers!

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

No branches or pull requests

2 participants