Autrun not picking up sub.ready() on ios device

I’m having this weird problem. I have a subscription set up inside of autorun, and if I console.log sub.ready() it never gets to true - but only in Cordova on a physical device. It’s fine on the simulator or in a browser.

Additionally, if I add an onReady handler to the subscription, that returns fine, and I can even grab the data I want through Coll.find(), but Tracker still never sees the ready change.

Even more strangely, if I trace out the autorun handler inside of onReady, sometimes it actually works…

I’ve tried a bunch of different configurations, including using SubsManager, and not, rearranging things, putting everything inside the autorun function, moving some stuff around, nothing seems to reliably fix this problem.

Has anyone else noticed reliability problems with autorun subscriptions inside Cordova?

// track the grid
autoruns [gridSlug] = Tracker.autorun (function () {

  // subscribe to the grid publication for gridSlug (must be in autorun)
  const gridSub = gridSubs.subscribe ('grids', gridSlug, {
    onStop (error) {
      console.log(error)
    },
    onReady () {
      console.log(gridSub.ready(), Grids.findOne ({ slug: gridSlug }))
      console.log(autoruns [gridSlug])
    }
  })

  console.log (gridSub.ready()) // almost never true in corodova on a device
})

This was happening in various versions of Meteor 1.3, including 1.3.3

Kevin N.

Okay, I just noticed that it’s been stopped. Why would that be happening?

At this point i’d rather just rely on an object I can reliably configure (that doesn’t do any magic, like stopping - without calling the onStop method I have in the code above) callback that reliably runs, rather than dealing with autorun magic, which doesn’t seem reliable.

Is there an alternative way to wire up a reactive function, and configure what it reacts to manually/directly?

Based on this I made a workaround, where I check if the Computation has stopped earlier up the chain, and reset the autorun if it has been stopped.

I’d really like more information about what stops a Computation, and why this one in particular is being stopped only in Cordova, and only on a physical device.

@captainn any news about this issue? I think I’m experiencing the same.

I put in a workaround to simply always recreate the computation. I think react-meteor-data does something similar: https://github.com/meteor/react-packages/blob/devel/packages/react-meteor-data/ReactMeteorData.jsx#L68

I don’t use this model for data any more - I switched everything to an offline first model, where the data is loaded over a method into ground:db instances. I probably won’t be able to help much beyond that.

1 Like

Thank you :wink:

I was able to implement the same behavior without reactivity.