SlideShare a Scribd company logo
1 of 54
Download to read offline
A Journey from
SASS to CSS-in-JS
Martin Jujou (jooj)
About me
@mjujou
Current Domain
Frontend Landscape
● ~ 288 Reusable / Themable React
components
● ~ 62 page level components
● 4 Single Page Apps (SPA) components
● Many node servers
Current Domain React
Landscape
fe-pa-xyz
Or
fe-spa-xyz
fe-co-ccc
fe-co-bbb
fe-co-aaa
fe-server-xxxx
Node server React
React
Let's start the (long) Journey ...
Why SASS
Rewind to June 2016… (When i started at Domain)
● SASS was used on a few components already
● Our common style library was written in SASS
(fe-brary)
● At the time it was more popular than most other
style frameworks / extensions
● Worked well enough alongside React
How we used SASS
At a very high level :)
<Select />
(scss, js, static files)
fe-build
(internal build tool)
fe-brary
(common sass,
mixins, variables,
placeholders etc)
Bundle Command Output:
*.css
*.js
Static assets
How we used SASS
<Select />
Why #no-sass
Fast-forward to Jan 2017 …
Why #no-sass
Why #no-sass
Why #no-sass
We needed to step back to think more about the WHY
● Multiple versions of the same component caused style clashes.
● BEM syntax was annoying (required too much developer brain power)
● Bloated css output, nested selector overload, unused css on a given
page
● Needed critical css
● Sass compilation was slow due to a few factors (theming, static assets
etc)
● node-sass binary was problematic on different platforms (eg:
windows)
<MyPageComponent />
<Select /> 1.0.4
<SearchFilters /> 1.0.0 <Select /> 2.0.0
Why #no-sass
Why we needed to be careful with our decision
● Need to keep components consistent
● Not easy to update many components
● Performance was critical
● We wanted a framework which was relatively future
proof
● We need a great developer experience
We needed to experiment
styled-components
styled-components
styled-components
Pros:
- Most popular CSS-in-JS framework
- Easier to delete unused css (tied to components)
- Good performance
Cons:
- Difficult for us to migrate to (code mod would be
impossible)
- Bundle size isn't great (at the time)
- JSX no longer semantic (relies on good naming)
- Architecting SC projects is a challenge
Glamorous
Glamorous
Glamorous
Pros:
- Easier to delete unused css
- Good performance + bundle size
- Extraction of css
Cons:
- Difficult for us to migrate to (code mod would be
impossible)
- Quickly became clear the author (Kent C Dodds) was
in favour of emotion (eventually deprecated) .. DOA
Styled jsx
Styled jsx
Pros:
● shadow dom-style encapsulation, closely resembles
web components
● Fast and small bundle
● Future-proof: Equivalent to server-renderable
"Shadow CSS"
Cons:
● Not very intuitive (having style block inside JSX
confused developers)
● Not very mature at the time of investigation + not very
popular outside of nextjs
Postcss + CSS Modules
● It's not CSS-in-JS !! This would be a staged approach
prior to making the full move to CSS-in-JS
● What if we could satisfy some of these pain points
quickly:
○ Keeping same scss syntax so no major changes
needed in each component
○ Getting rid of problematic node-sass binary
○ Removing the need to use BEM
Postcss + CSS Modules
Pros:
- Got a component working with minimal sass changes
- Extraction of css
Cons:
- Ended up being slower !! We needed lots of plugins
- Not all sass syntax could be supported (eg: @function,
@if )
- Some nasty side effects (eg: sass math evaluation was
different)
Postcss + CSS Modules
● postcss-scss (Parser)
● postcss-easy-import
● postcss-url
● postcss-advanced-variables
● postcss-hexrgba
● postcss-color-function
● postcss-functions
● postcss-flexbugs-fixes
● postcss-nested
● postcss-extend-rule
● postcss-at-rules-variables
● postcss-property-lookup
● postcss-calc
● postcss-automath
● postcss-current-selector
● postcss-at-warn
● postcss-warn-cleaner
Emotion
Emotion
Emotion
Emotion
Pros:
- Popular CSS-in-JS framework
- Excellent performance
- Don't need to clutter JSX with styled components
- Easiest migration path out of all CSS-in-JS frameworks
- Supports composition, nested selectors and global styles
- Supports server side rendering
- Plays nice with legacy sass components
Cons:
- Docs not as good as something like styled components (bit better
now)
Emotion
Finally agreed this was the path forward !
How?
Styled Components
● Agreed not to use import styled from '@emotion/styled' yet ...
○ Easier migration path to use css string styles (can automate some
bits)
○ Less brain power required, using styled approach would need a
re-architecture of the component being reworked (including JSX
changes)
○ Less semantic in JSX if using styled
○ Disabling with eslint rule
If this turns out to be too restrictive we can bring it back in the future - was a
heated topic
Styled Components
Server Side Rendering
Emotion 9 required mods to our internal
tooling at the time to ensure css was inlined
into HTML
Emotion 10 has SSR work out of the box !!
peerDep
Exporting style variables
with JS
Theming
Not ideal.. Need to
manually pass in theme for
each css
Theming
Style utility functions
Backwards compatibility
E2E Testing
Style linting
https://github.com/styled-components/stylelint-config-styled-components
Same style linter as styled components (works for emotion)
Co locating styles
CLI Migration Tool
SASS to Emotion: https://github.com/DomainGroupOSS/sass-to-emotion
Emotion workshops
Big wins
● No more style clashes if there is 2 majors in component tree (as
emotion classname hash is content based)
● No more node-sass !
● No need to worry about writing namespaced selectors
● Performance gains (faster bundling and faster runtime as there is
less css bloat !)
Common Questions
Class name labels
css-149rzh1
css-149rzh1-martin
Composing styles
Annoyances
Unit testing:
Annoyances
Passing custom class names to 3rd party components:
● Anti-pattern to doing this but sometimes it's necessary for 3rd party components
● Was ok to do in emotion 9, but cumbersome in 10
Emotion 9 Emotion 10
Annoyances
Critical CSS - ordering of style tags isn't necessary ideal for SSR critical css ?
Thanks
Software Engineers

