Fix comments no results placeholder not appearing#40234
Conversation
|
Size Change: +663 B (0%) Total Size: 1.23 MB
ℹ️ View Unchanged
|
|
I believe that the correct fix here is just this: diff --git a/packages/block-library/src/comment-template/hooks.js b/packages/block-library/src/comment-template/hooks.js
index ea2ead61331..eaeb28141a8 100644
--- a/packages/block-library/src/comment-template/hooks.js
+++ b/packages/block-library/src/comment-template/hooks.js
@@ -96,9 +96,10 @@ const useDefaultPageIndex = ( { defaultPage, postId, perPage, queryArgs } ) => {
method: 'HEAD',
parse: false,
} ).then( ( res ) => {
+ const pages = parseInt( res.headers.get( 'X-WP-TotalPages' ) );
setDefaultPages( {
...defaultPages,
- [ key ]: parseInt( res.headers.get( 'X-WP-TotalPages' ) ),
+ [ key ]: pages <= 1 ? 1 : pages, // If there are 0 pages, it means that there are no comments, but there is no 0th page.
} );
} );
}, [ defaultPage, postId, perPage, setDefaultPages ] );The problem is that when there are no comments on the site, the Then, in here: gutenberg/packages/block-library/src/comment-template/hooks.js Lines 51 to 58 in c6269c3 if |
Awesome catch! I spent almost a day and didn't figured out that one. Code updated with your approach! |
9f94520 to
96dcf0c
Compare
Oh, then then I don't feel so bad for spending a long time figuring out the fix 😄
Would be very nice to cover it with a test case. Will you add an e2e test in this PR or in another one? |
Now that 6.0 Beta has been released, I think we can address it on this PR. I will keep you updated! |
|
It’s too late for that because it isn’t a new critical bug that would block the plugin release. It will get included in 13.1 that ships in less two weeks. Is it something that should be included in WordPress 6.0? /cc @ndiego |
|
@gziolo, yes I think we should. Both the No Results and Comments blocks are included in 6.0 and this greatly improves the UI when there are no comments on a Post. I have added to the board and added the backport label. Happy to be overruled here, but I think it would a logical add. |
| if ( ! commentTree.length ) { | ||
| return <p { ...blockProps }> { __( 'No results found.' ) }</p>; | ||
| return ( | ||
| <p { ...blockProps } data-testid="noresults"> |
There was a problem hiding this comment.
What was the reason for polluting production code with a test-related attribute? Can it be done differently?
There was a problem hiding this comment.
We are doing triage for WordPress 6.0 Beta 2. @adamziel raised also a good point that in the Query Loop block, the same behavior is handled with a special Query No Results block:
https://github.com/WordPress/gutenberg/tree/trunk/packages/block-library/src/query-no-results
There was a problem hiding this comment.
As this component is rendered after fetching the comments through the API, I could not find another way to wait in Puppeteer for all XHR requests to be finished without adding a new library.
Right now I cannot find another way to fix it 😢 , but will be happy to remove this test until we find it before putting on 6.0
There was a problem hiding this comment.
Can you wait until p with a text is visible?
|
How does this relate to the |
* Fix comments no results placeholder not appearing * Revert changes and apply fix recommended * Add e2e test for no results * Comment cleaning
|
This was cherry-picked to |
What?
Display "No results" placeholder when there are no comments related to a post while you are in the post editor.
Why?
Right now, if you do not have any comments in the post, or any comments at all on the site, and you add a Comment Query Loop, you have an infinite loading spinner and a SQL error warning.
How?
Testing Instructions