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

Subscriptions inside tracker statements get duplicated #24

Open
JoaoCardoso193 opened this issue Nov 14, 2022 · 3 comments
Open

Subscriptions inside tracker statements get duplicated #24

JoaoCardoso193 opened this issue Nov 14, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@JoaoCardoso193
Copy link

JoaoCardoso193 commented Nov 14, 2022

Hey, I seem to be having an issue or potentially misunderstanding tracker statements.

I see that in the Readme file, there is a Meteor.subscribe call inside a tracker statement $m. If I do that in my meteor app, my subscriptions get multiplied. If I use Tracker.autorun instead, they don't.

Using "$m" for the "mainObjects-sources" subscription:
image
image

Using Tracker.autorun:
image
image

Could you please clarify what exactly is the difference between using $m and Tracker.autorun? And why should we put "Meteor.subscribe" calls inside tracker statements if it leads to the subscriptions being multiplied?

Thanks!

@zodern zodern added the bug Something isn't working label Nov 14, 2022
@zodern
Copy link
Owner

zodern commented Nov 14, 2022

Thanks for reporting this. Subscriptions should work the same with both $m and Tracker.autorun, with $m automatically ending the subscriptions when the component instance is destroyed. I will see if I can reproduce the subscriptions being duplicated. In your code, where is mainObjectId coming from, and when can it change?

@JoaoCardoso193
Copy link
Author

JoaoCardoso193 commented Nov 14, 2022

Hi, thanks for your quick response!

mainObjectId is the id of the currently displayed item on this page. It is fed to the page through the URL:
image
image

It never changes.

@tosinek
Copy link

tosinek commented Dec 8, 2022

Do you have rdb:svelte-meteor-data installed? I just came across a similar thing, that the sub was called twice (two different ids). Removing svelte-meteor-data fixed it.

With the zodern's suggested implementation (while having svelte-meteor-data installed) it was even causing a memory leak (when the page was embedded on another page), creating thousands of subs (thanks MontiAPM for pointing me in the right direction)
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants