Skip to content

Refactor Complex DOM CSS generator - #246

Merged
issackjohn merged 4 commits into
WebKit:mainfrom
lpardosixtosMs:issackjohn/ComplexDOMRefactorCssGenerator
Jun 29, 2023
Merged

issackjohn merged 4 commits into
WebKit:mainfrom
lpardosixtosMs:issackjohn/ComplexDOMRefactorCssGenerator

Conversation

@issackjohn

Copy link
Copy Markdown
Contributor

Refactored the CSS generator to use JSDOM and html markups to create the targeted CSS selectors.

With this PR we can generate CSS for the Complex DOM version of Angular TodoMVC.

Refactored the CSS generator to use JSDOM and html markups.
@lpardosixtosMs

Copy link
Copy Markdown
Contributor

@bgrins can you take a look. @issackjohn refactored the Complex CSS generator to be more flexible. Now we can generate targeted css for the Angular TodoMVC.

@bgrins

bgrins commented Jun 20, 2023

Copy link
Copy Markdown
Contributor

Maybe naive question, but why can't we update the Angular markup to match all the others so it doesn't need special handling?

@bgrins

bgrins commented Jun 20, 2023

Copy link
Copy Markdown
Contributor

There are some updates in here that look good regardless, but it would be nice if we didn't have to work around a case for Angular specifically.

One other question - I see changes between the current CSS and the new CSS after this refactor. For example in the deleted matching.css there were some rules with .top-bar https://github.com/WebKit/Speedometer/pull/246/files#diff-2d83897a8d4871731e922269b9fa2c8eea145c17801e3e7c807748f0b9614bd7L1 but then in the new generated.css I don't see it https://github.com/WebKit/Speedometer/pull/246/files#diff-c8db8ce599a2ff7895e5a612f92938ffb6db09f4339e7928e0e300a93f4d1d47R1. I don't have an opinion on which CSS is better but would like to understand why that's happened. I.e. is that a consequence of the specified HTML changing (and then the seeded random number generator selects a different element instead)?

@lpardosixtosMs

Copy link
Copy Markdown
Contributor

Maybe naive question, but why can't we update the Angular markup to match all the others so it doesn't need special handling?

I'm not familiar with angular, we assumed that those custom tags are the usual way to code and went with it. @flashdesignory would it make sense to change those tags to match the others?

@lpardosixtosMs

Copy link
Copy Markdown
Contributor

There are some updates in here that look good regardless, but it would be nice if we didn't have to work around a case for Angular specifically.

One other question - I see changes between the current CSS and the new CSS after this refactor. For example in the deleted matching.css there were some rules with .top-bar https://github.com/WebKit/Speedometer/pull/246/files#diff-2d83897a8d4871731e922269b9fa2c8eea145c17801e3e7c807748f0b9614bd7L1 but then in the new generated.css I don't see it https://github.com/WebKit/Speedometer/pull/246/files#diff-c8db8ce599a2ff7895e5a612f92938ffb6db09f4339e7928e0e300a93f4d1d47R1. I don't have an opinion on which CSS is better but would like to understand why that's happened. I.e. is that a consequence of the specified HTML changing (and then the seeded random number generator selects a different element instead)?

Yes, even though we are using the same seed, the steps of the generator changed a little bit so now it picks different elements.

@lpardosixtosMs

Copy link
Copy Markdown
Contributor

Maybe naive question, but why can't we update the Angular markup to match all the others so it doesn't need special handling?

I'm not familiar with angular, we assumed that those custom tags are the usual way to code and went with it. @flashdesignory would it make sense to change those tags to match the others?

I imagine we'll have a similar issue if we introduce something using web components, so we might as well have flexible generator from the beginning.

@flashdesignory

Copy link
Copy Markdown
Contributor

Maybe naive question, but why can't we update the Angular markup to match all the others so it doesn't need special handling?

I'm not familiar with angular, we assumed that those custom tags are the usual way to code and went with it. @flashdesignory would it make sense to change those tags to match the others?

what specific markup are we referring to? It's been a while that I looked at this workload...

@lpardosixtosMs

Copy link
Copy Markdown
Contributor

Maybe naive question, but why can't we update the Angular markup to match all the others so it doesn't need special handling?

I'm not familiar with angular, we assumed that those custom tags are the usual way to code and went with it. @flashdesignory would it make sense to change those tags to match the others?

what specific markup are we referring to? It's been a while that I looked at this workload...

The angular version have some extra <app-todo-header>, <app-todo-list>, and <app-todo-item> tags surrounding the header, list and items.
image

@flashdesignory

Copy link
Copy Markdown
Contributor

Got it... the updated Angular version uses components (todo-list, todo-item, ect), instead of the previous version that was just one file (in speedometer 2.1). That's where these tags are coming from.

This is the most common way I saw Angular devs using components in their apps and therefore the most representing way of a typical Angular app.

There are probably several different ways to do this differently, but we usually tend to go with the most common approach.

