perak / meteor-joins

Collection joins for Meteor
77 stars 7 forks source link

Exception when joined collection is updated and reactive is enabled #18

Closed leite08 closed 6 years ago

leite08 commented 6 years ago

First, thanks for making this library available!

We're using it to make a reactive join between 2 collections, similar to this:

Company {
  name
}
Document {
  name,
  companyId,
}

The relationship is defined as:

Companies = new Meteor.Collection('companies');
Documents = new Meteor.Collection('documents');
Documents.join(Companies, "companyId", "company", ["name"]);

Then we publish the list of documents:

const cursor = Documents.find();
return Documents.publishJoinedCursors(cursor, { reactive: true }, this);

From there we display the data, with the library working as expected.

Then we update the database:

  1. Update the first document's name: OK
  2. Update the first company's name: FAILED

The first update works as expected, with the page reactively updated without the need of refresh.

The second update generates the exception below on the server:

Exception in changed observe/observeChanges callback: ReferenceError: Random is not defined
     at Object.changed (packages/perak_joins.js:275:104)
     at _CachingChangeObserver.changed (packages/minimongo/local_collection.js:1315:28)
     at applyChange.changed (packages/minimongo/local_collection.js:727:27)
     at runWithEnvironment (packages/meteor.js:1188:24)
     at packages/meteor.js:1201:14
     at packages/mongo/observe_multiplex.js:182:30
     at Array.forEach (<anonymous>)
     at Function._.each._.forEach (packages/underscore.js:139:11)
     at Object.task (packages/mongo/observe_multiplex.js:176:9)
     at Meteor._SynchronousQueue.SQp._run (packages/meteor.js:819:16)

I've created a branch on a Meteor+React repo to reproduce the error.

Clone the branch: git clone -b perak-joins-issue-random-not-defined git@github.com:leite08/Create-React-Meteor-App.git

Run: meteor npm install --save react react-dom meteor

On a Mongo shell, run: db.companies.update({},{$set:{name:'aaa'}});

That should generate the exception above.

Curiously, the exception also happens when the reactive option is ommited.

perak commented 6 years ago

Hey @leite08 this is what I call bug report! Thank you! Working on it now...

perak commented 6 years ago

@leite08 Fixed.

Thank you! 👍

leite08 commented 6 years ago

Thanks @perak! And WOW, that's what I call quick bug fix! :) Cheers!

leite08 commented 6 years ago

Tested and it worked as expected, thanks!

It included another bug, though, reported here: #19