From 6f4a26ea71dd2db3a070569095ca2e4610a6fdfb Mon Sep 17 00:00:00 2001 From: Nathan Muir Date: Wed, 30 Mar 2022 11:29:12 +1300 Subject: [PATCH] autoSubscribe: only stop subscriptions if the arguments change --- packages/vue3/src/index.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/vue3/src/index.ts b/packages/vue3/src/index.ts index fac593d..3cb138a 100644 --- a/packages/vue3/src/index.ts +++ b/packages/vue3/src/index.ts @@ -65,8 +65,23 @@ export function autoSubscribe (callback: () => [name: string, ...args: any[]]): }) onInvalidate(() => { - sub.stop() computation.stop() + // Do not stop the subscription immediately + // if we resubscribe with the same arguments, + // meteor will reuse the previous subscription + // See meteor/ddp-client + const id = sub.subscriptionId + if (Meteor.connection._subscriptions[id] != null) { + // mark inactive + Meteor.connection._subscriptions[id].inactive = true; + // check again after we resubscribe, if still inactive, cancel + Promise.resolve().then(() => { + const handle = Meteor.connection._subscriptions[id]; + if (handle && handle.inactive) { + handle.stop(); + } + }) + } }) }, { immediate: true,