-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Using is( elementName ) considered harmful #7608
Comments
My few loose notes on this, for now I don't have strong opinion on where to head with this: What about model's API? We also have The other thing to consider is - why I'd test the change with logging to the console in this part of API - I worry for a performance hit. |
I was wondering if we could make different breaking change (possibly with smaller impact). Currently in source files we have:
Also we use
So maybe it would be more consistent, less breaking and still providing clean API if we replace |
Unfortunately, I've got second doubts about The problem is with We can't say for sure that no one uses What's more. There are more cases. So, I'm again thinking about I know that your concern was that typing
gives me 150 results in |
As discussed F2F we came to a solution that would use existing namespacing that we use already (i.e., But since the above would resolve the issue with
Maybe we should also change |
tlldr: To rephrase Kuba's comment, the notation would look like this: |
But also |
Trying to put this into some more readable form. Case 1
Currently in code we use
Currently ProposalWe could change implementation of ProsBy providing expected type (either by prefix or using 2 arguments) we avoid conflicts with ConsIt's breaking change but we don't see any better generic solution. This is RFC so maybe anyone could see come cons? Case 2At first it was prepared as changing ProsCode consistency with Schema, Differ, Conversion, model parser and serializer ConsSolves only case of Since this is considered "not enough" and SVG problem would be solved by case 1 then this change might be not needed. OTOH this would give more consistency in code. The question is if you see any cons for this change if we would push both cases at once. Both cases require breaking change so it would be better to push it once than in multiple iterations. |
@niegowski & @Reinmar I still find the RFC messy, so I'd try to summarize it in ADRish form (I've used a compilation from example templates). I've also compiled the solution and it sill might need some improvements (you're welcome to update below ADR) Checking model/view element type and nameContextThe model/view nodes check for type and name: text.is( 'text' );
text.is( 'model:text' );
element.is( 'tableCell' );
element.is( 'element', 'tableCell' );
element.is( 'model:element', 'tableCell' ); cause troubles if some view element has name that happens to be one of our element type ( Decision drivers
Considered options1. Special notation of text nodes in check ❌Keep is check as now but change text nodes check: text.is( '$text' ) for text nodes and keep current consistent form (already ditched as other elements types would also cause troubles). 2. A three part string for
|
After compiling the above ADR, my thoughts on this:
|
Thank you, @jodator for writing it this way. I'm ok with option 2, but I completely agree with you about its cons. Therefore, I also find 3, so the initial idea, a better option. |
@jodator I like this ADR approach. I think this should become a standard in our project. 3 sounds good (lesser evil) to me. |
@Reinmar & @niegowski I've found one place confusing a bit in the current/PR code. It is about checking for However, it looks like the check was later on brought back (ckeditor/ckeditor5-engine#1368) - probably due to So the current implementation (not the original one) https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/element.js#L118-L127: will check:
Now, I'd like to have a confirmation that ps.: This topic |
Other (engine): Changed arguments of `Element#is()`, `Text#is()`, `TextProxy#is()`, `AttributeElement#is()`, `ContainerElement#is()`, `EditableElement#is()`, `EmptyElement#is()`, `UIElement#is()` methods and all it's usages. Closes #7608. Internal: Usages of `is()` methods updated to the latest API change. MAJOR BREAKING CHANGE (engine): Changed expected argument for model's [`Text#is()`](https://ckeditor.com/docs/ckeditor5/latest/api/module_engine_model_text-Text.html#function-is) and [`TextProxy#is()`](https://ckeditor.com/docs/ckeditor5/latest/api/module_engine_model_textproxy-TextProxy.html#function-is) methods (`'text'` replaced with `'$text'` and `'textProxy'` replaced with `'$textProxy'`). MAJOR BREAKING CHANGE (engine): Changed expected argument for views's [`Text#is()`](https://ckeditor.com/docs/ckeditor5/latest/api/module_engine_view_text-Text.html#function-is) and [`TextProxy#is()`](https://ckeditor.com/docs/ckeditor5/latest/api/module_engine_view_textproxy-TextProxy.html#function-is) methods (`'text'` replaced with `'$text'` and `'textProxy'` replaced with `'$textProxy'`). MAJOR BREAKING CHANGE (engine): Changed expected arguments for model's `Element#is()`, `Text#is()` and `TextProxy#is()` (element name is no longer accepted as a first argument, type argument is required for name checks). MAJOR BREAKING CHANGE (engine): Changed expected arguments for view's `Element#is()`, `Text#is()`, `TextProxy#is()`, `AttributeElement#is()`, `ContainerElement#is()`, `EditableElement#is()`, `EmptyElement#is()`, `UIElement#is()` (element name is no longer accepted as a first argument, type argument is required for name checks).
To sum up, this change modifies arguments of Element name parameterBefore this change ModelBefore: element.is( 'image' );
rootElement.is( '$root' ); After: element.is( 'element', 'image' );
rootElement.is( 'element', '$root' );
rootElement.is( 'rootElement', '$root' ); ViewBefore: element.is( 'img' );
containerElement.is( 'div' );
emptyElement.is( 'img' );
attributeElement.is( 'b' );
editableElement.is( 'div' );
rootEditableElement.is( 'div' );
uiElement.is( 'span' ); After: element.is( 'element', 'img' );
containerElement.is( 'element', 'div' );
emptyElement.is( 'element', 'img' );
attributeElement.is( 'element', 'b' );
editableElement.is( 'element', 'div' );
rootEditableElement.is( 'element', 'div' );
uiElement.is( 'element', 'span' ); Text and TextProxy type parameterBefore this change Before: text.is( 'text' );
textProxy.is( 'textProxy' ); After: text.is( '$text' );
textProxy.is( '$textProxy' ); |
📝 Provide detailed reproduction steps (if any)
I've been recently trying to pass this SVG through the DOM <-> view conversion:
Unfortunately, it throws at one point with:
The error comes from https://github.com/ckeditor/ckeditor5/blob/2f1568d/packages/ckeditor5-engine/src/view/domconverter.js#L960.
The issue is that the SVG uses a
<text>
element and that falls into this case:https://github.com/ckeditor/ckeditor5/blob/2f1568d/packages/ckeditor5-engine/src/view/domconverter.js#L204-L209
Unfortunately, we made a very bad decision to allow checking element names with
is( elementName )
instead of forcing ais( 'element', elementName )
notation.Proposal
Unfortunately, I can't see an option to avoid introducing a breaking change.
Even if we'd replace all our
is( elementName )
usage withis( 'element', elementName )
and add warning tois( elementName )
for cases whereelementName != NODE_TYPE_ENUM
to notify people about using a deprecated and unsafe API, theis( 'text' )
check that we would still have in our code (cause we're looking for a text node) would still make the SVG case fail.To avoid a BC we'd need to introduce a new API for checking element type but that makes no sense as
is()
was created for primarily this reason.Therefore, I'm for:
is( elementName )
.is( elementName )
usage withis( 'element', elementName )
.is()
methods when they are used with first param from beyond theNODE_TYPE_ENUM
to help with migration. However, since it's fairly simple to find allis()
usage, this would not be a big help.If you'd like to see this fixed sooner, add a 👍 reaction to this post.
The text was updated successfully, but these errors were encountered: