2

I am getting the following error from comment-reply.min.js (which seems to be a WordPress file):

Uncaught TypeError: Cannot read property 'firstChild' of null
    at comment-reply.min.js?ver=026d5828124b6319675d89d24f212b97:2
    at Object.moveForm (comment-reply.min.js?ver=026d5828124b6319675d89d24f212b97:2)
    at HTMLAnchorElement.a (comment-reply.min.js?ver=026d5828124b6319675d89d24f212b97:2)

Is this a known issue after upgrading to WordPress 5.5 or should I start debugging it?

What would be the best way to address it?

We have not changed the comments template but only upgraded to the latest version of WordPress.

The relevant part of the template is:

<?php comment_id_fields($_GET["post_id"]); ?>
<?php do_action('comment_form', $_GET["post_id"]); ?>
            
<div class="fl-comment-form-cancel">
   <?php cancel_comment_reply_link(); ?>
</div>

After a quick check, it seems it is searching for an element with the id wp-temp-form-div, which does not exist.

And the issue seems to be here:

, r = E(h.commentReplyTitleId)
, o = void 0 !== r ? r.firstChild.textContent : "";

If commentReplyTitleId does not exist, r will be null, hence different than undefined, so it tries to get the firstChild.


A quick workaround I'm using:

(function () {
    var oldGet = document.getElementById.bind(document)
    document.getElementById = function (id) { return oldGet(id) || undefined; }
})();

But to me it seems like a bug in 5.5.

1
  • 1
    You probably want to be looking at the unminified version, but yes I agree that's wrong. I'd change it to ( null != replyElement ). Go ahead and raise a trac ticket?
    – Rup
    Aug 23, 2020 at 17:54

1 Answer 1

0

This was fixed in 5.5.1, commit 48877:

Correct the check for reply element existence in comment-reply.js.

document.getElementById() returns null if no matching element was found, so the previous comparison didn't work as expected.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.