vue-meteor-tracker
vue-meteor-tracker copied to clipboard
Errors in publications aren't handled properly
Using the $subscribe
function with Vue dynamic arguments doesn't work properly if the publication throws an error.
- The previous subscription (which didn't have an error) is not stopped, so the data persists client-side.
- There is no way to display or otherwise react to the error on the client.
In my app, this results in a situation where the subscription update fails silently (and $subReady
never updates), and then a new subscription without error results in both the data from the old and new subscription being displayed.
Not all subscriptions can be validated and guaranteed not to have an error client-side, so this creates a bit of a mess with regard to possible user error.
The issue is caused by this block of code:
const autorun = this.$autorun(() => {
// Failed subscription will never be ready
const ready = handle.ready()
set(this.$data.$meteor.subs, key, ready)
// So the following code will never be executed
if (ready && oldSub) {
this.$stopHandle(oldSub)
}
})
There is no way to display or otherwise react to the error on the client.
Actually it's partially possible:
$subscribe: {
'sub.name': [arg1, arg2, {
onStop(err) { if (err) /* do something */ }
}]
}
It must be possible to use onStop
callback in the package code as well to determine whether a subscription is not ready due to error. Then with a condition
if ((ready || error) && oldSub) {
this.$stopHandle(oldSub)
}
the issue must be solved.