[wp-trac] [WordPress Trac] #46588: comment-reply JavaScript not working with comments loaded via Ajax
WordPress Trac
noreply at wordpress.org
Mon Apr 15 20:53:50 UTC 2019
#46588: comment-reply JavaScript not working with comments loaded via Ajax
--------------------------+------------------------------
Reporter: dcooney | Owner: peterwilsoncc
Type: defect (bug) | Status: accepted
Priority: normal | Milestone: Awaiting Review
Component: Comments | Version: 5.1
Severity: normal | Resolution:
Keywords: | Focuses: javascript
--------------------------+------------------------------
Comment (by dcooney):
Hi @peterwilsoncc,
The issue appears for me on the front end. I have not tested in the admin.
Here is what I have determined to be the issue(s).
1.
`get_comment_reply_link` uses `add_query_arg` to get the URL for the
comment reply, by default `add_query_args` uses `$_SERVER['REQUEST_URI']`
as the base URL. The issue here is when using admin-ajax or the REST API
`$_SERVER['REQUEST_URI']` is the endpoint URL not the base URL of the
page.
You can pass in HTTP_REFERRER which fixes the error in the URL.
{{{
add_query_arg(
array(
'replytocom' => $comment->comment_ID,
'unapproved' => false,
'moderation-hash' => false,
), $_SERVER["HTTP_REFERER"]
)
}}}
[https://developer.wordpress.org/reference/functions/add_query_arg/]
2.
**"The comment-reply JavaScript uses a mutation observer for adding events
for AJAX added comments, are you experiencing the problem in all
browsers?"**
Yes, in all browser. The MutationObserver `observeChanges` method never
fires. It does trigger on page load, but even appending `<li>` elements in
plain JS (not via Ajax) after page load does not trigger the event.
Unfortunately, I don't how the MutationObserver is suppose to function so
do not have a fix for this.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/46588#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list