Socket on Content Page Capturing Emitts Multiple Times

Wappler Version : 4.6.2
Operating System : W10
Server Model: NodeJS
Database Type: PostgreSQL

How to reproduce

We created a fresh NodeJS SPA project with 1 layout page and two content pages - list & chat.
On click of a link in list page, chat page is opened.
The chat content page has socket component defined and a link to go to list page.
For testing, on chat page, we have a message input which submits value via server connect form.
In this server action, there is a emit of the same message configured.

On the chat page, the socket has dynamic element message defined to show the value from emit in a browser alert.

When I click on link in list page, and send a message multiple time, I always receive one browser alert for each message.

Now, I go back to list page and click the chat page link.
Then, on chat page, if I send a message, I receive two browser alerts for each message.
I can see in the WS type in Dev tools network tab that there is only 1 message being received from the server… but the client is running the message dynamic event multiple times.

Every time I repeat the back-forward flow, number of alerts increase by one.

If I move the socket component from content page to layout page, everything works fine.
Interestingly, I have another project where I have sockets on content page and it works as expected above.
But not in this newly createed project.

Are sockets not supported in content pages in SPA? Please help.

I think it doesn’t destroy the previous socket connection and creates a new one when you return to the chat page. I never tried it inside a content page, will check it out.

Thanks.
I tried on two projects… a new and an existing one. This was the behaviour on both.

But on one of my other existing projects (the one I gave you access to yesterday), socket is getting closed correctly in content page. Not sure why/how.

Please test this update, when the socket component is in a content page it didn’t unsubscribe from the events when the page changed, this update should fix that.

dmxSockets.zip (1.1 KB)

Perfect. That works as expected. :slight_smile:

This has been fixed in Wappler 4.7.2

This topic was automatically closed after 42 hours. New replies are no longer allowed.