Closed nazacity closed 2 years ago
React pin field has been rewritten in web component since the v2, so I'm not surprised SSR does not work. I will try to investigate.
EDIT: I found this article https://dev.to/swyx/how-to-use-web-components-with-next-js-and-typescript-4gg1. Maybe this could be the solution?
This issue is making this component impossible to work with in Gatsby. I think the above solution needs to be implemented in react-pin-fields as a fix.
I'm quite busy these days, I will try to take some time to fix this issue. I will let you know!
Thanks @soywod. My workaround is to load the component lazily using React.lazy and React.Suspense. Without that, both SSR and component unit tests fail.
If you're using NextJS you can do the following:
import dynamic from "next/dynamic";
const ReactPinField = dynamic(() => import("react-pin-field"), { ssr: false });
After searching on the subject, I came to the conclusion that there is nothing I can do there:
react-pin-field
is imported and used (Webpack, Next, Gatsby…)react-pin-field
to be rendered server side, it is a client feature. So the solution to import dynamically the component makes sense (and it is how web components seem to be treated right now)I will add a side note in the README about SSR and link to this issue. Feel free to add more workarounds about how to import dynamically the component!
The native web component was a big mistake, it led to so many issues… I ended up rolling back to v1 state, without web component (pure React implementation). The SSR should work back as expected starting from the v3.0.11
.
I got ReferenceError: HTMLElement is not defined when try to implement on Nextjs