socketio / socketio/socket.io

Socket.io-client fires "connect" event but can't send events to server

Open
#5,115 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

needs investigation package:socket.io-client
Dominant language
TypeScript
Stars
63.2k
Forks
10.3k
Avg merge
11d 20h
Merged PRs (30d)
2

Description

Describe the bug

If I leave my site domain and use the browser back button to return socket.io-client fires the "connect" event, but the client socket can't send any events to the server until the connection is disconnected and then reconnects or I refresh the page.

To Reproduce

Please fill the following code example:

Socket.IO server version: 4.5.4
Socket.IO client version: 4.5.4

Link to repl: https://replit.com/@ambil/socket-io-bug-example#index.js

  1. Click "Open website" to run code fiddle in a new browser tab
  2. Click the "Test Event" button. You'll see a new message appended to the list with each click that says: "event: button_clicked"
  3. In the same browser tab, navigate to a new domain (ex: google.com)
  4. Use the browser back button to navigate back to the previous tab
  5. Without refreshing the page, click the "Test Event" button. Notice a new message is not appended to the list, although the status shows "Connected"

Expected behavior
Since the client is firing off the "connect" event, I'd expect the server to acknowledge client events right away.

Platform:

  • Chrome for MacOS

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked Replit reproduction in index.js and reproduce the browser back-button sequence in Chrome on macOS. Trace the client connection state after the connect event and verify the Test Event button can send button_clicked without a page refresh, forced disconnect, or reconnect.

Written by the indexing model from the issue text.

Assessment

Tech stack
nodejs, typescript
Domain
frontend, networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.