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

Merged

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!

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks I will test this tomorrow..

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay I did some desk testing with the new change and there are couple of issues with this change.

  1. Although body is focusable, it is not tabbable which actually takes user out of tab order and if once the focus is reseton body, pressing Tab after that does nothing.
  2. In previous case, the reset was focusing the logo, which was kind of first in the tab order and users can now tab through out the page which is not possible in the new change.
  3. It looks like, this function ( old version, not the change) is broken in serverless, since logo with class chrHeaderLogo does not even exists in Serverless.
    • this begs the question, if we even need this functionality. I will discuss with the team today and if we do not, i will push the commit to remove it.

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 @logeekal!

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 Does this PR need to be held on the discussion with your team? I hope not, and I think that if nothing else is blocking this PR, it could get approved and the team discussion could be handled as follow-up work.

Does that sound ok?

Copy link
Contributor

Choose a reason for hiding this comment

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

@tsullivan , Sorry for the delay from my side. It took time to get full information, but i can say that this piece of code is not required at our end. But I will create a separate PR to remove it so that you are not blocked.

I will create a separate PR to add that code. Thanks for your patience.

@tsullivan
Copy link
Member Author

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

@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)

Copy link
Contributor

@logeekal logeekal left a comment

Choose a reason for hiding this comment

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

investigations LGTM 🚀 . Thanks for answering all our queries.

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

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 14.6MB 14.6MB -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.6KB 450.2KB -4.4KB

History

Copy link
Contributor

@eokoneyo eokoneyo left a comment

Choose a reason for hiding this comment

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

LGTM

@tsullivan tsullivan merged commit d86896b into elastic:main Dec 4, 2024
9 checks passed
@tsullivan tsullivan deleted the remove-sass/core-chrome-browser-internal branch December 4, 2024 17:39
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.x

https://github.com/elastic/kibana/actions/runs/12165272922

@kibanamachine kibanamachine added the backport missing Added to PRs automatically when the are determined to be missing a backport. label Dec 5, 2024
@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 199885 locally

tsullivan added a commit to tsullivan/kibana that referenced this pull request Dec 6, 2024
Part of elastic/kibana-team#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.

1. https://emotion.sh/docs/globals
2. https://emotion.sh/docs/best-practices
3.
elastic/eui#6828 (comment)

---------

Co-authored-by: Jatin Kathuria <[email protected]>
(cherry picked from commit d86896b)
@tsullivan
Copy link
Member Author

💚 All backports created successfully

Status Branch Result
8.x

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

SoniaSanzV pushed a commit to SoniaSanzV/kibana that referenced this pull request Dec 9, 2024
## Summary

Part of elastic/kibana-team#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.
elastic/eui#6828 (comment)

---------

Co-authored-by: Jatin Kathuria <[email protected]>
SoniaSanzV pushed a commit to SoniaSanzV/kibana that referenced this pull request Dec 9, 2024
## Summary

Part of elastic/kibana-team#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.
elastic/eui#6828 (comment)

---------

Co-authored-by: Jatin Kathuria <[email protected]>
tsullivan added a commit that referenced this pull request Dec 9, 2024
# Backport

