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

The domConverter should not modify DOM structure #4371

Closed
f1ames opened this issue Jun 29, 2018 · 8 comments
Closed

The domConverter should not modify DOM structure #4371

f1ames opened this issue Jun 29, 2018 · 8 comments
Labels
package:engine resolution:expired This issue was closed due to lack of feedback. status:stale type:improvement This issue reports a possible enhancement of an existing feature.

Comments

@f1ames
Copy link
Contributor

f1ames commented Jun 29, 2018

Extracted from https://github.com/ckeditor/ckeditor5-engine/issues/1451#issuecomment-401356437:

When converting elements from view to DOM, the element itself is fetched from the mappings. If it doesn't exists there the new element is created. The same happens to its children if withChildren: true option is present. New elements are created or existing ones are used. If the parent is newly created element and children exists in the DOM, DOM children are attached to a new parent. Since new parent is detached from the DOM, moved children also becomes detached.

and also mentioned earlier in https://github.com/ckeditor/ckeditor5-engine/issues/1125#issuecomment-332790058:

There are two bugs connected with this and related tickets. Both are caused by the fact that DomConverter sometimes returns references (when elements are already bound) and sometimes create new elements. It's also confusing for the programmer, because it is hard to say what you can do with the results got from DomConverter. For example, you should not append returned elements to other elements - if those were already in DOM/View tree, you mess up the current structure. Another problem is that this indirectly mixes responsibilities of Renderer and DomConverter. If we go with the original idea to refresh nodes in viewToDom then why we need a Renderer in the first place -- the refreshed changes will be already applied in DOM.

The main issue here is that even though only renderer should be responsible for updating DOM structure (apart from external actions ofc), in some cases domConverter also modifies it before rendering which looks like rather unpleasant side effect, may be confusing and hard to debug and mixes responsibilities of renderer and domConverter. It may lead to some hard to understand cases too - #4370.

As we have introduced some renderer improvements, especially deep changes rendering (#1417), maybe such mechanism is not needed anymore and domConverter could always create new DOM elements. The renderer itself will detect and prevent rerendering of similar elements.
Or maybe there are other ideas how we can improve this situation? cc @Reinmar @pjasiun @scofalik

@pjasiun
Copy link

pjasiun commented Jun 29, 2018

DomConverter is part of the logic shared between renderer and data processors. It means that the code which is common for both data and editing pipelines need to go to the dom converter. Data pipeline does not use the renderer, uses only DomConverter directly. The logic which is limited to editing pipeline can be kept in the renderer (but does not need to, if you feel that this code fit better DomConverter it is fine to put it there).

This is why DomConverter need to be able to create DOM tree based on the view tree. However, we may split viewToDom into two methods: getDomForView and createDomFromView. This is an old issue that it is not clear if viewToDom should or should not create something.

@f1ames
Copy link
Contributor Author

f1ames commented Jun 29, 2018

This is why DomConverter need to be able to create DOM tree based on the view tree. However, we may split viewToDom into two methods: getDomForView and createDomFromView. This is an old issue that it is not clear if viewToDom should or should not create something.

Creating DOM tree itself is not a problem here and it could stay in a DomConverter. The problem is that in some cases when the DOM tree is created, already existing DOM elements are used and detached from the DOM (attached to newly created DOM parent). Is it important for other data processor that structure created by DomConverter contains DOM elements which already exists in the DOM or it could be just newly created elements?

@pjasiun
Copy link

pjasiun commented Jun 29, 2018

All what data processors do is to create new DOM from view. Data processors do not reuse any nodes:

https://github.com/ckeditor/ckeditor5-engine/blob/66bf132bbb915515c18318cb7e2869670bb7b90a/src/dataprocessor/htmldataprocessor.js#L61

@Reinmar
Copy link
Member

Reinmar commented Jun 29, 2018

The problem is that in some cases when the DOM tree is created, already existing DOM elements are used and detached from the DOM (attached to newly created DOM parent).

Completely agree. DomConverter gets way too far in this. Its name and method names say that it's about "conversion", while it does a lot more. So, either we should split responsibilities here or think about better naming.

@pjasiun
Copy link

pjasiun commented Jul 2, 2018

To make it clear I also agree that DomConverter is messy. There is no need to keep it that complicated, methods should be clear and should not do renderer work. However, there should be a method to create DOM structure based on the view structure (and vice versa) for data processors usages.

@f1ames
Copy link
Contributor Author

f1ames commented Jul 2, 2018

DomConverter gets way too far in this. Its name and method names say that it's about "conversion", while it does a lot more. So, either we should split responsibilities here or think about better naming.

Agree 👍 Renaming could be easier, but probably splitting some methods will be needed to.

However, there should be a method to create DOM structure based on the view structure (and vice versa) for data processors usages.

Yes, I agree that it should stay inside DomConverter. The main reason this issue was created is that during view to DOM conversion, in some cases, existing DOM is modified and some its elements detached (withChildren: true flag):

https://github.com/ckeditor/ckeditor5-engine/blob/66bf132bbb915515c18318cb7e2869670bb7b90a/src/view/domconverter.js#L229-L233

This is described in more details in https://github.com/ckeditor/ckeditor5-engine/issues/1451#issuecomment-401356437.

@mlewand mlewand transferred this issue from ckeditor/ckeditor5-engine Oct 9, 2019
@mlewand mlewand added this to the backlog milestone Oct 9, 2019
@mlewand mlewand added module:view type:improvement This issue reports a possible enhancement of an existing feature. package:engine labels Oct 9, 2019
@pomek pomek removed this from the backlog milestone Feb 21, 2022
@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 Nov 4, 2023
@CKEditorBot CKEditorBot closed this as not planned Won't fix, can't repro, duplicate, stale Nov 4, 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. status:stale type:improvement This issue reports a possible enhancement of an existing feature.
Projects
None yet
Development

No branches or pull requests

6 participants