Skip to content

Commit

Permalink
Fix unexpected autosave for published posts (#27942)
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad authored Jan 4, 2021
1 parent dc52d16 commit 6ab4d7a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
13 changes: 6 additions & 7 deletions packages/editor/src/components/autosave-monitor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { withSelect, withDispatch } from '@wordpress/data';
*
* There are two caveats:
* * If `props.isAutosaveable` happens to be false at a time of checking for changes, the check is retried every second.
* * The timer may be disabled by setting `props.disableIntervalChecks` to `false`. In that mode, any change will immediately trigger `props.autosave()`.
* * The timer may be disabled by setting `props.disableIntervalChecks` to `true`. In that mode, any change will immediately trigger `props.autosave()`.
*/
export class AutosaveMonitor extends Component {
constructor( props ) {
Expand All @@ -29,15 +29,14 @@ export class AutosaveMonitor extends Component {
}

componentDidUpdate( prevProps ) {
if (
this.props.disableIntervalChecks &&
this.props.editsReference !== prevProps.editsReference
) {
this.props.autosave();
if ( this.props.disableIntervalChecks ) {
if ( this.props.editsReference !== prevProps.editsReference ) {
this.props.autosave();
}
return;
}

if ( ! this.props.isDirty && prevProps.isDirty ) {
if ( ! this.props.isDirty ) {
this.needsAutosave = false;
return;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/editor/src/components/autosave-monitor/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe( 'AutosaveMonitor', () => {
AutosaveMonitor.prototype,
'setAutosaveTimer'
);
wrapper = shallow( <AutosaveMonitor />, {
wrapper = shallow( <AutosaveMonitor isDirty />, {
lifecycleExperimental: true,
} );
} );
Expand All @@ -36,7 +36,7 @@ describe( 'AutosaveMonitor', () => {
} );

describe( '#componentDidUpdate()', () => {
it( 'should set needsAutosave=true when editReference changes and other props stay the same (1)', () => {
it( 'should set needsAutosave=true when editReference changes', () => {
expect( wrapper.instance().needsAutosave ).toBe( false );
wrapper.setProps( {
editsReference: [],
Expand Down

0 comments on commit 6ab4d7a

Please sign in to comment.