ParseReact icon indicating copy to clipboard operation
ParseReact copied to clipboard

Exception thrown: "TypeError: undefined is not an object (evaluating 'mutation.action')" in ObjectStore.js

Open iamdoron opened this issue 10 years ago • 4 comments

Sometimes I get the following error:

TypeError: undefined is not an object (evaluating 'mutation.action')  ObjectStore.js:396  (version 0.4.2)

Which is the second line in the following code:

for (var i = 0; i < pendingMutations[id].length; i++) {
      mutation = pendingMutations[id][i].mutation;
      if (mutation.action === 'DESTROY') {
        return null;
      }
      mutation.applyTo(base);
      base.updatedAt = pendingMutations[id][i].date;
    }

From what I gather, it can be reproduced when you rapidly mutate the same object, and it happens due to a race condition. I'm not familiar exactly with the object store, but it seems that resolveMutation is called just before getLatest, which means there is a pending mutation that has the delta property and from which the mutation property has been removed.

The use case that brought me here is a checkbox that mutates a boolean key every time it changes

error

iamdoron avatar Jul 08 '15 18:07 iamdoron

Interesting. It's hard to imagine a race condition being an issue, since everything is single-threaded, but I'll dig into this. Do you have a simple demo that reproduces this bug reliably?

andrewimm avatar Jul 27 '15 20:07 andrewimm

when I said race condition I meant in the broader sense - that some async functions are running in an unexpected order (I don't know how else to call it). to reproduce it just rapidly mutate an object with the Set function

for example:

for (var i = 0; i<1000; ++i) {
  ParseReact.Mutation.Set(this.data.user, {
      test: !this.data.user.test
    }).dispatch();
}

iamdoron avatar Jul 27 '15 22:07 iamdoron

@iamdoron I am having the same issue, how did you manage to solve it?

yogurt-island-331 avatar Oct 29 '15 01:10 yogurt-island-331

Having same issue as well, if i add/remove an object a few times (not very quickly, say once every 2-3 seconds) using ParseReact.Mutation.AddUnique and ParseReact.Mutation.Remove

nikkool avatar Nov 16 '15 07:11 nikkool