I have a meteor react app.
I am having a problem where on the live (production) version, when I update a document, the subscription to the particular document goes away.
When I run it locally, everything works. I update the document, and maintain the subscription.
Here is the code…
This is how I am doing the subscription…
export default withTracker(() => {
const handles = [
Meteor.subscribe('singleDesign', Session.get('singleViewDocId')),
];
const loading = handles.some(handle => !handle.ready());
var doc = Designs.findOne(Session.get('singleViewDocId'));
return {
loading,
doc
};
})(EditDesign);
This is the code that runs when I submit the form to save the document (client side)…
Meteor.call('designs.update', Session.get('singleViewDocId'), values, (err,res) => {
if (err) {
console.error(err);
message.error("Something went wrong...");
} else {
form.resetFields()
message.success("Design updated");
}
})
The method that saves the document (server)…
'designs.update'(_id, doc) {
if (!this.userId) {
throw new Meteor.Error('Not authorised');
}
Designs.update({
_id: _id
}, {
$set: {
updatedAt: moment().valueOf(),
...doc
}
},{upsert:true});
},
The subscription…
Meteor.publish('singleDesign', function (_id) {
return Designs.find({$or: [{_id: _id, createdBy: this.userId}, {system:{$in: [true]}}]});
});
As mentioned, on local, it works flawlessly. I click to update the document and all the subscriptions (there are other ones as well) stay as they are and do not change.
On the live production version, I click to update the document, and I can see the subscriptions to the document I am saving, stops.
I don’t understand why the same code works locally but doesn’t on the live version.
I have also tried subscribing to all Designs (rather than just the one I am editing), and again, it works locally, but not on the deployed version. Funny thing is if I see 28 documents in the subscription while editing, then I click to update the document, I then see I only have 27 documents in the subscription. Basically, I lose the subscription to the document I am editing after I save it. Again, this only happens on deployed version.