TransWikia.com

Uncaught TypeError: Cannot read property 'firstChild' of null after upgrading to WordPress 5.5

WordPress Development Asked on January 1, 2021

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.

One Answer

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.

Answered by Rup on January 1, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP