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

Consider comments when comparing nodes. #7403

Merged
merged 4 commits into from
Jun 15, 2020
Merged

Consider comments when comparing nodes. #7403

merged 4 commits into from
Jun 15, 2020

Conversation

tomalec
Copy link
Contributor

@tomalec tomalec commented Jun 8, 2020

Suggested merge commit message (convention)

Fix (engine): Editor no longer crashes when initialized on HTML with comment. Closes #5734.


Additional information

I was not sure about the location of the tests.

} );

// https://github.com/ckeditor/ckeditor5/issues/5734
it( 'should replace a comment with the added element', () => {
Copy link
Member

Choose a reason for hiding this comment

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

TBH I don't understand this description even though I read the test and I know what the issue is about 😛

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you have any alternative in mind?
Is "should remove the comment and add a child element" any better?

Copy link
Member

Choose a reason for hiding this comment

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

Nothing particular in my mind. The alternative sounds better, though.

@@ -930,6 +930,7 @@ function addInlineFiller( domDocument, domParentOrArray, offset ) {
function areSimilar( node1, node2 ) {
return isNode( node1 ) && isNode( node2 ) &&
!isText( node1 ) && !isText( node2 ) &&
node1.nodeType !== 8 && node2.nodeType !== 8 &&
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Also: DomCoverter already implements isComment(). I think it should be extracted to ckeditor5-utils/src/dom (like isNode(), isText() and many others), tested, and then used both in DomConverter and Renderer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we really need to add a dependency and bunch of tests for quite straightforward, native, and atomic comparison: node.nodeType !== Node.COMMENT_NODE? To me, it seems like overhead.

Copy link
Member

@oleq oleq Jun 9, 2020

Choose a reason for hiding this comment

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

I figured since there are 2 places that would benefit from the new thing, then why not? We have is*() helpers for most of the native DOM object types anyway. There are even tests for it already.

We could use Object.prototype.toString.apply( obj ) == '[object Comment]'; to make sure it is document-agnostic (like in isText() or isRange()).

Copy link
Member

@oleq oleq Jun 9, 2020

Choose a reason for hiding this comment

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

Or... to make it faster (I assume toString is sluggish), we could call isNode() first and then check the #nodeType.

Copy link
Member

Choose a reason for hiding this comment

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

...or not :D It looks like isNode() is buggy. A comment does not have a #defaultView, so isNode() will always return false even though Comment inherits from Node 

Copy link
Member

Choose a reason for hiding this comment

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

Maybe let's have a follow-up for this whole story then 😛

@oleq oleq self-assigned this Jun 9, 2020
@oleq oleq merged commit 377d142 into master Jun 15, 2020
@oleq oleq deleted the i/5734-balloon-comment branch June 15, 2020 08:11
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.

Balloon editor crashes on init when there is a comment in source html
2 participants