WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.46k stars 4.18k forks source link

Post Author Block doesn't display when author has no posts #40431

Closed annezazu closed 2 years ago

annezazu commented 2 years ago

Description

If you add a Post Author block to the Author template and view the template for an author without any posts yet, the post author block doesn't display. This was found as part of the thirteenth call for testing for the FSE Outreach Program:

But if there are no posts for the author, the Author tag disappears (displays nothing) on the author archive page. However, the author name still shows in the page title (in the tab in Chrome browser). It seems odd to me that if there are no posts, the page title still knows the author name, but the Post Author block just does not display anything.

Step-by-step reproduction instructions

  1. Open Site Editor.
  2. Navigate to the Templates List.
  3. Click "Add" and add in an author template.
  4. Add a Post Author block at the top of the template.
  5. Add a Query Loop below it with the option of “Inherit query from template” selected.
  6. Publish the template.
  7. View an author with posts and see the author name.
  8. View an author without posts and notice that the author name does not display.

Screenshots, screen recording, code snippet

Here's a quick video of me demonstrating the problem: https://user-images.githubusercontent.com/26996883/163894155-98f43d27-0442-45b8-96a7-6fb305ca66b0.mov

Environment info

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

mauriac commented 2 years ago

TEST REPORT


After some debug it appears that the bug is due to the missing of postType and postId.

introduced here: #19894 (looks like an oversight)


ping @draganescu since he spearheaded this part of code and I am not sure what should be the best way to fix this. Should we disable the block when there's no postId?

I'm open to any suggestion, and then I can ship a patch.

draganescu commented 2 years ago

@mauriac the problem you reported seems different from the one in the issue. Changing the author outside of a post has no effect since there is no post to edit. I think that drop-down should not show if there is not post.

draganescu commented 2 years ago

Trying to see if it's trivial to bring over the feature the query block has to get post from query.

draganescu commented 2 years ago

So the problem here is that when there are no posts, the author block does not get any post id from the context. This is a quirk of how block context works on the server-side, for some reason if there are posts, the contextual post type and post id are set to the 1st one in the list of posts from the query block.

mauriac commented 2 years ago

@mauriac the problem you reported seems different from the one in the issue. Changing the author outside of a post has no effect since there is no post to edit. I think that drop-down should not show if there is not post.

I used to think that fix the postId missing will fix this issue, this is due to my first understand of the block purpose; but now I guess you are right. I'll create a new issue related to my problem and I'll probably ship a patch according to your comment ========> I think that drop-down should not show if there is not post.