Unable to use websockets
Description
I followed the WebSocket setup as described in the JStack docs, but I encountered the following errors:
-
async/await is not yet supported in Client Components, only Server Components. This error is often caused by accidentally adding 'use client' to a module that was originally written for the server.
-
A component was suspended by an uncached promise. Creating promises inside a Client Component or hook is not yet supported, except via a Suspense-compatible library or framework.
-
TypeError: socket.on is not a function
Reproduction Steps
- Started from the official JStack WebSocket example.
- Implemented the WebSocket connection as shown in the docs.
- Ran the project and encountered the above errors.
I've to admin that the documentation could be really improved, but following the example provided on the website you MUST provide a validation schema for incoming and outgoing data, this should solve your problem n.3 .
const chatValidator = z.object({
message: z.object({
roomId: z.string(),
message: z.string(),
author: z.string(),
}),
});
chat: j.procedure
.incoming(chatValidator)
.outgoing(chatValidator)
.ws(({ c, io, ctx }) => ({
By doing this my lint becomes happy.
fair, using them without validators should be possible too. if you could pr that would be awesome