Closed TylerBarnes closed 6 months ago
The reproduction steps only work with a published page (if you've already deleted Sample Page).
Testing.
WordPress 5.7.2. Gutenberg plugin 10.6.2. Twenty Twenty One.
Went to a published page. With the name: "A post - Reuse" Changed the title to "A page - Reuse" -> previewed. I saw the new title. "A page - Reuse" Went back and changed the title back to "A post - Reuse" -> previewed. I saw the old title. "A page - Reuse"
It seems that every second change I can also see the change on the frontend.
Wordpress (gutenberg) will auto-save the editor state before previewing and then presumably the preview will always show the most recent save. It adds an autosave using the autosave rest API /wp/v2/posts/$postid/autosave
Following the repro steps @paaljoachim gives on trunk (d827fc5b9), the first preview generates an API request with a body of {"status":"publish","title":"A page - Reuse","content":"","excerpt":""}
and the second preview generates a completely identical API request i.e. it's sending the same title both times, despite being changed.
Using react dev tools, AutosaveMonitor isDirty prop is set to false if the content matches the saved version and true otherwise, I assume this is related.
When saving in saveEntityRecord
(core-data's actions.js) let data = { ...persistedRecord, ...autosavePost, ...record }
merges three records, persistedRecord will have the initially saved title, autosavePost will have the previously saved one, and record will have the latest title, unless it matches the initially saved title. This means the bug needs to be fixed earlier than saving, presumably as one of the events that fire while changing the title.
Paraphrasing @dsas:
This problem reproduces only when you set the Title back to the original saved one. In that case, autosave doesn't pick up the change possibly because there is no actual change to the title and therefore it sends along the last autosaved one.
Describe the bug When previewing with a new title, and then immediately after with the original title, the preview title doesn't update back to the original title. This bug isn't present when using the "Classic Editor" plugin.
To reproduce
Expected behavior Every time "Preview" is clicked, it should show the correctly revisioned title.
Desktop:
Additional context