UI Kit (React) - Two browser tabs interefere with each other

I’ve integrated CometChat into my React app using the UI Kit. I’m now encountering a problem where if I open my app in a second browser tab, I get errors/weird behavior in the CometChat code. (Instead of creating a new user, it seems like the CometChat user already exists in the second tab, etc).

Do you have any recommendations on how I can keep separate browser tabs from sharing the same CometChat data? Since my page is a single page js app, I don’t really want separate tabs or chrome windows to share the same cometchat instance.

Thanks

Hello @justinfaulkner,

Can you please let us know which version of the SDK are you using. We have added support for multiple tabs in v2.0.10. Please update to this version if you are not already using it.
Also, can you please let us know what exactly are you trying to achieve, so that we can help you in implementing CometChat in the most efficient way.

Warm Regards,

CometChat Pro
Mayur Bhandari

1 Like

I’m already using:

"@cometchat-pro/chat": {
      "version": "2.0.10",
      "resolved": "https://registry.npmjs.org/@cometchat-pro/chat/-/chat-2.0.10.tgz",

For “what exactly are you trying to achieve”: I am building a React web app, it is a “Chat” app. Everyone is a guest (there is no login). Each browser window/tab that visits the site should be considered a separate user. All of this works fine in my app, until I integrated CometChat. But when I open my site in a second browser tab, although my app code still works fine and treats the second tab as a new user, I’m encountering behavior where CometChat seems to have created a CometChat user and saved some data either to cookie/session/local storage, and tries to share user/instance data between my Chrome tabs.

Hello @justinfaulkner,

This is the default behavior, the problem here is that for a browser the local storage is shared by default. One cannot have separate local storage for each tab.

Whenever you call CometChat.login() we save the logged-in user in local storage, so when you open another tab and call CometChat.init(), this time there is a logged-in user saved in the local storage so it connects to the WebSocket with the logged-in user.

You cannot log in using any other user in the same browser. If you call CometChat.logout() in any of the tabs, it will logout the user from all the tabs. If you open up n number of tabs and call CometChat.login() it will log in the same user in all the tabs.

Warm Regards,

CometChat Pro
Mayur Bhandari