gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

Silently failing to save template modifications (double slashes in URL)

Open OnitiFR opened this issue 4 years ago • 2 comments

Description

When saving a template (FSE), the POST request sent to the backend contains too many slashes (ex: https://foobar/wp-json/wp/v2/templates/twentytwentytwo//404?_locale=user).

Some webservers / reverse proxies will "rewrite" this request with a 301 response, and api-fetch will then request again with the "fixed" URL, but with GET method. As the result is 200, Gutenberg will display a "site updated" confirmation to the user, but the template is not modified. This is a bit misleading to the user 😄

Step-by-step reproduction instructions

  1. Go to Appearance → Editor → Templates
  2. Select a template (ex: 404)
  3. Modify the template
  4. Save the template

Screenshots, screen recording, code snippet

See the confirmation popup as the back returns a 301: image

"Failing" request details: image

Environment info

  • Wordpress 5.9.3, stock, fresh install

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

OnitiFR avatar May 10 '22 15:05 OnitiFR

Thanks for the report. This issue is still reproducible.

Request URL examples:

  • http://localhost:8888/wp-json/wp/v2/templates/twentytwentyfive//404?_locale=user
  • http://localhost:8888/wp-json/wp/v2/template-parts/twentytwentyfive//sidebar?_locale=user

t-hamano avatar Jun 03 '25 10:06 t-hamano

It turns out that the double slash separating the theme name from the slug is intentional:

https://github.com/WordPress/gutenberg/blob/2cfdf9234abea96a3161bfc25efba4a343ddd526/packages/block-library/src/template-part/edit/utils/create-template-part-id.js#L9

This double slash was first implemented in #27910 (Source).

I'm not sure if we can simply replace the double slashes with single slashes or if that will cause any problems.

cc @youknowriad @TimothyBJacobs

t-hamano avatar Jun 03 '25 10:06 t-hamano