Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

WooCommerce templates: two 404 requests when loading the templates list #5327

Closed
Aljullu opened this issue Dec 7, 2021 · 3 comments · Fixed by #5375 or #5519
Closed

WooCommerce templates: two 404 requests when loading the templates list #5327

Aljullu opened this issue Dec 7, 2021 · 3 comments · Fixed by #5375 or #5519
Assignees
Labels
focus: FSE Work related to prepare WooCommerce for FSE. type: bug The issue/PR concerns a confirmed bug.

Comments

@Aljullu
Copy link
Contributor

Aljullu commented Dec 7, 2021

WP makes two 404 requests when loading the Templates list (in Appearance > Editor > Templates). Those requests are:

  • /wp-json/wp/v2/themes/woocommerce
  • /wp-json/wp/v2/plugins/WooCommerce

While nothing seems to break because of that, we should try to avoid making unnecessary requests.

To reproduce

Steps to reproduce the behavior:

  1. Go to Appearance > Editor > Templates with your browser devtools Network tab open.
  2. Notice there were two 404 requests:

imatge

Expected behavior

We should investigate why those requests return 404 and avoid them.

@Aljullu Aljullu added type: bug The issue/PR concerns a confirmed bug. focus: FSE Work related to prepare WooCommerce for FSE. labels Dec 7, 2021
@gigitux gigitux self-assigned this Dec 10, 2021
@gigitux
Copy link
Contributor

gigitux commented Dec 10, 2021

After some investigation, I will summarize what I discovered.

The request /wp-json/wp/v2/plugins/WooCommerce is done when the user lands on Template section, instead the request /wp-json/wp/v2/themes/woocommerce is done when the user lands on Template Parts section.

The first request is done by this component on GB. Since the request fails, the code uses the slug parameter like the fallback. The slug value is the template theme name. In our code we set the template theme name here.

More or less the same thing happens for the second request. The request is done by this component. Since the request fails, the code uses the slug parameter like the fallback. The slug value is the template theme name. In this case we set the template theme name here.

In conclusion, if we want to avoid this error, we should create a REST endpoint, so GB can fetch the request correctly.

What do you think? @Aljullu

@Aljullu
Copy link
Contributor Author

Aljullu commented Dec 13, 2021

Thanks for investigating this @gigitux and for posting links to the code, that was very useful. Hope you don't mind that I continued your research. It turns out the REST endpoint already exists, it's provided by WordPress core. However it must be called in the form /wp-json/wp/v2/plugins/woocommerce/woocommerce. I found it out debugging the code from here:

https://github.com/WordPress/wordpress-develop/blob/trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.php

I created a fix for this in #5375. Hope you don't mind that I picked it up, but after the investigation, it made sense to directly create the PR. 🙏

@gigitux
Copy link
Contributor

gigitux commented Dec 17, 2021

I'm reopening this issue because this bug will be reintroduced with #5412

First, we should be sure that woocommerce/woocommerce is the right endpoint.

When we are sure of this, we should check if the best option is change the theme value in our codebase (more info #5399 #5409)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
focus: FSE Work related to prepare WooCommerce for FSE. type: bug The issue/PR concerns a confirmed bug.
Projects
None yet
3 participants