@@ -0,0 +1,50 @@
export const ANGULAR_TODO_MVC_HTML_MARKUP = `
<div class="main-ui" dir="ltr">

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This doesn't match the markup I see on https://speedometer-preview.netlify.app/resources/todomvc/architecture-examples/angular/dist/.

I was pasting this in the web console to simulate 100 items, although it's not necessary to see the discrepency:

var numberOfItemsToAdd = 100;
var newTodo = document.querySelector(".new-todo");
for (let i = 0; i < numberOfItemsToAdd; i++) {
  newTodo.value = `Something to do ${i}`;
  newTodo.dispatchEvent(new Event("input"))
  enter(newTodo)
}


function enter(node, options = undefined) {
  let keyCode = 13;
  let eventOptions = { bubbles: true, cancelable: true, keyCode, key: "Enter", which: keyCode };
  const event = new KeyboardEvent("keyup", eventOptions);
  node.dispatchEvent(event);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We might consider generating the necessary HTML with 100 todo items from the live test contents (starting with something like the above) and pasting it here, compared with needing to keep a duplicate shell and todo generation logic in the script here.

I think that would be an improvement, as it would be easier to keep in sync with changes and I think have less room for error in the codegen script, but I don't feel strongly that it must happen right now.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

These are supposed to match the html structure from here https://issackjohn.github.io/Speedometer/resources/todomvc/architecture-examples/angular/embedded-dist/ , which already contain some of the modifications I introduced in the other PR.. Although, the order of top-bar and ribbon is wrong and must be fixed.

I'd be happy if we could get rid of this manual step down the line.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Makes sense. I'd like to get #239 landed to make this easier to compare with

@lpardosixtosMs

Copy link
Copy Markdown
Contributor

There are some updates in here that look good regardless, but it would be nice if we didn't have to work around a case for Angular specifically.
One other question - I see changes between the current CSS and the new CSS after this refactor. For example in the deleted matching.css there were some rules with .top-bar https://github.com/WebKit/Speedometer/pull/246/files#diff-2d83897a8d4871731e922269b9fa2c8eea145c17801e3e7c807748f0b9614bd7L1 but then in the new generated.css I don't see it https://github.com/WebKit/Speedometer/pull/246/files#diff-c8db8ce599a2ff7895e5a612f92938ffb6db09f4339e7928e0e300a93f4d1d47R1. I don't have an opinion on which CSS is better but would like to understand why that's happened. I.e. is that a consequence of the specified HTML changing (and then the seeded random number generator selects a different element instead)?

Yes, even though we are using the same seed, the steps of the generator changed a little bit so now it picks different elements.

It is not only that .top-bar is not appearing, no classname on that level of the DOM is used, which seems unlikely. It is probably an error with the depths, we are investigating.

Address PR comments.
@flashdesignory

Copy link
Copy Markdown
Contributor

It is not only that .top-bar is not appearing, no classname on that level of the DOM is used, which seems unlikely. It is probably an error with the depths, we are investigating

@lpardosixtosMs - was this solved?

@lpardosixtosMs

Copy link
Copy Markdown
Contributor

It is not only that .top-bar is not appearing, no classname on that level of the DOM is used, which seems unlikely. It is probably an error with the depths, we are investigating

@lpardosixtosMs - was this solved?

@flashdesignory Yes, the latest patch addresses all the comments.

@flashdesignory

Copy link
Copy Markdown
Contributor

@rniwa - do you want to take a look at this one too, or is it good to merge?

@issackjohn

Copy link
Copy Markdown
Contributor Author

Just resolved a new conflict with .gitignore.

The html markup must contain a `<app-root>` tag that wraps around the `<section>` tag of the Angular TodoMVC's complex DOM version.
@rniwa

rniwa commented Jun 28, 2023 •

Copy link
Copy Markdown
Member

Administrative: @issackjohn you should have write access to the repository now. Let me know if you do not. Also, are you on webkit.slack.com?

@issackjohn

issackjohn commented Jun 28, 2023 •

Copy link
Copy Markdown
Contributor Author

Administrative: @issackjohn you should have write access to the repository now. Let me know if you do not. Also, are you on webkit.slack.com?

image

@rniwa I still don't have write access. and no, I'm not on there, could you invite me please?

@rniwa

rniwa commented Jun 28, 2023

Copy link
Copy Markdown
Member

How about now?

@issackjohn

Copy link
Copy Markdown
Contributor Author

How about now?

Yeah I have it now.

@rniwa

rniwa commented Jun 29, 2023

Copy link
Copy Markdown
Member

How about now?

Yeah I have it now.

In that case, you can go ahead & squash-merge this.

@issackjohn
issackjohn merged commit ad36a2c into WebKit:main Jun 29, 2023
@issackjohn
issackjohn deleted the issackjohn/ComplexDOMRefactorCssGenerator branch July 3, 2023 21:06
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.

5 participants