gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

Site Editor: templates available in sidebar is limited to 10 in total

Open Sandstromer opened this issue 5 years ago • 9 comments

Description

With a theme that includes more than 10 templates, some of the templates are not available in the Site Editor left sidebar.

It seems to be that the templates are being sorted alphabetically, and all templates after the 10th item are dropped from the sidebar.

An example would be a theme that has the following 12 templates: 404 author index page page-blog page-contact page-home page-no-header page-no-footer page search single

In this scenario the 'search' and 'single' templates are dropped from the available templates in the sidebar, making them unavailable for editing.

It seems to be limited to a total of 10 templates.

With multiple "page" templates they are grouped in a "Page Templates" sub-panel, but still the last 2 do not appear after the "Page Templates" sub heading.

The sidebar was very recently reverted as a temporary solution in https://github.com/WordPress/gutenberg/pull/36516

Step-by-step reproduction instructions

Take any theme e.g. empty theme and copy/rename the page (or single) template multiple times until you have more than 10 templates in total. Load the Site Editor. Notice any templates that are ordered alphabetically after the 10th item are missing from the available templates.

Screenshots, screen recording, code snippet

No response

Environment info

WP 5.82 Gutenberg 11.9.1

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

Sandstromer avatar Nov 17 '21 11:11 Sandstromer

Looks like in core-data/index,js the getQueryParts(query) function has the perPage attribute set at 10.

Don't know if increasing this number is something that can done, or we just have to live with some templates not being available for editing.

Sandstromer avatar Nov 17 '21 12:11 Sandstromer

Hopefully someone with more knowledge can answer whether increasing this would negatively affect performance elsewhere.

Sandstromer avatar Nov 17 '21 12:11 Sandstromer

Apologies for the labeling chaos :D I didn't think I'd have time to test after initially being unable to replicate and then did have time.

I can replicate this and, further, the search functionality shows no results:

https://user-images.githubusercontent.com/26996883/142351246-c1b88b5f-7c1e-4e4f-8574-c84caa6ee651.mov

annezazu avatar Nov 18 '21 04:11 annezazu

@Copons do you have any insight here since you've done lots of work here? :)

annezazu avatar Nov 18 '21 04:11 annezazu

Removing from 5.9 project since this approach is being worked on for 5.9 and it will resolve this issue by providing a different experience to view all templates: https://github.com/WordPress/gutenberg/pull/36379 Still feels wise to address going forward in the navigation component if the full blown component returns in the future.

annezazu avatar Nov 18 '21 04:11 annezazu

@annezazu As @Sandstromer said, it's a matter of per_page when fetching the templates for the sidebar. We originally used per_page: -1, which requests all the templates (expensive, but back then we deemed it reasonable with the assumption that folks might not have hundreds of templates).

That parameter got removed in https://github.com/WordPress/gutenberg/pull/36044/files#r738414102 because, as it turned out:

per_page is not supported in the wp_template and wp_template_part post types.

I'm not exactly sure why it's not supported though. 🤔

Copons avatar Nov 18 '21 10:11 Copons

The problem here is that core data limits received items to ten when the per_page argument isn't provided. It is okay for most of the endpoints since they return ten items by default as well. But can cause unexpected behavior likes this for others.

You can find more details in this issue - https://github.com/WordPress/gutenberg/issues/15413#issuecomment-743800831.

I think the easiest way to resolve this is to bring back perPage: -1 for template selectors, but in the long term, we should fix #15413.

@youknowriad what do you think?

Mamaduka avatar Nov 18 '21 14:11 Mamaduka

@Mamaduka I agree, I forgot this when I removed the per_page argument from the query, that said when restoring it we should ensure that the right endpoints are preloaded (we might have to update the query string of some preloaded urls)

youknowriad avatar Nov 19 '21 10:11 youknowriad

we should ensure that the right endpoints are preloaded (we might have to update the query string of some preloaded urls)

Sounds good. I will start working on PR.

Mamaduka avatar Nov 19 '21 10:11 Mamaduka