More Related Content

What's hot

Introduction to 5g technology
Introduction to 5g technologyIntroduction to 5g technology
Introduction to 5g technologyShambhu Ram
 
Network Architecture of 5G Mobile Tecnology
Network Architecture of 5G Mobile TecnologyNetwork Architecture of 5G Mobile Tecnology
Network Architecture of 5G Mobile Tecnologyvineetkathan
 
Fixed mobile convergence (fmc)
Fixed mobile convergence (fmc)Fixed mobile convergence (fmc)
Fixed mobile convergence (fmc)IEEE VESIT
 
5g wireless technology
5g wireless technology 5g wireless technology
5g wireless technology Sudhanshu Jha
 
4 g technology
4 g  technology4 g  technology
4 g technologyRitu Bafna
 
Beamforming for 5G Networks
Beamforming for 5G NetworksBeamforming for 5G Networks
Beamforming for 5G Networksijtsrd
 
Generations of network 1 g, 2g, 3g, 4g, 5g
Generations of network 1 g, 2g, 3g, 4g, 5gGenerations of network 1 g, 2g, 3g, 4g, 5g
Generations of network 1 g, 2g, 3g, 4g, 5gNoor Mohammad's Faltoos
 
Introduction to 3G technology
Introduction to 3G technologyIntroduction to 3G technology
Introduction to 3G technologyShweta Ghate
 
GPRS(General Packet Radio Service)
GPRS(General Packet Radio Service)GPRS(General Packet Radio Service)
GPRS(General Packet Radio Service)Jay Nagar
 
Mobile communication
Mobile communicationMobile communication
Mobile communicationsourabh kant
 
Generation of mobile communication systems
Generation of mobile communication systemsGeneration of mobile communication systems
Generation of mobile communication systemsjincy-a
 
4 g LTE, LTE Advance
4 g LTE, LTE Advance 4 g LTE, LTE Advance
4 g LTE, LTE Advance Sajid Marwat
 
Ppt on smart small cell with hybrid beamforming for 5 g
Ppt on smart small cell with hybrid beamforming for 5 gPpt on smart small cell with hybrid beamforming for 5 g
Ppt on smart small cell with hybrid beamforming for 5 gBhaskar Gurana
 
