diff --git a/editor/store/effects.js b/editor/store/effects.js index 75da4df7821d2..05586e58fa8d5 100644 --- a/editor/store/effects.js +++ b/editor/store/effects.js @@ -422,26 +422,29 @@ export default { } // Check the auto-save status - let autosaveAction; + let autosaveActions; if ( autosave ) { const noticeMessage = __( 'There is an autosave of this post that is more recent than the version below.' ); - autosaveAction = createWarningNotice( -

- { noticeMessage } - { ' ' } - { __( 'View the autosave' ) } -

, - { - id: AUTOSAVE_POST_NOTICE_ID, - spokenMessage: noticeMessage, - } - ); + autosaveActions = [ + createWarningNotice( +

+ { noticeMessage } + { ' ' } + { __( 'View the autosave' ) } +

, + { + id: AUTOSAVE_POST_NOTICE_ID, + spokenMessage: noticeMessage, + } + ), + resetAutosave( autosave ), + ]; } return [ setTemplateValidity( isValidTemplate ), setupEditorState( post, blocks, edits ), - ...( autosaveAction ? [ autosaveAction ] : [] ), + ...( autosaveActions ? autosaveActions : [] ), ]; }, SYNCHRONIZE_TEMPLATE( action, { getState } ) { diff --git a/editor/store/test/effects.js b/editor/store/test/effects.js index 8e135cb7c566b..f5614db5f5d13 100644 --- a/editor/store/test/effects.js +++ b/editor/store/test/effects.js @@ -35,6 +35,7 @@ import { convertBlockToShared, setTemplateValidity, editPost, + resetAutosave, } from '../actions'; import effects, { removeProvisionalBlock, @@ -558,6 +559,37 @@ describe( 'effects', () => { setupEditorState( post, [], { title: 'A History of Pork' } ), ] ); } ); + + it( 'it resets the autosave if the settings contains an autosave property', () => { + const post = { + id: 1, + title: { + raw: 'A History of Pork', + }, + content: { + raw: '', + }, + status: 'draft', + }; + const autosave = { + title: 'test title', + content: 'test content', + excerpt: 'test excerpt', + editLink: 'test edit link', + }; + const getState = () => ( { + settings: { + template: null, + templateLock: false, + }, + } ); + + const dispatch = jest.fn(); + + const result = handler( { post, autosave }, { getState, dispatch } ); + + expect( result ).toContainEqual( resetAutosave( autosave ) ); + } ); } ); describe( 'shared block effects', () => { diff --git a/lib/client-assets.php b/lib/client-assets.php index 106e426cca5f4..70fda94080e4c 100644 --- a/lib/client-assets.php +++ b/lib/client-assets.php @@ -1216,6 +1216,9 @@ function gutenberg_editor_scripts_and_styles( $hook ) { if ( $post_autosave ) { $editor_settings['autosave'] = array( 'editLink' => add_query_arg( 'gutenberg', true, get_edit_post_link( $post_autosave->ID ) ), + 'title' => $post_autosave->post_title, + 'content' => $post_autosave->post_content, + 'excerpt' => $post_autosave->post_excerpt, ); }