Silently failing to save template modifications (double slashes in URL)
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
- Go to Appearance → Editor → Templates
- Select a template (ex: 404)
- Modify the template
- Save the template
Screenshots, screen recording, code snippet
See the confirmation popup as the back returns a 301:

"Failing" request details:

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
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
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