Next.js Discord

Discord Forum

ServerSideEvents / Singleton classed

Unanswered
Cape lion posted this in #help-forum
Open in Discord
Cape lionOP
Hey guys,

I’m currently trying to use server side events with next js. Fo that I created a class wich contains the state of connected clients and takes care of the state as new clients connect air disconnect.

So far this works.

Due to how next is rendering classes I cannot manage to share the class across multiple files.
The clients list is always empty because the class is always newly created.

I already tried several approaches to get a singleton class for this bug neither global nor globalThis works.

I’m currently totally lost and have no clue what else to try. Do you guys have ideas or solutions to this issue?

0 Replies