WordPress / gutenberg

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

The author list for PostAuthor should be loaded on demand #27103

Open johnbillion opened 3 years ago

johnbillion commented 3 years ago

Describe the bug

When loading the post editing screen, the <PostAuthor/> component triggers a REST API request (via getAuthors()) to fetch the authors to list to populate its filterable list. If the user isn't planning on changing the post author, this is an unnecessary REST API request and a waste of resources.

This request should be performed on-demand, for example when the field gains focus.

To reproduce

  1. Go to the post editing screen on a site with several users
  2. Observe that a request to wp-json/wp/v2/users is performed
  3. Don't change the post author
  4. Wonder why that request was needed

Editor version (please complete the following information):

Mamaduka commented 3 years ago

I recently refactored the <PostAuthor/> component, which reduced the number of REST API requests - #33695.

But it would be interesting to see the "on-demand" pattern for data fetching. It can be useful for other components too.