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

Manager interfering with ReactMeteorData #55

Open
tomitrescak opened this issue Sep 17, 2015 · 3 comments
Open

Manager interfering with ReactMeteorData #55

tomitrescak opened this issue Sep 17, 2015 · 3 comments

Comments

@tomitrescak
Copy link

Hi, first thanks for this optimisation item without which I cannot imagine my applications to be. I have found a possible bug in the implementation, when subscription manager is interfering with "ReactMeteorData" mixin. I am attaching a minimal repro application.

The problem is, that if you use a component with subscriptions inside another component with subscriptions, it is invalidating the parent subscriptions, making them run twice or more. Example:

I have following components and only parent has subscriptions:

<Parent>
<Child>
</Parent>

If I put following line inside paren's "render" method console.log("With: " + this.data.posts) where data is fed with following method:

getMeteorData() {
    this.data = { }
    var handle = subs.subscribe("posts");
    if (handle.ready()) {
      this.data = {
        posts: Posts.find().fetch()
      }
    }
    return this.data;
  },

The output is following as expected:

With: undefined
With: undefined
With: [object Object],[object Object],[object Object]

Now I add another subscription inside child component as following:

  getMeteorData() {
    this.data = { }
    var handle = subs.subscribe("user", this.props.post.uid); // Replace with Meteor.subscribe and all is good
    if (handle.ready()) {
      this.data = {
        user: Usrs.findOne({uid: this.props.post.uid})
      }
    }

    return this.data;
  }

Output becomes:

With: undefined
With: undefined
With: [object Object],[object Object],[object Object]
With: undefined
With: [object Object],[object Object],[object Object]

Somewhere there, the subscription invalidated meteor data and it ran again creating havoc in the application. Please note, that when I replace subs.subscribe with Meteor.subscribe all is running as expected and data is not invalidated.

Example minimal app is here 6Kb.

@arunoda
Copy link
Contributor

arunoda commented Sep 18, 2015

Yes. I can understand the issue. I think it's hard to mitigate this unless, you create two instances of subsManagers to each component.

I've added some notes here: https://goo.gl/9PeI1Q

@tomitrescak
Copy link
Author

Thanks! Just a question regarding performance .. .will that affect subsmanager performance if I will be creating a new instance of subs manager per each subscription? Will that interfere with its functionality ?
Thanks.

@arunoda
Copy link
Contributor

arunoda commented Sep 18, 2015

Nope. It create caches separately.

On Fri, Sep 18, 2015 at 7:25 AM Tomas Trescak [email protected]
wrote:

Thanks! Just a question regarding performance .. .will that affect
subsmanager performance if I will be creating a new instance of subs
manager per each subscription? Will that interfere with its functionality ?
Thanks.


Reply to this email directly or view it on GitHub
#55 (comment)
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants