Skip to content

Commit

Permalink
Only set timestampsInSnapshots when explicitly requested via prop
Browse files Browse the repository at this point in the history
As of firebase@5.8.x timestampsInSnapshots is true implicitly
green-arrow#39

Furthermore: calling settings() multiple times is not supported.
If your app interacts with Firestore prior to using <FirestoreProvider>,
FirestoreProvider's settings() call will get you into trouble:

Uncaught FirebaseError: Firestore has already been started
and its settings can no longer be changed. You can only call settings()
before calling any other methods on a Firestore object
  • Loading branch information
tomsun committed Mar 4, 2019
1 parent 9b00fdf commit ec64eb7
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/FirestoreProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ export default class FirestoreProvider extends Component {
static propTypes = {
firebase: PropTypes.object.isRequired,
children: PropTypes.node.isRequired,
useTimestampsInSnapshots: PropTypes.bool.isRequired,
useTimestampsInSnapshots: PropTypes.bool,
};

static defaultProps = {
useTimestampsInSnapshots: false,
};
static defaultProps = {};

static childContextTypes = {
firestoreDatabase: PropTypes.object.isRequired,
Expand All @@ -22,9 +20,11 @@ export default class FirestoreProvider extends Component {
super(props);

const { firebase, useTimestampsInSnapshots } = props;
const settings = { timestampsInSnapshots: useTimestampsInSnapshots };
const firestore = firebase.firestore();
firestore.settings(settings);
if (typeof useTimestampsInSnapshots !== 'undefined') {
const settings = { timestampsInSnapshots: useTimestampsInSnapshots };
firestore.settings(settings);
}

this.state = {
firestoreDatabase: firestore,
Expand Down

0 comments on commit ec64eb7

Please sign in to comment.