Vent Publications Never Die... They Duplicate.
See original GitHub issueIn integrating Vent into my app, I just noticed through debugging that my Vent publication is duplicating responses to subscriptions and continuing to fire messages after calling handler.stop()
. When client browsers get refreshed or are HCR’d (Hot Code Reload), you end up getting lots of duplicated publish responses.
I have a publication:
Vent.publish({
'manualReactivity': function(someId) {
this.on('manualReactivity::' + someId + '::updated', function(response) {
console.log("manualReactivity PUBLISHER running...");
return response;
});
}
});
I have my Vent.subscribe
call in my parent-most template so it can always be listening for updates. In my parentTemplate.onCreated
I am subscribing:
var instance = this;
instance.manualReactivityListener = Vent.subscribe('manualReactivity', instance.someId);
instance.manualReactivityListener.listen(function(response) {
// Do stuff...
});
In my parentTemplate.onDestroyed
I am stopping the listener which I thought would tear everything down:
var instance = this;
instance.manualReactivityListener.stop();
If I open four browsers and watch the console on the server after triggering a Vent.emit('manualReactivity::someId::updated', {someObject});
in my code somewhere, I see the following expected output:
manualReactivity PUBLISHER running...
manualReactivity PUBLISHER running...
manualReactivity PUBLISHER running...
manualReactivity PUBLISHER running...
If I then refresh all four client browsers, and trigger the Vent.emit
again, the output is duplicated with the old subscriptions and the new ones created by the refresh:
manualReactivity PUBLISHER running...
manualReactivity PUBLISHER running...
manualReactivity PUBLISHER running...
manualReactivity PUBLISHER running...
manualReactivity PUBLISHER running...
manualReactivity PUBLISHER running...
manualReactivity PUBLISHER running...
manualReactivity PUBLISHER running...
Same if I an HCR happens. After lots code updates and HCRs in development, I noticed the output above really growing.
At first I thought the problem was that my template.onDestroyed
wasn’t getting called because of issues with the window closing/refreshing and it not having time to run the onDestroyed
. I thought maybe it needed to go into a window.addEventListener('beforeunload')...
Before doing that, I tried testing instance.manualReactivityListener.stop();
by moving it to somewhere I can trigger. After running the line, I do see that the subscription code on my client stops running as expected. But the the above output from the publication code keeps running and duplicating.
What’s the Vent policy on ending publications? Are they not killed when calling handler.stop()
? Do they die after a certain amount of time? Could this be problematic for the server - with 1000+ clients?
If needed, I can submit a repo, but this is easy to duplicate.
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (7 by maintainers)
Top GitHub Comments
@evolross Suppose you wrote something like:
Yes, you would probably use a loop, but we’re illustrating that
this.on
could be called multiple times in the one publish handler.Ah… understood. I see the use-case now. Thanks!