Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Prevent rendering when one is in the change block. #1535

Merged
merged 9 commits into from
Sep 10, 2018
Merged

Prevent rendering when one is in the change block. #1535

merged 9 commits into from
Sep 10, 2018

Conversation

pjasiun
Copy link

@pjasiun pjasiun commented Sep 7, 2018

Suggested merge commit message (convention)

Internal: Prevent rendering when one is in the change block. Closes ckeditor/ckeditor5#4412.

@pjasiun pjasiun requested review from Reinmar and ma2ciek September 7, 2018 15:37
@coveralls
Copy link

coveralls commented Sep 7, 2018

Coverage Status

Coverage remained the same at 100.0% when pulling 08f0a29 on t/1528 into 5eb1fec on master.

Copy link
Contributor

@ma2ciek ma2ciek left a comment

Choose a reason for hiding this comment

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

Works well in Chrome, Safari and FF.

@@ -70,6 +70,19 @@ export default class EditingController {
const selection = doc.selection;
const markers = this.model.markers;

// Various plugins listen on model changes (on selection change, post fixers, etc.) and change the view as a
Copy link
Member

@Reinmar Reinmar Sep 10, 2018

Choose a reason for hiding this comment

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

When plugins listen on model changes (on selection change, post fixers, etc) and change the view as a result of model's change, they might trigger view rendering before the conversion is completed (e.g. before the selection is converted). We disable rendering for the length of the outermost model change() block to prevent that.

See https://github.com/ckeditor/ckeditor5-engine/issues/1528

@@ -487,6 +491,22 @@ export default class Model {
* @param {module:engine/model/writer~Writer} writer `Writer` instance that has been used in the change block.
*/

/**
* Fired when entering the first {@link module:engine/model/model~Model#enqueueChange} or
* {@link module:engine/model/model~Model#change} block of the pending changes.
Copy link
Member

Choose a reason for hiding this comment

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

That "pending changes" thing is misleading. It sounds like this is the Nth+ block. A one that was scheduled but needed to be postponed so it's "pending". Isn't it just the "outermost enqueueChange/change block"?


/**
* Fired when leaving the last {@link module:engine/model/model~Model#enqueueChange} or
* {@link module:engine/model/model~Model#change} block of the pending changes.
Copy link
Member

Choose a reason for hiding this comment

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

The same as above.

src/view/view.js Outdated
* @protected
* @member {Boolean} module:engine/view/view~View#_disabledRendering
*/
this._disabledRendering = false;
Copy link
Member

Choose a reason for hiding this comment

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

_renderingDisabled would be more grammatical. Plus, you have _renderingInProgress above already.

@@ -339,6 +339,112 @@ describe( 'EditingController', () => {
expect( getViewData( editing.view, { withoutSelection: true } ) )
.to.equal( '<p></p><p>f<span>oo</span></p><p>bar</p>' );
} );

describe( 'rendering preventing in the change block', () => {
Copy link
Member

Choose a reason for hiding this comment

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

preventing rendering in the change block

Copy link
Member

@Reinmar Reinmar Sep 10, 2018

Choose a reason for hiding this comment

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

or even:

preventing rendering while in the model.change() block

editing.view.on( 'render', renderSpy );
} );

it( 'should not call render in the change block', () => {
Copy link
Member

Choose a reason for hiding this comment

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

model.change()

expect( renderSpy.called ).to.be.true;
} );

it( 'should not call render in the change block even if view change was called', () => {
Copy link
Member

Choose a reason for hiding this comment

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

view.change()

@Reinmar
Copy link
Member

Reinmar commented Sep 10, 2018

Except for some wording and naming, this LGTM.

@Reinmar
Copy link
Member

Reinmar commented Sep 10, 2018

Tests look good so I'm merging it.

@Reinmar Reinmar merged commit 0097e58 into master Sep 10, 2018
@Reinmar Reinmar deleted the t/1528 branch September 10, 2018 11:46
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Nested contenteditables + comment markers make page jumps
4 participants