WordPress.org

Make WordPress Core

Opened 4 weeks ago

Closed 4 weeks ago

#48543 closed defect (bug) (fixed)

Uncaught TypeError in comment-reply.js when 'id_form' is not 'commentform'

Reported by: raamdev Owned by: SergeyBiryukov
Milestone: 5.3 Priority: normal
Severity: normal Version: 5.3
Component: Comments Keywords: has-patch commit dev-reviewed
Focuses: javascript Cc:
PR Number:

Description

When comment_form() is passed and id_form argument other than the default of commentform, clicking the Reply link on a comment produces the following error in the JavaScript console:

Uncaught TypeError: Cannot read property 'addEventListener' of null

This results in the page refreshing and defaulting to the non-JS behavior, breaking the intended functionality of moving the comment reply form underneath the comment being replied to.

It looks like this bug was introduced in r45790, where it's assumed that commentFormElement contains a non-null reference to the comment form ID (config.commentFormId), which is set to an ID of commentform. If the ID is anything other than commentform, the Uncaught TypeError is produced.

To reproduce the bug in trunk, you can modify comment_form() in twentynineteen/inc/template-tags.php to specify a custom comment form element id attribute (anything other than the default of commentform produces the bug):

<?php
comment_form(
                array(
                        'logged_in_as' => null,
                        'title_reply'  => null,
                        'id_form' => 'commentform-' . get_the_ID()
                )
        );

Attachments (1)

48543.diff (518 bytes) - added by raamdev 4 weeks ago.
Checks if commentFormElement is non-null before using it

Download all attachments as: .zip

Change History (8)

@raamdev
4 weeks ago

Checks if commentFormElement is non-null before using it

#1 @raamdev
4 weeks ago

  • Keywords has-patch added; needs-patch removed

#2 @SergeyBiryukov
4 weeks ago

  • Milestone changed from Awaiting Review to 5.3

Thanks for the ticket and the patch! Moving to 5.3, as this appears to be a regression.

#3 @SergeyBiryukov
4 weeks ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 46700:

Comments: Check if comment form element exists before adding a key handler to detect the cmd/ctrl-enter key press.

Follow-up to [45790].

Props raamdev.
Fixes #48543. See #41545.

#4 @SergeyBiryukov
4 weeks ago

  • Keywords commit dev-feedback added
  • Resolution fixed deleted
  • Status changed from closed to reopened

Reopening for a second committer's review before merging to the 5.3 branch.

This ticket was mentioned in Slack in #core-committers by sergey. View the logs.


4 weeks ago

#6 @whyisjake
4 weeks ago

  • Keywords dev-reviewed added; dev-feedback removed

#7 @whyisjake
4 weeks ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 46706:

Comments: Check if comment form element exists before adding a key handler to detect the cmd/ctrl-enter key press.

Brings [46700] to the 5.3 branch.

Follow-up to [45790].
Props raamdev.
Fixes #48543. See #41545.

Note: See TracTickets for help on using tickets.