This will backport the following commits from `main` to `8.x`:
- [[SharedUX] Replace Sass with Emotion, Round 1
(#199885)](#199885)

<!--- Backport version: 8.9.8 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Tim
Sullivan","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-12-04T17:39:22Z","message":"[SharedUX]
Replace Sass with Emotion, Round 1 (#199885)\n\n## Summary\r\n\r\nPart
of https://github.com/elastic/kibana-team/issues/1082\r\n\r\nSelects
certain Sass files to replace with styles declared with Emotion.\r\nThis
PR does not include any changes that would be noticeable
by\r\nend-users. It changes the internals to use a different technology
for\r\nstyling components.\r\n\r\n~~Some `className` attributes have
been kept, because they are\r\nreferenced in JS and tests.~~ Update: all
classNames that are no longer\r\nneeded for styling purposes have been
removed.\r\n* If the className was needed for tests, it has been
replaced with a\r\ntest-subj.\r\n* If the className was used as a
selector in production code, it has\r\nbeen replaced with alternative
JS.\r\n\r\n## References\r\n1. https://emotion.sh/docs/globals\r\n2.
https://emotion.sh/docs/best-practices\r\n3.\r\nhttps://github.com/elastic/eui/discussions/6828#discussioncomment-10825360\r\n\r\n---------\r\n\r\nCo-authored-by:
Jatin Kathuria
<[email protected]>","sha":"d86896bac0bbc5ed48b43e695e0a73c55b21450c","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","backport
missing","v9.0.0","backport:prev-minor"],"number":199885,"url":"https://github.com/elastic/kibana/pull/199885","mergeCommit":{"message":"[SharedUX]
Replace Sass with Emotion, Round 1 (#199885)\n\n## Summary\r\n\r\nPart
of https://github.com/elastic/kibana-team/issues/1082\r\n\r\nSelects
certain Sass files to replace with styles declared with Emotion.\r\nThis
PR does not include any changes that would be noticeable
by\r\nend-users. It changes the internals to use a different technology
for\r\nstyling components.\r\n\r\n~~Some `className` attributes have
been kept, because they are\r\nreferenced in JS and tests.~~ Update: all
classNames that are no longer\r\nneeded for styling purposes have been
removed.\r\n* If the className was needed for tests, it has been
replaced with a\r\ntest-subj.\r\n* If the className was used as a
selector in production code, it has\r\nbeen replaced with alternative
JS.\r\n\r\n## References\r\n1. https://emotion.sh/docs/globals\r\n2.
https://emotion.sh/docs/best-practices\r\n3.\r\nhttps://github.com/elastic/eui/discussions/6828#discussioncomment-10825360\r\n\r\n---------\r\n\r\nCo-authored-by:
Jatin Kathuria
<[email protected]>","sha":"d86896bac0bbc5ed48b43e695e0a73c55b21450c"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","labelRegex":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/199885","number":199885,"mergeCommit":{"message":"[SharedUX]
Replace Sass with Emotion, Round 1 (#199885)\n\n## Summary\r\n\r\nPart
of https://github.com/elastic/kibana-team/issues/1082\r\n\r\nSelects
certain Sass files to replace with styles declared with Emotion.\r\nThis
PR does not include any changes that would be noticeable
by\r\nend-users. It changes the internals to use a different technology
for\r\nstyling components.\r\n\r\n~~Some `className` attributes have
been kept, because they are\r\nreferenced in JS and tests.~~ Update: all
classNames that are no longer\r\nneeded for styling purposes have been
removed.\r\n* If the className was needed for tests, it has been
replaced with a\r\ntest-subj.\r\n* If the className was used as a
selector in production code, it has\r\nbeen replaced with alternative
JS.\r\n\r\n## References\r\n1. https://emotion.sh/docs/globals\r\n2.
https://emotion.sh/docs/best-practices\r\n3.\r\nhttps://github.com/elastic/eui/discussions/6828#discussioncomment-10825360\r\n\r\n---------\r\n\r\nCo-authored-by:
Jatin Kathuria
<[email protected]>","sha":"d86896bac0bbc5ed48b43e695e0a73c55b21450c"}}]}]
BACKPORT-->
@kibanamachine kibanamachine removed the backport missing Added to PRs automatically when the are determined to be missing a backport. label Dec 9, 2024
CAWilson94 pushed a commit to CAWilson94/kibana that referenced this pull request Dec 9, 2024
## Summary

Part of elastic/kibana-team#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.
elastic/eui#6828 (comment)

---------

Co-authored-by: Jatin Kathuria <[email protected]>
Samiul-TheSoccerFan pushed a commit to Samiul-TheSoccerFan/kibana that referenced this pull request Dec 10, 2024
## Summary

Part of elastic/kibana-team#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.
elastic/eui#6828 (comment)

---------

Co-authored-by: Jatin Kathuria <[email protected]>
CAWilson94 pushed a commit to CAWilson94/kibana that referenced this pull request Dec 12, 2024
## Summary

Part of elastic/kibana-team#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.
elastic/eui#6828 (comment)

---------

Co-authored-by: Jatin Kathuria <[email protected]>
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 v8.18.0 v9.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants