You can stop an observer. The observe method return a handle with a stop method:
const handle = cursor.observe(...);
// more code ...
handle.stop(); // to stop the observer.
You would normally define an observer once for any cursor. Its presence in a function body bothers me, although I can’t see that it should cause an issue.
Your workaround indicates you are running this inside an autorun (see point 2). It is true that stopping the computation will also stop an observer (if the observer is in the autorun).
Are you observing this cursor (or another on the same collection) elsewhere?
Other than stating that, all things being equal, your added should only be triggered once per new document, I don’t think I’m seeing enough code to comment sensibly. However, that’s never stopped me before
Since you appear to be running this in an autorun, you could try the reactive: false option on your cursor. From the observe docs:
If the cursor was created with the option reactive set to false, it will only deliver the initial results and will not call any further callbacks; it is not necessary to call stop on the handle.
So I put it in the constructor so it’s only done once. But it stops the page from loading, probably because this.messages has not been initialized yet.
Thank you for all the suggestions, I was feeling a little lost, but now I have a lot of things to try.