Describe the bug
When trying to edit the template part name, the entire template section is removed. cc @epiqueras since this _might_ be resolved with your PR https://github.com/WordPress/gutenberg/pull/23661
To reproduce
Steps to reproduce the behavior:
Expected behavior
I expected the template part to be renamed.
Screenshots
Here's a video of me walking through this (44 seconds): https://cloudup.com/cc_RpdQWy8F
Editor version (please complete the following information):
Desktop (please complete the following information):
Does #23661 fix it?
Possibly related: #22639
Does #23661 fix it?
No. Interestingly, I can only reproduce this bug with the template parts created by the Full Site Editing Demo Templates experiment. If I create a new Template Part, I have no trouble renaming it, even after a save and refresh.
The issue also happens with Template Parts provided by a block-based theme, so I think the issue may have something to do with the difference between those and user-created Template Parts.
The issue also happens with Template Parts provided by a block-based theme
Interesting, I am able to reproduce as well without demo-templates. It seems that the renaming is problematic if we haven't saved a custom version of the template part.
Template part disappears when:
Does not have an issue when:
I guess once you edit and save the content of a template part originally provided by a theme, it stops being sourced from the theme since its been modified, so I guess that's why renaming works afterwards.
I guess once you edit and save the content of a template part originally provided by a theme, it stops being sourced from the theme since its been modified, so I guess that's why renaming works afterwards.
Right.. something along those lines.
So initially the theme references the template part by a name and has a template-part file with that name. When we change the name to something else, the file with that new name is not found and the template part disappears from the editor.
When we edit the template part first and 'save', the Template is also updated and saved to reference the new template part cpt with a given ID. So when that name is updated it still has the ID to display the template part.
Renaming it needs to save as well then.
Renaming it needs to save as well then.
Or maybe we shouldn't allow renaming if it's not saved? Or a more elegant way of handling this?
I feel like the forcing a save is going to be problematic? It would need to save the template part and template as soon as the user types into the name input. If there are already changes dirtied in the template or template part the forced save would either overwrite those changes to only save the new TP name / how the template references it, or will save all those other dirty changes without user confirmation? Either case seems problematic.
Perhaps what needs to happen is in the case that the Template Part is being referenced by slug
and has no id
, then when the input is changed it will need to continue to reference by that old slug
until we are able to save. The fact that it's looking for that new slug as soon as we edit the input is what is causing it to disappear.
Good points. That sounds like a sensible solution.
Perhaps a theme-supplied template part should be in read-only mode by default, with a button exposed to enable customizing it. Upon pressing this button, a user-created clone of the template part will be created and the block will be updated to reference the user one rather than the theme one. That makes the action a bit more explicit, which makes it clearer that you're no longer using the unmodified theme template part.
I would expect to be able to rename a template part without hitting save until I am ready. I expect the template part to remain in place with the new name.
It would need to save the template part and template as soon as the user types into the name input.
Should we just delay persistent changes to the title until clicking save? Doesn't it currently update the actual title in the DB just when typing in the field?
It would need to save the template part and template as soon as the user types into the name input.
Should we just delay persistent changes to the title until clicking save? Doesn't it currently update the actual title in the DB just when typing in the field?
If it _is_ currently updating the DB immediately upon typing, then that's inefficient, and it should definitely be changed to only happen upon save.
Should we just delay persistent changes to the title until clicking save? Doesn't it currently update the actual title in the DB just when typing in the field?
I think whats happening is when you type in to change the name, it uses setAttribute
on the block to change the slug
attribute (not necessarily save it). But since there is no ID at this stage, the slug is the only thing used to find the template part. The component tries to retrieve this after the block updates from setAttribute
, but a template part file corresponding to this new slug doesn't exist. So we need to NOT re-retrieve the entity when the slug changes (probably only when an Id is not present?)
Edit - I think #24500 has a good working fix now.
https://github.com/WordPress/gutenberg/pull/24500 fixes the issue with the template part disappearing, but it surfaces another issue in the next step of the process.
I am noticing once I go to 'save', the template part can be replaced with a different auto-draft template part of the same initial slug. It seems like its an issue with the template saving with undefined
as the value for the template part block's postId attribute.
It works as expected when:
It can replace with a different auto-drafted template part by the same slug when:
Reloading brings the proper template part back into place. 馃
Most helpful comment
Interesting, I am able to reproduce as well without demo-templates. It seems that the renaming is problematic if we haven't saved a custom version of the template part.
Template part disappears when:
Does not have an issue when: