admin管理员组

文章数量:1122833

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(hmentReplyTitleId)
, 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.

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.

Share Improve this question edited Aug 25, 2020 at 9:48 Ionică Bizău asked Aug 23, 2020 at 17:26 Ionică BizăuIonică Bizău 3213 gold badges4 silver badges20 bronze badges 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 Commented Aug 23, 2020 at 17:54
Add a comment  | 

1 Answer 1

Reset to default 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.

本文标签: phpUncaught TypeError Cannot read property 39firstChild39 of null after upgrading to WordPress 55