5G - Tech to business case
5G - Tech to business case5G - Tech to business case
5G - Tech to business case3G4G
 
5G Wireless Technology
5G Wireless Technology5G Wireless Technology
5G Wireless TechnologyNafees Alam
 
Ttalteoverview 100923032416 Phpapp01 (1)
Ttalteoverview 100923032416 Phpapp01 (1)Ttalteoverview 100923032416 Phpapp01 (1)
Ttalteoverview 100923032416 Phpapp01 (1)Deepak Sharma
 
Wireless communication theodore rappaport
Wireless communication   theodore rappaportWireless communication   theodore rappaport
Wireless communication theodore rappaportDaud Khan
 

What's hot (20)

Introduction to 5g technology
Introduction to 5g technologyIntroduction to 5g technology
Introduction to 5g technology
 
Network Architecture of 5G Mobile Tecnology
Network Architecture of 5G Mobile TecnologyNetwork Architecture of 5G Mobile Tecnology
Network Architecture of 5G Mobile Tecnology
 
5G tecnology
5G tecnology5G tecnology
5G tecnology
 
Fixed mobile convergence (fmc)
Fixed mobile convergence (fmc)Fixed mobile convergence (fmc)
Fixed mobile convergence (fmc)
 
5g wireless technology
5g wireless technology 5g wireless technology
5g wireless technology
 
4 g technology
4 g  technology4 g  technology
4 g technology
 
Beamforming for 5G Networks
Beamforming for 5G NetworksBeamforming for 5G Networks
Beamforming for 5G Networks
 
5 g
5 g5 g
5 g
 
Generations of network 1 g, 2g, 3g, 4g, 5g
Generations of network 1 g, 2g, 3g, 4g, 5gGenerations of network 1 g, 2g, 3g, 4g, 5g
Generations of network 1 g, 2g, 3g, 4g, 5g
 
Introduction to 3G technology
Introduction to 3G technologyIntroduction to 3G technology
Introduction to 3G technology
 
GPRS(General Packet Radio Service)
GPRS(General Packet Radio Service)GPRS(General Packet Radio Service)
GPRS(General Packet Radio Service)
 
Mobile communication
Mobile communicationMobile communication
Mobile communication
 
Generation of mobile communication systems
Generation of mobile communication systemsGeneration of mobile communication systems
Generation of mobile communication systems
 
4 g LTE, LTE Advance
4 g LTE, LTE Advance 4 g LTE, LTE Advance
4 g LTE, LTE Advance
 
Ppt on smart small cell with hybrid beamforming for 5 g
Ppt on smart small cell with hybrid beamforming for 5 gPpt on smart small cell with hybrid beamforming for 5 g
Ppt on smart small cell with hybrid beamforming for 5 g
 
5G - Tech to business case
5G - Tech to business case5G - Tech to business case
5G - Tech to business case
 
5G Wireless Technology
5G Wireless Technology5G Wireless Technology
5G Wireless Technology
 
Ttalteoverview 100923032416 Phpapp01 (1)
Ttalteoverview 100923032416 Phpapp01 (1)Ttalteoverview 100923032416 Phpapp01 (1)
Ttalteoverview 100923032416 Phpapp01 (1)
 
Gprs ppt
Gprs pptGprs ppt
Gprs ppt
 
Wireless communication theodore rappaport
Wireless communication   theodore rappaportWireless communication   theodore rappaport
Wireless communication theodore rappaport
 

Similar to A journey from sass to css in-js

Structuring your CSS for maintainability: rules and guile lines to write CSS
Structuring your CSS for maintainability: rules and guile lines to write CSSStructuring your CSS for maintainability: rules and guile lines to write CSS
Structuring your CSS for maintainability: rules and guile lines to write CSSSanjoy Kr. Paul
 
Efficiently theming a multi-site Drupal 8 portal - Drupal Dev Days Seville 2017
Efficiently theming a multi-site Drupal 8 portal - Drupal Dev Days Seville 2017Efficiently theming a multi-site Drupal 8 portal - Drupal Dev Days Seville 2017
Efficiently theming a multi-site Drupal 8 portal - Drupal Dev Days Seville 2017La Drupalera
 
