firebase-mock
firebase-mock copied to clipboard
MockFirestore: `RangeError: Maximum call stack size exceeded` when setting a ref with `{merge: true`}
Hi, apologies if I'm doing something wrong here, but in MockFirestore, attempting to set a ref with merge:true enabled is causing a loop. Example:
const ref = mockfirestore.doc(`/path/to/some/doc`);
await mockfirestore.doc(`/path/to/some/other/doc`).set({
myRef: ref
}, {merge: true});
results in
RangeError: Maximum call stack size exceeded
at removeEmptyFirestoreProperties (/path/node_modules/firebase-mock/src/utils.js:1:1)
at removeEmptyFirestoreProperties (/path/node_modules/firebase-mock/src/utils.js:121:19)
at removeEmptyFirestoreProperties (/path/node_modules/firebase-mock/src/utils.js:121:19)
...etc
The issue appears to be that refs contain a circular reference, so when removeEmptyFirestoreProperties recursively loops through the object keys it's getting stuck there.
Your code is correct. Currently the firestore mocks do not support saving a reference, which is a bug. Similarly, queries are not working with references either (https://github.com/soumak77/firebase-mock/issues/78).