Mergebox broken?


#1

Hi Meteor enthuthiasts !

Here’s my problem : I have a navbar template, where I subscribe to a “home.posts” publication that fetch last ten posts, then iterate through them and add them t the client (no observer, no reactivity).

Then, when my user enter a discussion, he already have the first in minimongo, and subscribe to all the posts in the current discussion (the first one included) with a “get.discussion” publication. This time, the publication use oberservers and is entirely reactive (added, changed, removed).

My problem there is that when I like a post in the currently opened discussion, if it is a reply, it works perfectly well, but if it is the first posts (which is shared by the non reactive sub from navbar and the reactive one from the discussion page, both sending the exact same fields), my minimongo instance (and therefore, my view), is not updated ! The server correctly add a like to the post in the DB, the observer from the “get.discussion” does well log the correct callback, with the updated field and the good doc _id. But the client will either :

  • receive the doc in minimongo then remove it instantly
  • don’t receive it at all.

And this only happens for the first post of each discussion, which is the only one shared by both the reactive and non reactive publish.

And I’ve got no sweety icecream idea why :frowning:

Am I missing anything about how Meteor works ?

// subscribed from the navbar (once only in a client session, accross any page)
  Meteor.publish("home.posts", function () {
	if ( this.userId ) {
		unblock( this );

		const self = this;
		
		let cursor = queryGet({
										type 				: 'posts',
										method			: 'find',
										query				: {},
										projection	: { sort		: { date: -1 },
																		limit		: ( 10 ),
																		fields	: POSTS_FIELDS_.NO_TAGS_
																	}
								});

		let posts = cursor.fetch(),
				i = -1;

		while ( posts_array[ ++i ] ) {
			self.added( "posts", posts[ i ]._id, posts[ i ] );
		}
		
		this.ready();
	}
});

   // subscribed from a discussion page
  Meteor.publish("getTalkthread", function () {
    unblock( this );
        const self = this;

	let cursor = T.queryGet({
    			type 				: 'posts',
    			method			: 'find',
    			query				: { $or: [
                            { _id			: thread_id },
                            { parent	: thread_id }
                          ]
                        },
    			projection	: { sort		: { _id: 1 },
    											limit		: limit,
													fields	: POSTS_FIELDS_.NO_TAGS_
    										}
    		});

	let observer = posts_cursor.observeChanges({
		added	( id, fields ) { self.added  ("posts", id, fields);	},
		changed	( id, fields ) {
			console.log( id, fields );
			self.changed("posts", id, fields);
		},
		removed ( id ) { self.removed("posts", id); }
	});

	// Ready
	this.ready();
  this.onStop( observer.stop );
});