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

Stop creating unnecessary arrays in Renderer._updateAttrs #16918

Conversation

sunesimonsen
Copy link

This PR optimizes the Renderer._updateAttrs by removing a unnecessary Array.from call.

This change is a bit more controversial than my previous changes as it changes the order of iterations. I believe the semantics to be identical, but it should be reviewed with a bit of extra care.

@sunesimonsen sunesimonsen marked this pull request as ready for review August 13, 2024 15:34
@scofalik
Copy link
Contributor

scofalik commented Sep 2, 2024

Thanks for this suggestion! We plan to include it in the October CKEditor 5 release.

It wasn't clear to me why you needed to change the order - it shouldn't matter. But there was a test failing and after debugging I realized that attributes are sometimes renamed as they are set on DOM due to unsafe attributes handling. Hence, it is important to remove first, and set second, as the other way around we would remove an attribute that was just set.

I'll add a comment as this is not obvious at the first glance.

@sunesimonsen
Copy link
Author

It wasn't clear to me why you needed to change the order - it shouldn't matter. But there was a test failing and after debugging I realized that attributes are sometimes renamed as they are set on DOM due to unsafe attributes handling. Hence, it is important to remove first, and set second, as the other way around we would remove an attribute that was just set.

Yes it was to avoid the test failure.

@scofalik
Copy link
Contributor

Introduced in #17144.

@scofalik scofalik closed this Sep 24, 2024
// Remove from DOM attributes which do not exists in the view.
for ( const key of domAttrKeys ) {
for ( const attr of ( domElement as DomElement ).attributes ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Unfortunately, we had to partially revert this line as it caused issues removing multiple attributes as attributes is a live collection.
The fix: https://github.com/ckeditor/ckeditor5/pull/17489/files

Copy link
Author

Choose a reason for hiding this comment

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

Sorry about that.

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.

3 participants