Skip to content

Commit 60532ab

Browse files
committed
More defensive measures based on errors related to null comments.
Null comments don't just go away - it seems that the API can catch up.
1 parent 687eb38 commit 60532ab

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/Comment.jsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,18 @@ var Comment = React.createClass({
5252
return
5353
}
5454

55-
if (!prevState.comment.id) {
55+
// On !prevState.comment: a comment which was initially null - see
56+
// above - may eventually load when the API catches up.
57+
if (!prevState.comment || !prevState.comment.id) {
5658
// Register a newly-loaded comment with the thread store
5759
if (this.state.comment.id) {
58-
// If the commant was delayed, cancel any pending timeout
59-
if (prevState.comment.delayed) {
60+
// If the comment was delayed, cancel any pending timeout
61+
if (prevState.comment && prevState.comment.delayed) {
6062
this.clearDelayTimeout()
6163
}
6264
this.props.threadStore.commentAdded(this.state.comment)
6365
}
64-
if (!prevState.comment.delayed && this.state.comment.delayed) {
66+
if (prevState.comment && !prevState.comment.delayed && this.state.comment.delayed) {
6567
this.props.threadStore.commentDelayed(this.props.id)
6668
}
6769
}
@@ -94,16 +96,16 @@ var Comment = React.createClass({
9496

9597
/**
9698
* This is usually caused by a permissions error loading the comment due to
97-
* its author using the delay setting, which is measured in minutes - try
98-
* again in 30 seconds.
99+
* its author using the delay setting (note: this is conjecture), which is
100+
* measured in minutes - try again in 30 seconds.
99101
*/
100102
handleFirebaseRefCancelled(e) {
101103
if ("production" !== process.env.NODE_ENV) {
102104
console.error('Firebase ref for comment ' + this.props.id + ' was cancelled: ' + e.message)
103105
}
104106
this.unbind('comment')
105107
this.timeout = setTimeout(this.bindFirebaseRef, 30000)
106-
if (!this.state.comment.delayed) {
108+
if (this.state.comment && !this.state.comment.delayed) {
107109
this.state.comment.delayed = true
108110
this.forceUpdate()
109111
}

src/stores/CommentThreadStore.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ extend(CommentThreadStore.prototype, {
7474
* Register a comment's deletion from the thread.
7575
*/
7676
commentDeleted(comment) {
77+
// Comments which initially failed to load (null from Firebase API) can be
78+
// deleted by the time the API catches up.
79+
if (!comment) { return }
80+
7781
var siblings = this.children[comment.parent]
7882
siblings.splice(siblings.indexOf(comment.id), 1)
7983
},
@@ -84,4 +88,4 @@ extend(CommentThreadStore.prototype, {
8488
}
8589
})
8690

87-
module.exports = CommentThreadStore
91+
module.exports = CommentThreadStore

0 commit comments

Comments
 (0)