Firebase-js-sdk: FieldValue.serverTimestamp() no longer serializable

Created on 29 Sep 2020  路  4Comments  路  Source: firebase/firebase-js-sdk

  • Operating System version: macOS 10.15.6
  • Browser version: Chrome 85.0.4183.121
  • Firebase SDK version: 7.21.1
  • Firebase Product: firestore

This change appeared after 7.15.0 (worked in 7.14.6).

console.log(JSON.stringify(firebase.firestore.FieldValue.serverTimestamp()));

> Uncaught TypeError: Converting circular structure to JSON
>    --> starting at object with constructor 'n'
>    --- property 's_' closes the circle
>    at JSON.stringify

The value references itself.
Screen Shot 2020-09-29 at 10 45 30 AM

firestore

Most helpful comment

All 4 comments

@cmditch Thanks for filing this. Almost all of our types will have this problem and I am trying to understand what the user impact is here. Can you describe your use case?

@cmditch Never mind. This is already fixed in the release that is going out this week. Thanks for catching it.

In short, we granularly track the state of a document, and need to serialize this latest version of the doc to pass off to our runtime (Elm).

Our stack is elm-lang + firebase. Elm is a compile-to-js language. If you want to talk to native javascript (e.g. firebase-js-sdk) from Elm you must use ports. Ports rely on JSON.stringify which allow decoders to work their magic. Long story short, since Elm <-> JS interop is not callback based, the cleanest way we've found to update the state of our Elm app is to pass the entire firestore document each time an alteration occurs.

The library we've written (elm-firestore) also uses hooks which allow the user to massage document data in ways that Elm can't, e.g. adding FieldValue.serverTimestamp() to a field.

Was this page helpful?
0 / 5 - 0 ratings