WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.51k stars 4.2k forks source link

Templates and Template part revision history shows wrong first revision #49164

Open draganescu opened 1 year ago

draganescu commented 1 year ago

Description

When editing for the 1st time a template or template part and saving, the result of the edit is saved in the database. That becomes the 1st version of the post saved. This is erroneous because compared to the original version saved on disk, the 1st version saved in the database contains edits. This leads to a poor UX like the one described in #48610 where users think their edits have not been saved as a revision.

The templates and template parts are not in the database and the 1st time they're edited they're basically added to the database, along with their edit. This shows up as two revisions, one with an empty post and one with the post having all the content (including the 1st edit).

Starting only with the 2nd edit, which will result in 3 available revisions, will we see actual diffs.

Step-by-step reproduction instructions

  1. Start a fresh WordPress install with Gutenberg 15.2 installed and
  2. Open the Site Editor and open a template or template part to
  3. Add a paragraph with text to the template and save the changes.

You can check for template revisions immediately, or after closing and re-opening the Site Editor. But none will.

  1. Edit the template again and make a different change, like adding an image, and saving the changes.

After this edit - revisions will start showing.

props @jordesign

Screenshots, screen recording, code snippet

https://user-images.githubusercontent.com/107534/225954617-eeefff85-3ff2-41c0-adc3-68c0f20de748.mp4

Environment info

No response

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

jordesign commented 1 year ago

Brilliant - thanks @draganescu

talldan commented 1 year ago

@draganescu What technical feedback do you need? It seems like the cause of the problem is explained in the description, so I'll remove the label.

I guess technically 'Clear customizations' is the same as resetting to the original revision.

Given revisions are a big part of phase 3, it may not be worth tackling this fully until then, there may be some quick wins though, like showing the 'clear customizations' button in that sidebar.

draganescu commented 1 year ago

The technical feedback should have been around the basic idea of using posts that are saved on disk and loading them in the DB after 1st edit. There are options to auto-create 1st revision automagically etc.

ramonjd commented 1 year ago

Quoting @talldan about a possible UX-based approach to mitigate any confusion until phase 3:

I think a quick fix could be something like:

  • template exists only as a file - no revisions
  • template exists as a post with a single edit - show the ‘clear customizations’ option, but maybe styled to look similar to revisions, it could open a dialog to say that the template will be reverted back to the theme version
  • template exists as a post with multiple edits - show the normal revision system
annezazu commented 9 months ago

I'd like to add this to the 6.5 board https://github.com/WordPress/gutenberg/issues/54503 but we seem close on time to get a fix in place for the release in a week. If anyone can take this on, let me know and let's get it added. Otherwise, leaving out for now.

mrfoxtalbot commented 5 months ago

This is still an issue, @annezazu. Whose sleeve can I tug to get it fixed? Thanks!

ramonjd commented 5 months ago

Whose sleeve can I tug to get it fixed? Thanks!

I won't get time for a while, but I double checked to reacquaint myself with the issue and I still think that @talldan's suggestion above is a valid approach.

It's confusing when the side-by-side revisions view doesn't display the correct, or any, previous revisions so rather than hide the link to revision.php Gutenberg displays a "Clear customizations" or something for the first revision. This would also reflect the practical reality that the first edit of a theme file is not, according to the database, a revision post type, but a first "user" version.

What do folks think?

annezazu commented 5 months ago

I would be curious to explore that approach and try it out! I think it could work.

mrfoxtalbot commented 5 months ago

That could work, thank you for taking a look, @ramonjd!

ramonjd commented 2 months ago

I'm still looking at options on this. Jotting down some notes from today:

richtabor commented 2 months ago

How big of an issue is this? Feels a bit obscure (thinking on priority).

ramonjd commented 2 months ago

How big of an issue is this? Feels a bit obscure (thinking on priority).

My personal read of its 'bigness' is mild to lukewarm. Even on issues like https://github.com/Automattic/wp-calypso/issues/74685

That revisions (2) only appear after having saved the template three times is pretty weird - it's a side-effect of the way Core handles changes to template files.

Maybe a small UI change could mitigate it, but I'd question the value of going any deeper right now.

What do other folks think?

talldan commented 1 month ago

Sharing a connected issue - https://github.com/WordPress/gutenberg/issues/52221.

I think the two are connected, as the incorrect revision history would make preserving/resetting the history not work correctly. 🤔