firebase-mock icon indicating copy to clipboard operation
firebase-mock copied to clipboard

MockFirestore: `RangeError: Maximum call stack size exceeded` when setting a ref with `{merge: true`}

Open jhickey opened this issue 7 years ago • 1 comments

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.

jhickey avatar May 15 '18 21:05 jhickey

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).

soumak77 avatar May 19 '18 15:05 soumak77