Nextjs how to use websockets in a server side rendering setup

122 Views Asked by At

I newly discovered that using UseEffect is causing CSR Client Side Rendering and throwing away SEO benefits of getStaticProps or getServerSideProps. I use Websockets for realtime chatting and notifications and had a SocketContext component listening for incoming pings within a UseEffect and its cleanout function (the return callback inside UseEffect).

So am I now supposed to not use Websockets on the pages i want SSR or SSG to work and fetch possible missed realtime pings from the serverside? In the transition of the user from a serverside page to a not serverside page where websockets is again implemented, is that a big ux drawback?

Last Question, is it even doable to have a WebsocketContext Not in _app but in Layout components so they stay with some pages before being "new initialized" ?

By the way the project is in a Nextjs v12 and vpn setup

0

There are 0 best solutions below