Stop your share point css become a di-sass-ter today - SPS Munich
Stop your share point css become a di-sass-ter today - SPS MunichStop your share point css become a di-sass-ter today - SPS Munich
Stop your share point css become a di-sass-ter today - SPS MunichStefan Bauer
 
KharkivJS: Flaws of the Web Components in 2019 and how to address them
KharkivJS: Flaws of the Web Components in 2019 and how to address themKharkivJS: Flaws of the Web Components in 2019 and how to address them
KharkivJS: Flaws of the Web Components in 2019 and how to address themVlad Fedosov
 
Know the reason behind choosing bootstrap as css framework
Know the reason behind choosing bootstrap as css frameworkKnow the reason behind choosing bootstrap as css framework
Know the reason behind choosing bootstrap as css frameworkOmkarsoft Bangalore
 
SPS Oslo - Stop your SharePoint CSS becoming a di-sass-ter today!
SPS Oslo - Stop your SharePoint CSS becoming a di-sass-ter today!SPS Oslo - Stop your SharePoint CSS becoming a di-sass-ter today!
SPS Oslo - Stop your SharePoint CSS becoming a di-sass-ter today!Stefan Bauer
 
Teams, styles and scalable applications
Teams, styles and scalable applicationsTeams, styles and scalable applications
Teams, styles and scalable applicationsVittorio Vittori
 
The Future is Modular, Jonathan Snook
The Future is Modular, Jonathan SnookThe Future is Modular, Jonathan Snook
The Future is Modular, Jonathan SnookFuture Insights
 
Post css - Getting start with PostCSS
Post css - Getting start with PostCSSPost css - Getting start with PostCSS
Post css - Getting start with PostCSSNeha Sharma
 
Architecting with Style
Architecting with StyleArchitecting with Style
Architecting with StyleTimothy Knight
 
CSS3 and a brief introduction to Google Maps API v3
CSS3 and a brief introduction to Google Maps API v3 CSS3 and a brief introduction to Google Maps API v3
CSS3 and a brief introduction to Google Maps API v3 Jeffrey Barke
 
An Introduction to CSS Frameworks
An Introduction to CSS FrameworksAn Introduction to CSS Frameworks
An Introduction to CSS FrameworksAdrian Westlake
 
Building Responsive Intranet using Sharepoint Framework solutions - Asish Pad...
Building Responsive Intranet using Sharepoint Framework solutions - Asish Pad...Building Responsive Intranet using Sharepoint Framework solutions - Asish Pad...
Building Responsive Intranet using Sharepoint Framework solutions - Asish Pad...Asish Padhy
 
CSS-in-JS in React: Why, current state, and bright future.
CSS-in-JS in React: Why, current state, and bright future.CSS-in-JS in React: Why, current state, and bright future.
CSS-in-JS in React: Why, current state, and bright future.Andrii Los
 
CSS Methodology
CSS MethodologyCSS Methodology
CSS MethodologyZohar Arad
 

Similar to A journey from sass to css in-js (20)

Structuring your CSS for maintainability: rules and guile lines to write CSS
Structuring your CSS for maintainability: rules and guile lines to write CSSStructuring your CSS for maintainability: rules and guile lines to write CSS
Structuring your CSS for maintainability: rules and guile lines to write CSS
 
Efficiently theming a multi-site Drupal 8 portal - Drupal Dev Days Seville 2017
Efficiently theming a multi-site Drupal 8 portal - Drupal Dev Days Seville 2017Efficiently theming a multi-site Drupal 8 portal - Drupal Dev Days Seville 2017
Efficiently theming a multi-site Drupal 8 portal - Drupal Dev Days Seville 2017
 
Stop your share point css become a di-sass-ter today - SPS Munich
Stop your share point css become a di-sass-ter today - SPS MunichStop your share point css become a di-sass-ter today - SPS Munich
Stop your share point css become a di-sass-ter today - SPS Munich
 
