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