ParseReact
ParseReact copied to clipboard
Exception thrown: "TypeError: undefined is not an object (evaluating 'mutation.action')" in ObjectStore.js
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
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?
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 I am having the same issue, how did you manage to solve it?
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