KharkivJS: Flaws of the Web Components in 2019 and how to address them
KharkivJS: Flaws of the Web Components in 2019 and how to address themKharkivJS: Flaws of the Web Components in 2019 and how to address them
KharkivJS: Flaws of the Web Components in 2019 and how to address them
 
Know the reason behind choosing bootstrap as css framework
Know the reason behind choosing bootstrap as css frameworkKnow the reason behind choosing bootstrap as css framework
Know the reason behind choosing bootstrap as css framework
 
Semantic markup
Semantic markupSemantic markup
Semantic markup
 
SPS Oslo - Stop your SharePoint CSS becoming a di-sass-ter today!
SPS Oslo - Stop your SharePoint CSS becoming a di-sass-ter today!SPS Oslo - Stop your SharePoint CSS becoming a di-sass-ter today!
SPS Oslo - Stop your SharePoint CSS becoming a di-sass-ter today!
 
Teams, styles and scalable applications
Teams, styles and scalable applicationsTeams, styles and scalable applications
Teams, styles and scalable applications
 
The Future is Modular, Jonathan Snook
The Future is Modular, Jonathan SnookThe Future is Modular, Jonathan Snook
The Future is Modular, Jonathan Snook
 
Post css - Getting start with PostCSS
Post css - Getting start with PostCSSPost css - Getting start with PostCSS
Post css - Getting start with PostCSS
 
slides-students-C04.pdf
slides-students-C04.pdfslides-students-C04.pdf
slides-students-C04.pdf
 
Architecting with Style
Architecting with StyleArchitecting with Style
Architecting with Style
 
CSS3 and a brief introduction to Google Maps API v3
CSS3 and a brief introduction to Google Maps API v3 CSS3 and a brief introduction to Google Maps API v3
CSS3 and a brief introduction to Google Maps API v3
 
An Introduction to CSS Frameworks
An Introduction to CSS FrameworksAn Introduction to CSS Frameworks
An Introduction to CSS Frameworks
 
Building Responsive Intranet using Sharepoint Framework solutions - Asish Pad...
Building Responsive Intranet using Sharepoint Framework solutions - Asish Pad...Building Responsive Intranet using Sharepoint Framework solutions - Asish Pad...
Building Responsive Intranet using Sharepoint Framework solutions - Asish Pad...
 
CSS Grid Systems
CSS Grid SystemsCSS Grid Systems
CSS Grid Systems
 
CSS-in-JS in React: Why, current state, and bright future.
CSS-in-JS in React: Why, current state, and bright future.CSS-in-JS in React: Why, current state, and bright future.
CSS-in-JS in React: Why, current state, and bright future.
 
Front end frameworks
Front end frameworksFront end frameworks
Front end frameworks
 
CSS Methodology
CSS MethodologyCSS Methodology
CSS Methodology
 
Building Webs Better
Building Webs BetterBuilding Webs Better
Building Webs Better
 

Recently uploaded

Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetEnjoy Anytime
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 

Recently uploaded (20)

Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 

