Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comment form “Leave a Reply” heading misbehaves in Twenty Nineteen #2489

Closed
westonruter opened this issue Jun 2, 2019 · 3 comments · Fixed by #4388
Closed

Comment form “Leave a Reply” heading misbehaves in Twenty Nineteen #2489

westonruter opened this issue Jun 2, 2019 · 3 comments · Fixed by #4388
Assignees
Labels
Bug Something isn't working
Milestone

Comments

@westonruter
Copy link
Member

The #reply-title element is not getting the correctly populated in Twenty Nineteen. It is being output as:

<span [text]='commentform_post_2013.replyToName ? "Leave a Reply to " + commentform_post_2013.replyToName + "" : "Leave a Reply"'></span>

Notice the text content of the span is empty, but no value of [text] is empty.

In #development=1 mode, this is generating a warning:

Default value () does not match first result (Leave a Reply) for <SPAN [text]="commentform_post_2013.replyToName ? "Leave a Reply to " + commentform_post_2013.replyToName + "" : "Leave a Reply"">. We recommend writing expressions with matching default values, but this can be safely ignored if intentional.

It also exhibits a strange behavior when adding comment text to the form.

Upon entering text:

image

Then hit tab to go to the Submit button, and the “Leave a Reply” heading all of a sudden appears:

Screen Shot 2019-06-01 at 23 42 35

The problem here is that Twenty Nineteen renders its comment form via twentynineteen_comment_form() which does:

comment_form(
	array(
		'logged_in_as' => null,
		'title_reply'  => null,
	)
);

In particular, the title_reply here is supplied as null. This is causing problems in the \AMP_Theme_Support::filter_comment_form_defaults() method which is doing the following:

/**
* Filter comment form args to an element with [text] AMP binding wrap the title reply.
*
* @since 0.7
* @see comment_form()
*
* @param array $args Comment form args.
* @return array Filtered comment form args.
*/
public static function filter_comment_form_defaults( $args ) {
$state_id = self::get_comment_form_state_id( get_the_ID() );
$text_binding = sprintf(
'%s.replyToName ? %s : %s',
$state_id,
str_replace(
'%s',
sprintf( '" + %s.replyToName + "', $state_id ),
wp_json_encode( $args['title_reply_to'], JSON_UNESCAPED_UNICODE )
),
wp_json_encode( $args['title_reply'], JSON_UNESCAPED_UNICODE )
);
$args['title_reply_before'] .= sprintf(
'<span [text]="%s">',
esc_attr( $text_binding )
);
$args['cancel_reply_before'] = '</span>' . $args['cancel_reply_before'];
return $args;
}

The problem is that comment_form() applies filters on comment_form_defaults, not on the actual args passed to comment_form(). Therefore, we don't actually know what value for title_reply was passed.

This hasn't been a problem before Twenty Nineteen because themes normally are calling comment_form() without any args at all.

@westonruter westonruter added the Bug Something isn't working label Jun 2, 2019
@laurelfulford
Copy link

We're running into a similar issue in Newspack, where we have a simple plugin that lets you change the comment form text, including the "reply" header:

https://github.com/Automattic/newspack-rename-comments

The Newspack theme is also a fork of Twenty Nineteen and does have the duplicate header issue, but I'm working on removing some of that code, since it's not needed. We will still need to pass a unique title to comment_form(), though, which gets changed to "Leave a Reply" when you interact with the form or toggle the search.

For the short term, we can work around both by hiding and replacing that title, but if it's possible to have AMP use the title value passed to comment_form(), that would be awesome!

@westonruter
Copy link
Member Author

@laurelfulford I've opened a PR to prevent this from happening. Please test #4388.

@westonruter
Copy link
Member Author

I've also opened #4389 to redo the AMP implementation of WordPress comments so that we can achieve full feature parity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants