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

Replace uses of style prop #3345

Merged
merged 3 commits into from Jul 13, 2022
Merged

Replace uses of style prop #3345

merged 3 commits into from Jul 13, 2022

Conversation

jpveooys
Copy link
Contributor

@jpveooys jpveooys commented Jul 8, 2022

Related issue

Resolves #2600

Overview

This replaces all uses of style props with patterns from Styled Components.

Link to preview

https://5e25c277526d380020b5e418-qvmgkmtfwt.chromatic.com/

Reason

It is known that use of style={} causes unnecessary rerenders. Remaining uses of this are not consistent with existing SC patterns.

Work carried out

  • Replace remaining uses of style prop in components
  • Replace uses in stories for consistency
  • Fix sidebar width problem revealed after updating stories

Developer notes

Stories were updated as well for consistency and to make sure there are no more hits for style= in code.

@jpveooys jpveooys force-pushed the perf/remove-style-objects branch 5 times, most recently from 81c5c00 to cd17194 Compare July 11, 2022 12:22
@jpveooys jpveooys changed the title Replace all uses of style props Replace all uses of style prop Jul 11, 2022
@jpveooys jpveooys changed the title Replace all uses of style prop Replace all uses of style props Jul 11, 2022
@jpveooys jpveooys changed the title Replace all uses of style props Replace uses of style prop Jul 11, 2022
@@ -14,6 +14,7 @@ export const StyledSidebar = styled.aside<StyledSidebarProps>`
flex-direction: column;
position: relative;
z-index: ${zIndex('sidebar', 0)};
flex-shrink: 0;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removing the redundant intermediary <div> in the stories revealed this would be shrunk slightly when Sidebar is directly in SidebarWrapper, so this was added to fix that.

@@ -89,18 +95,8 @@ export const Default: ComponentStory<typeof Sidebar> = (props) => {

return (
<SidebarWrapper>
<div style={{ maxHeight: '30rem' }}>
Copy link
Contributor Author

@jpveooys jpveooys Jul 11, 2022

Choose a reason for hiding this comment

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

These intermediary divs were redundant as StyledSidebar has max-height applied to it already. Removing them did reveal a small problem with the StyledSidebar styles (see comment left there).

it('is is rendered below the mouse pointer', () => {
// jest-styled-components doesn't work with css props:
// https://github.com/styled-components/jest-styled-components/issues/250
it.skip('is is rendered below the mouse pointer', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

jest-styled-components doesn't understand css props unfortunately:

styled-components/jest-styled-components#250

offset: string
}) => (
<span
className="rn_text-s"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There was an old CSS framework class here!

@jpveooys jpveooys marked this pull request as ready for review July 11, 2022 15:52
Copy link
Collaborator

@thyhjwb6 thyhjwb6 left a comment

Choose a reason for hiding this comment

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

👍

Copy link
Member

@m7kvqbe1 m7kvqbe1 left a comment

Choose a reason for hiding this comment

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

LGTM

This replaces all uses of style props in components with preferred Styled Components patterns.
This replaces all uses of style props in stories with alternative Styled Components patterns.
This stops the width of `Sidebar` being shrunk when it's placed directly in `SidebarWrapper` (causing it to be less than 60px wide).
@sonarcloud
Copy link

sonarcloud bot commented Jul 13, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 2 Code Smells

96.7% 96.7% Coverage
0.0% 0.0% Duplication

@jpveooys jpveooys merged commit 32ff6cf into master Jul 13, 2022
@jpveooys jpveooys deleted the perf/remove-style-objects branch July 13, 2022 12:27
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.

Remove instances of style={}
3 participants