Hi.
We have a page (A) which has socket element in NodeJS SPA.
If I click on some link on page (B) to go to A, the socket connection is established and everything works well.
Now, if I navigate to another page from A to say C, sockets stop working. Which is good.
Next, if I press browser back button while on C, page A loads but socket connection is not established. Breaking the page.
I am a bit confused on the context of your points. So here’s what you might be looking for:
Page A - has socket component.
Page B - no socket stuff.
Page C - no socket stuff.
Yes. But not sure if that is the reason for this issue.
B → A is fragment load, where socket connects.
A → C is another fragment load, where socket gets disconnected.
C → A is not a fragment load, since browser is just showing previous page from cache or something (not entirely sure)… which is why socket connection is not invoked again.
Does page A and page B uses the same base template?
Interesting. So, just to confirm, from page B to A it’s an internal/SPA link?
Ok, correct it’s not a fragment load, but it’s still handled by Wappler’s framework as this is not a browser-native behaviour (Wappler’s SPA is using pushstate and popstate)
If you answered Yes to the 1st question open a bug report
From what I understand, the behaviour of sockets disconnecting on navigation is ok. Which is what is happenning in the linked post.
But, in this case, the problem is that when navigating back to the page, socket does not automatically reconnect.
I think it has to do with the bfcache of the browser, it should normally not do this when there is a websocket connection open. When it uses the bfcache it restores the page from a local cache instead of reloading it.
Thanks for the info.
Its not a major inconvenience at the moment, because of low number of active users, but still a problem. Hope you can find a solution for this.