Automattic / Automattic/jetpack
Jetpack Comments: nested comments with async load of comments
- Dominant language
- PHP
- Stars
- 1.8k
- Forks
- 898
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 774
Description
#### Is your feature request related to a problem? Please describe.
When comments are loaded asynchronously in a template, the Jetpack Comments module won't work for nested comments.
Jetpack Comments is enqueuing the `watch_comment_parent()` function/script in `comment_form_before()` function using the `wp_footer` action hook. Loading the comments asynchronously, the `wp_footer` hook is already executed and no event listeners would be added. This is preventing the nested comments to work as the `comment_parent` hidden field won’t be updated.
#### Describe the solution you'd like
I would like the JS in the `watch_comment_parent()` function to be accessible outside of the closure with any kind of hook/API that we could trigger for this async use case
#### Describe alternatives you've considered
A workaround would be for the async comments to include this js snippet as well when the comments are loaded which is working but it sums up in mostly in copy-pasting the JS from `watch_comment_parent()` which is not elegant neither will be future proof if the Jetpack Comments feature evolves.
#### Additional context
n/a
Contributor guide
Research direction
Start by reading the Jetpack Comments implementation around watch_comment_parent(), comment_form_before(), and the wp_footer action. Trace how asynchronously loaded comments reach the comment form, then determine an accessible hook or API that can re-enable nested-comment behavior without copied JavaScript. Done means nested comments work after async loading and the existing behavior remains intact.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, php, wordpress
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100