Websocket with Next appdir/RSC?

With the new RSC paradigm, how would we write a React app with Websocket (say for example a discord clone)? Do we still do it similar to how it has always been done or is there a new (better) pattern for these types of apps? How would this change if I already have a functional backend vs just starting everything from scratch?
Solution:
You generate the html with the server component and let the client component do the rest
Jump to solution
6 Replies
Neto
Neto2y ago
Client component connecting to ws
Solution
Neto
Neto2y ago
You generate the html with the server component and let the client component do the rest
cornflour
cornflourOP2y ago
so as far as the websocket part itself is concerned, its the same as before, and the change that the layout stuff can be server components?
Neto
Neto2y ago
Yeah
cornflour
cornflourOP2y ago
got it, tysm!
Aland
Aland2y ago
If you don't want to use Websockets an alternative is HTTP streaming, user makes a GET request and connection is being kept open, the server can send new messages when it comes in via a POST request. https://nextjs.org/docs/app/building-your-application/routing/router-handlers#streaming
Routing: Route Handlers
Create custom request handlers for a given route using the Web's Request and Response APIs.
Want results from more Discord servers?
Add your server