A journey from sass to css in-js

  • 1. A Journey from SASS to CSS-in-JS Martin Jujou (jooj)
  • 4. Current Domain Frontend Landscape ● ~ 288 Reusable / Themable React components ● ~ 62 page level components ● 4 Single Page Apps (SPA) components ● Many node servers
  • 6. Let's start the (long) Journey ...
  • 7. Why SASS Rewind to June 2016… (When i started at Domain) ● SASS was used on a few components already ● Our common style library was written in SASS (fe-brary) ● At the time it was more popular than most other style frameworks / extensions ● Worked well enough alongside React
  • 8. How we used SASS At a very high level :) <Select /> (scss, js, static files) fe-build (internal build tool) fe-brary (common sass, mixins, variables, placeholders etc) Bundle Command Output: *.css *.js Static assets
  • 9. How we used SASS <Select />
  • 13. Why #no-sass We needed to step back to think more about the WHY ● Multiple versions of the same component caused style clashes. ● BEM syntax was annoying (required too much developer brain power) ● Bloated css output, nested selector overload, unused css on a given page ● Needed critical css ● Sass compilation was slow due to a few factors (theming, static assets etc) ● node-sass binary was problematic on different platforms (eg: windows) <MyPageComponent /> <Select /> 1.0.4 <SearchFilters /> 1.0.0 <Select /> 2.0.0
  • 14. Why #no-sass Why we needed to be careful with our decision ● Need to keep components consistent ● Not easy to update many components ● Performance was critical ● We wanted a framework which was relatively future proof ● We need a great developer experience
  • 15. We needed to experiment
  • 18. styled-components Pros: - Most popular CSS-in-JS framework - Easier to delete unused css (tied to components) - Good performance Cons: - Difficult for us to migrate to (code mod would be impossible) - Bundle size isn't great (at the time) - JSX no longer semantic (relies on good naming) - Architecting SC projects is a challenge
  • 21. Glamorous Pros: - Easier to delete unused css - Good performance + bundle size - Extraction of css Cons: - Difficult for us to migrate to (code mod would be impossible) - Quickly became clear the author (Kent C Dodds) was in favour of emotion (eventually deprecated) .. DOA
  • 23. Styled jsx Pros: ● shadow dom-style encapsulation, closely resembles web components ● Fast and small bundle ● Future-proof: Equivalent to server-renderable "Shadow CSS" Cons: ● Not very intuitive (having style block inside JSX confused developers) ● Not very mature at the time of investigation + not very popular outside of nextjs
  • 24. Postcss + CSS Modules ● It's not CSS-in-JS !! This would be a staged approach prior to making the full move to CSS-in-JS ● What if we could satisfy some of these pain points quickly: ○ Keeping same scss syntax so no major changes needed in each component ○ Getting rid of problematic node-sass binary ○ Removing the need to use BEM
  • 25. Postcss + CSS Modules Pros: - Got a component working with minimal sass changes - Extraction of css Cons: - Ended up being slower !! We needed lots of plugins - Not all sass syntax could be supported (eg: @function, @if ) - Some nasty side effects (eg: sass math evaluation was different)
  • 26. Postcss + CSS Modules ● postcss-scss (Parser) ● postcss-easy-import ● postcss-url ● postcss-advanced-variables ● postcss-hexrgba ● postcss-color-function ● postcss-functions ● postcss-flexbugs-fixes ● postcss-nested ● postcss-extend-rule ● postcss-at-rules-variables ● postcss-property-lookup ● postcss-calc ● postcss-automath ● postcss-current-selector ● postcss-at-warn ● postcss-warn-cleaner
  • 30. Emotion Pros: - Popular CSS-in-JS framework - Excellent performance - Don't need to clutter JSX with styled components - Easiest migration path out of all CSS-in-JS frameworks - Supports composition, nested selectors and global styles - Supports server side rendering - Plays nice with legacy sass components Cons: - Docs not as good as something like styled components (bit better now)
  • 31. Emotion Finally agreed this was the path forward !
  • 32. How?
  • 33. Styled Components ● Agreed not to use import styled from '@emotion/styled' yet ... ○ Easier migration path to use css string styles (can automate some bits) ○ Less brain power required, using styled approach would need a re-architecture of the component being reworked (including JSX changes) ○ Less semantic in JSX if using styled ○ Disabling with eslint rule If this turns out to be too restrictive we can bring it back in the future - was a heated topic
  • 35. Server Side Rendering Emotion 9 required mods to our internal tooling at the time to ensure css was inlined into HTML Emotion 10 has SSR work out of the box !!
  • 38. Theming Not ideal.. Need to manually pass in theme for each css
  • 45. CLI Migration Tool SASS to Emotion: https://github.com/DomainGroupOSS/sass-to-emotion
  • 47. Big wins ● No more style clashes if there is 2 majors in component tree (as emotion classname hash is content based) ● No more node-sass ! ● No need to worry about writing namespaced selectors ● Performance gains (faster bundling and faster runtime as there is less css bloat !)
  • 52. Annoyances Passing custom class names to 3rd party components: ● Anti-pattern to doing this but sometimes it's necessary for 3rd party components ● Was ok to do in emotion 9, but cumbersome in 10 Emotion 9 Emotion 10
  • 53. Annoyances Critical CSS - ordering of style tags isn't necessary ideal for SSR critical css ?