Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

autoSubscribe: only stop subscriptions if the arguments change #11

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion packages/vue3/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down