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

[SharedUX] Replace Sass with Emotion, Round 1 #199885

Open
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

tsullivan
Copy link
Member

@tsullivan tsullivan commented Nov 12, 2024

Summary

Part of https://github.com/elastic/kibana-team/issues/1082

Selects certain Sass files to replace with styles declared with Emotion. This PR does not include any changes that would be noticeable by end-users. It changes the internals to use a different technology for styling components.

Some className attributes have been kept, because they are referenced in JS and tests. Update: all classNames that are no longer needed for styling purposes have been removed.

  • If the className was needed for tests, it has been replaced with a test-subj.
  • If the className was used as a selector in production code, it has been replaced with alternative JS.

References

  1. https://emotion.sh/docs/globals
  2. https://emotion.sh/docs/best-practices
  3. [FAQ] Kibana and Emotion / CSS-in-JS usage eui#6828 (comment)

@tsullivan tsullivan requested review from a team as code owners November 12, 2024 22:47
@tsullivan tsullivan force-pushed the remove-sass/core-chrome-browser-internal branch from 0c39420 to d3fe030 Compare November 12, 2024 22:50
Comment on lines -6 to -8
.euiHeaderSectionItem .euiButtonEmpty__text {
// stop global header buttons from jumping during loading state
display: flex;
Copy link
Member Author

Choose a reason for hiding this comment

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

I did not port these styles over, because I do not see the global header buttons jumping around during loading state.

Copy link
Contributor

Choose a reason for hiding this comment

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

I just added this in a recent PR. See if you notice it when throttling your browser... in particular, the spaces button (loading rectangle) would jump up and right in a flash.

Copy link
Contributor

Choose a reason for hiding this comment

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

Checked locally, and it looks like the jump is there if this is excluded.

CleanShot.2024-11-13.at.10.03.40.mp4

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks @ryankeairns! I restored these styles in 8e4cd1d. I will try to improve my test method

@tsullivan tsullivan changed the title [SharedUX] Replace Sass with Emotion, round 1 [SharedUX] Replace Sass with Emotion, Round 1 Nov 12, 2024
@tsullivan tsullivan added release_note:skip Skip the PR/issue when compiling release notes backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) labels Nov 12, 2024
@@ -71,6 +72,7 @@ Array [
aria-hidden="true"
aria-labelledby="elasticMark"
class="chrHeaderLogo__mark"
css="You have tried to stringify object returned from \`css\` function. It isn't supposed to be used directly (e.g. as value of the \`className\` prop), but rather handed to emotion so it can handle it (e.g. as value of \`css\` prop)."
Copy link
Member Author

Choose a reason for hiding this comment

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

As far as I can tell, it is normal to see this message in a snapshot file when the component uses a css prop that gets an object returned from the css function.

@ryankeairns ryankeairns self-requested a review November 13, 2024 22:57
@@ -102,11 +119,12 @@ export function HeaderLogo({ href, navigateToApp, loadingCount$, ...observables
<img
src={customizedLogo}
className="chrHeaderLogo__mark"
Copy link
Contributor

Choose a reason for hiding this comment

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

I know we left these className in here because it's targeted some test files, what do you think about swapping this for testIds especially that it wont be apparent to some other person much later?

Copy link
Member Author

@tsullivan tsullivan Nov 20, 2024

Choose a reason for hiding this comment

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

@eokoneyo thanks for taking a look at this. I would prefer to leave this as it is. It will help this PR, and others like it, to avoid ballooning the refactoring into something larger than it needs to be. Changing this code could impact other code owners as well, and then add the need for more teams to review.

Edit: let me think more about this. One of the class names is used as a selector for production code. That probably isn't the best practice and there should be a more acceptable way.

Copy link
Member Author

Choose a reason for hiding this comment

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

bb45851 replaced a className with a testId, since it was only needed for a test

Copy link
Contributor

Choose a reason for hiding this comment

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

Heyy @tsullivan , @eokoneyo ,

Just curious from investigations perspective, I agree that tests should target test-ids but is there a downside of keeping classNames here?

Copy link
Member Author

Choose a reason for hiding this comment

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

@logeekal The downside of using classNames for non-style purposes is that classNames are not a public contract, so they shouldn't be used for other things.

As we're replacing CSS/SASS with Emotion, for thoroughness, the typical followup will be to remove the className from the DOM, for thoroughness. We could break integrations if we fail to realize that some place in the repo is using that className as a selector in production code.

Relevant: 24f6977

@tsullivan tsullivan requested a review from a team as a code owner November 21, 2024 23:20
@@ -184,7 +184,7 @@ export const focusUtilityBarAction = (containerElement: HTMLElement | null) => {
* Resets keyboard focus on the page
*/
export const resetKeyboardFocus = () => {
document.querySelector<HTMLAnchorElement>('header.headerGlobalNav a.chrHeaderLogo')?.focus();
Copy link
Member Author

Choose a reason for hiding this comment

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

@elastic/security-threat-hunting-investigations in reviewing this, let's consider accessibility. The way this works should keep a logical and intuitive flow in keyboard navigation.

Copy link
Contributor

Choose a reason for hiding this comment

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

@michaelolo24 / @kqualters-elastic Any historical context here? Was this just added to remove keyboard focus?

As suggested by @tsullivan in the slack thread , I think I agree that we can use document.body.focus() as well. Do you have any opinion?

Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure on the context of this to be honest, seems it's used in conjunction with https://github.com/elastic/kibana/blob/main/x-pack/plugins/timelines/common/utils/accessibility/helpers.ts#L772 . What exactly is wrong with this? "The way this works should keep a logical and intuitive flow in keyboard navigation." is this not the case now?

Copy link
Member Author

@tsullivan tsullivan Nov 25, 2024

Choose a reason for hiding this comment

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

What exactly is wrong with this? "The way this works should keep a logical and intuitive flow in keyboard navigation." is this not the case now?

@kqualters-elastic this is what SharedUX team needs the @elastic/security-threat-hunting team to test and verify, because we don't know how to access all of the parts that this change could affect. The context is that this code needs to change because .chrHeaderLogo is going away for cleanup purposes.

Let us know if you or a delegate can confirm that the functionality is not negatively impacted, or wish to see this modified in some way. Thanks!

@tsullivan
Copy link
Member Author

@eokoneyo fully removing the class names had minimal effects. Can you re-review?

@elasticmachine
Copy link
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] x-pack/test/alerting_api_integration/security_and_spaces/group1/config.ts / alerting api integration security and spaces enabled Alerts - Group 1 alerts backfill rule runs ad hoc backfill task should run all execution sets of a scheduled backfill and correctly generate alerts

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
core 448 434 -14

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
securitySolution 13.4MB 13.4MB -83.0B

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
core 454.2KB 449.8KB -4.4KB

History

@clintandrewhall
Copy link
Contributor

Some className attributes have been kept, because they are referenced in JS and tests

If it still applies, if class names are referenced in tests, convert to data-test-subj.

@tsullivan
Copy link
Member Author

@clintandrewhall

If it still applies, if class names are referenced in tests, convert to data-test-subj.

That part of the description is outdated. I will update.

See also the thread here: #199885 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) release_note:skip Skip the PR/issue when compiling release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants