socketio / socket.io

Realtime application framework (Node.JS server)
https://socket.io
MIT License
61.17k stars 10.11k forks source link

Only receiving first Message #5164

Closed Angeschossen closed 2 weeks ago

Angeschossen commented 3 months ago

Describe the bug After the first message is received, it no longer receives messages. Very rarely I dont receive any message at all. I only seem to experience this in the development mode (npm run dev of Next.js 14)

I have a very simple socket IO setup example below. Basically a simple page in the /app dir of Next.js and the API endpoint for the socket server creation in the old /pages dir. After the websocket server is created, it emits a message to the hello channel each second. When the page is loaded I only receive the message once. Very rarely, it works as intended. 90% of the time I only receive the first message.

I also noticed that it does some polling once a minute or so. I'm not sure why it does that, as the connection seems to be established and upgraded to websocket. Here is a screenshot from the network tab: Imgur This is how the developer console looks like: Imgur

No errors server side. Additionally, seems to fix itself after like 10 minutes, the messages start coming again.

To Reproduce You can find the example page (page.tsx), which is located in Next.js /app dir, and the API endpoint for the socket server creation, which is located in the old /pages/api dir, at this gist: https://gist.github.com/Angeschossen/84e1b50d93b5a0c1425eed4776a999d0

Next.js: v. 14.2.5 SocketIO and Client: 4.7.5

Expected behavior Each message should be received. As you can see the API endpoint emits a message every second.

Platform:

Additional context I have react strict mode disabled.

darrachequesne commented 1 month ago

Hi! Please check our Next.js example: https://socket.io/how-to/use-with-nextjs

darrachequesne commented 2 weeks ago

I think this can be closed now. Please reopen if needed.