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

Clicking content that has a comment causes content data change (resulting with extra autosave) #9901

Closed
mlewand opened this issue Jun 17, 2021 · 6 comments · Fixed by #11341
Assignees
Labels
squad:collaboration Issue to be handled by the Collaboration team. support:2 An issue reported by a commercially licensed client. type:bug This issue reports a buggy (incorrect) behavior.

Comments

@mlewand
Copy link
Contributor

mlewand commented Jun 17, 2021

📝 Provide detailed reproduction steps (if any)

  1. Open sample with comments e.g. https://ckeditor.com/docs/ckeditor5/28.0.0/features/collaboration/comments/comments.html
  2. Execute follwoing code in JavaScript console: document.querySelectorAll( '.ck-editor__editable' )[ 0 ].ckeditorInstance.model.document.on( 'change:data', console.log )
  3. Make sure JavaScript console is visible.
  4. Place selection in content that has some comments.
  5. Move content again to a place where there is no comment applied.
  6. Repeat steps 4 and 5 twice.

✔️ Expected result

Moving the selection from comment to a regular place should not trigger change:data event.

❌ Actual result

It triggers change data event. In turn there can be autosave calls, undo snapshots created etc.

❓ Possible solution

Initial words from @scofalik 

Ah, okay, I get it. Comment is "data" marker and it is actually changed (or rather - refreshed) through writer.updateMarker( marker ); when the comment is clicked.

📃 Other details

  • Browser: Any
  • OS: Any

If you'd like to see this fixed sooner, add a 👍 reaction to this post.

@mlewand mlewand added type:bug This issue reports a buggy (incorrect) behavior. squad:collaboration Issue to be handled by the Collaboration team. labels Jun 17, 2021
@mlewand mlewand added this to the backlog milestone Jun 17, 2021
@mlewand mlewand added the support:2 An issue reported by a commercially licensed client. label Jun 17, 2021
@scofalik
Copy link
Contributor

scofalik commented Sep 29, 2021

  1. It is not trivial at the moment because comment marker does affect data. When we "refresh" it, it makes sense that change:data event is generated.
  2. However, marker range did not change and "marker is active" property itself does not affect data.
  3. Are there cases, where outside-of-model property could affect data?
  4. On the first thought, it may make sense but it will not work in RTC (because the property is synced only on one client).
  5. So, we should have a rule that outside-of-model properties can be used only in editing pipeline conversion.
  6. So, it looks like we can make this change in differ?
  7. If not, another idea was to introduce writer.refreshMarker( marker, refreshAffectsData ) and that would handle whether differ should consider this refresh as affecting data or not.
  8. We may want to introduce writer.refreshMarker( marker ) anyway, I don't like it that there's no specific method to refresh/reconvert a marker.

What needs to be done:

  1. Think again whether we can fix it straight in Differ#hasDataChanges(). How do we use markers? Think how our customers might use markers.
  2. If yes, fix in differ.
  3. If no, go with Writer#refreshMarker( marker, refreshAffectsData ).

Bonus: talk about this on architect guild.

@Mgsy
Copy link
Member

Mgsy commented Sep 30, 2021

Related: #5796.

@ma2ciek
Copy link
Contributor

ma2ciek commented Oct 4, 2021

Related: #10643.

@scofalik
Copy link
Contributor

scofalik commented Oct 7, 2021

After having an internal discussion, we come up with following conclusions:

  1. Conversion can be affected by external, non-model properties, like "active comment" in this example.
  2. However, since those properties are non-model and not synced with other clients, they should not be used in data pipeline (they should not affect document data). We are making this a rule.
  3. The only thing that can change about the marker and that is kept in model is the marker's range.
  4. "Refreshing" a marker without changing its range should not affect document data. In such case change:data event should not be send (change should be send instead).

We should fix this straight in Differ#hasDataChanges() - the method should check whether the changed marker actually changed its range.

So, the goal of this issue is to change Differ#hasDataChanges() so that the reported problem will be fixed.

Other than that, two followups.

  1. Should Marker#affectsData = true force Marker#managedUsingOperations = true? #10658
  2. New API for #refreshItem() and #refreshMarker() #10659

@Reinmar
Copy link
Member

Reinmar commented Oct 21, 2021

We should fix this straight in Differ#hasDataChanges() - the method should check whether the changed marker actually changed its range.

Will this be fixed in this ticket?

@scofalik
Copy link
Contributor

Yes, that's the goal of this ticket.

@scofalik scofalik removed this from the backlog milestone Nov 24, 2021
@Reinmar Reinmar added the status:planned Set automatically when an issue lands in the "Sprint backlog" column. We will be working on it soon. label Feb 11, 2022
@CKEditorBot CKEditorBot added status:in-progress Set automatically when an issue lands in the "In progress" column. We are working on it. and removed status:planned Set automatically when an issue lands in the "Sprint backlog" column. We will be working on it soon. labels Feb 25, 2022
scofalik added a commit that referenced this issue Feb 25, 2022
Fix (engine): Setting a marker to the same range it was will not trigger the `change:data` event. This will prevent unnecessary autosave callbacks. Closes #9901.
@CKEditorBot CKEditorBot added this to the iteration 51 milestone Feb 25, 2022
@CKEditorBot CKEditorBot removed the status:in-progress Set automatically when an issue lands in the "In progress" column. We are working on it. label Feb 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
squad:collaboration Issue to be handled by the Collaboration team. support:2 An issue reported by a commercially licensed client. type:bug This issue reports a buggy (incorrect) behavior.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants