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

upcastAttributeToMarker converter overrides the conversion data object even when there is no conversion match #9779

Closed
ma2ciek opened this issue May 28, 2021 · 2 comments
Labels
package:engine resolution:expired This issue was closed due to lack of feedback. squad:collaboration Issue to be handled by the Collaboration team. status:stale type:bug This issue reports a buggy (incorrect) behavior.

Comments

@ma2ciek
Copy link
Contributor

ma2ciek commented May 28, 2021

This leads to a situation when adding a converter with the editor.conversion.dataToMarker upcast helper changes can change the conversion for some elements even if they do not match the view specified by the converter.

This behavior crashes the editor when the Table and either Track Changes or Comments are added to the editor (there're some additional prerequisites to reproduce the error though).

We should rethink if overriding the data properties for the whole element conversion in the  

data = Object.assign( data, conversionApi.convertChildren( data.viewItem, data.modelCursor ) );
is necessary. Currently adding any marker converter may change any element's upcast conversion - what's worse - it can be a race condition depending on the order of plugins in the editor.

As a temporary solution, we can check if any element can be consumed and return early for conversion calls for non-matching view elements - before the

// This converter wants to add a model element, marking a marker, before/after an element (or maybe even group of elements).
// To do that, we can use `data.modelRange` which is set on an element (or a group of elements) that has been upcasted.
// But, if the processed view element has not been upcasted yet (it does not have been converted), we need to
// fire conversion for its children first, then we will have `data.modelRange` available.
if ( !data.modelRange ) {
data = Object.assign( data, conversionApi.convertChildren( data.viewItem, data.modelCursor ) );
}
if ( conversionApi.consumable.consume( data.viewItem, { attributes: attrName + '-end-after' } ) ) {
addMarkerElements( data.modelRange.end, data.viewItem.getAttribute( attrName + '-end-after' ).split( ',' ) );
}
if ( conversionApi.consumable.consume( data.viewItem, { attributes: attrName + '-start-after' } ) ) {
addMarkerElements( data.modelRange.end, data.viewItem.getAttribute( attrName + '-start-after' ).split( ',' ) );
}
if ( conversionApi.consumable.consume( data.viewItem, { attributes: attrName + '-end-before' } ) ) {
addMarkerElements( data.modelRange.start, data.viewItem.getAttribute( attrName + '-end-before' ).split( ',' ) );
}
if ( conversionApi.consumable.consume( data.viewItem, { attributes: attrName + '-start-before' } ) ) {
addMarkerElements( data.modelRange.start, data.viewItem.getAttribute( attrName + '-start-before' ).split( ',' ) );
}
lines.

@ma2ciek ma2ciek added type:bug This issue reports a buggy (incorrect) behavior. package:engine squad:collaboration Issue to be handled by the Collaboration team. labels May 28, 2021
@ma2ciek ma2ciek self-assigned this May 28, 2021
scofalik added a commit that referenced this issue Jun 1, 2021
Fix (engine): Added checks for the upcast attribute-to-marker converter to prevent converter from doing anything if there are no changes to consume for given view element. Part of the #9779.
pomek added a commit that referenced this issue Jun 1, 2021
@CKEditorBot
Copy link
Collaborator

There has been no activity on this issue for the past year. We've marked it as stale and will close it in 30 days. We understand it may be relevant, so if you're interested in the solution, leave a comment or reaction under this issue.

@CKEditorBot
Copy link
Collaborator

We've closed your issue due to inactivity over the last year. We understand that the issue may still be relevant. If so, feel free to open a new one (and link this issue to it).

@CKEditorBot CKEditorBot added the resolution:expired This issue was closed due to lack of feedback. label Oct 30, 2023
@CKEditorBot CKEditorBot closed this as not planned Won't fix, can't repro, duplicate, stale Oct 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package:engine resolution:expired This issue was closed due to lack of feedback. squad:collaboration Issue to be handled by the Collaboration team. status:stale type:bug This issue reports a buggy (incorrect) behavior.
Projects
None yet
Development

No branches or pull requests

2 participants