Fix TypeError: null is not an object in initializeArticleReactions.js (#9297) [deploy]

* Fix TypeError: null is not an object in initializeArticleReactions.js

Should fix https://app.honeybadger.io/fault/67192/6f9b4fdf475e2229c968fa26d785b90f

* Return 0 rather than undefined if reactionEl doesn't exist
This commit is contained in:
Vaidehi Joshi 2020-07-14 08:12:07 -07:00 committed by GitHub
parent 3391593de1
commit 2fadc24d28
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -40,12 +40,12 @@ function hasUserReacted(reactionName) {
}
function getNumReactions(reactionName) {
var num = document.getElementById('reaction-number-' + reactionName)
.textContent;
if (num === '') {
const reactionEl = document.getElementById('reaction-number-' + reactionName);
if (!reactionEl || reactionEl.textContent === '') {
return 0;
}
return parseInt(num, 10);
return parseInt(reactionEl.textContent, 10);
}
function reactToArticle(articleId, reaction) {