Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autosave improvements #10218

Merged
merged 1 commit into from
Jul 27, 2021
Merged

Autosave improvements #10218

merged 1 commit into from
Jul 27, 2021

Conversation

scofalik
Copy link
Contributor

Suggested merge commit message (convention)

Fix (autosave): Autosave callback should not be called while the editor is initialized. Closes #10214.

Feature (autosave): Introduced `Autosave#save()`. Closes #10215.

Fix (autosave): Autosave callback should not be called while the editor is initialized.
// Change may not produce an operation, so the document's version
// can be the same after that change.
if (
version < this._lastDocumentVersion ||
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to me that this condition can never be met. At most version can be the same as _lastDocumentVersion but it can never be lower, as _lastDocumentVersion is set to it, and document version never goes down.

Copy link
Contributor Author

@scofalik scofalik Jul 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, as I thought it was at some point <= (which AFAIU also should simply be ==) and it was changed to < because of markers that affect data but does not bump version: 5577aa2#diff-f3cd7394728f0a6168a108ff56dc6ee631d0a71eb34f1a762264f9339de28311L161

But we don't need to check versions anyway -- _save() is called (debounced) only in change:date events, so we can be sure that there was actual change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW. TBH I don't know what was the use case but if a marker affects data it should also use operations 🤔 .

While use-operation, not-data may make sense, the other combination does not. If marker affects data it has to be send over to other clients.

Copy link
Contributor Author

@scofalik scofalik Jul 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, we need to check version lower, in the promise resolution:

if ( this.editor.model.document.version > this._lastDocumentVersion ) {

And there might be a problem there with the markers that don't bump version but:

  1. This change (removing if) is not related to the code below.
  2. As I explained, I am not sure what kind of marker affects data but does not use operations 🤔 . It may be a good idea to try and find that as a part of this PR review.

// can be the same after that change.
if (
version < this._lastDocumentVersion ||
this.editor.state === 'initializing'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong assumption. Data change might be triggered during editor initialization (when editor state is initializing) but _save() might be actually called later (with delay) when the editor state is already ready.

} )
.then( _editor => {
editor = _editor;

autosave = editor.plugins.get( Autosave );

const data = '<p>paragraph1</p><p>paragraph2</p>';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved data initialization where it should be. Didn't have any impact on tests.

@@ -25,14 +33,6 @@ ClassicEditor
destroyButton.addEventListener( 'click', () => editor.destroy() );

const autosave = editor.plugins.get( Autosave );
autosave.adapter = {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used config callback instead of adapter because there is no word about adapter anywhere in our docs or guides, it is just mentioned somewhere deeper in API docs. I believe this is forgotten/not recommended way to integrate autosave.

Funny, with this integration, the problem with calling autosave during initialization does not happen (because the adapter is added after the editor is initialized).

Copy link
Contributor

@psmyrek psmyrek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🎉

@psmyrek psmyrek merged commit 7be280f into master Jul 27, 2021
@psmyrek psmyrek deleted the ck/10214 branch July 27, 2021 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

API to immediately call autosave callback Autosave is triggered on data init
2 participants