Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add warning regarding using socket.data reference equality #436

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

nedgrady
Copy link

Related: socketio/socket.io#4935

This adds to the Socket#data, there are a few other places that mentioned socket.data

https://socket.io/docs/v4/server-instance/#fetchsockets
https://socket.io/docs/v4/server-api/#socketdata

So happy to move to either of these places.

Copy link

vercel bot commented Jan 31, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
socket-io-website ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 2, 2024 9:20pm


socket.on("disconnect", () => {
// ... however primitive values will be preserved
activeUsers.delete(socket.data.user.name);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two things that bother me with this example:

  • socket.data.user.name must be unique (implicitly)
  • using a map here means it won't work when scaling to multiple servers

What do you think?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, i've simply removed the 'Good' example. Hopefully just knowing it is bad will be enough to guide anyone who ran into the same problem as I did using a reference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants