A brief analysis and comparison of the CSS for Twitter's PWA vs Twitter's legacy desktop website. The difference is dramatic and I'll touch on some reasons why.

Legacy site *downloads* ~630 KB CSS per theme and writing direction.

6,769 rules
9,252 selectors
16.7k declarations
3,370 unique declarations
44 media queries
36 unique colors
50 unique background colors
46 unique font sizes
39 unique z-indices

https://t.co/qyl4Bt1i5x
PWA *incrementally generates* ~30 KB CSS that handles all themes and writing directions.

735 rules
740 selectors
757 declarations
730 unique declarations
0 media queries
11 unique colors
32 unique background colors
15 unique font sizes
7 unique z-indices

https://t.co/w7oNG5KUkJ
The legacy site's CSS is what happens when hundreds of people directly write CSS over many years. Specificity wars, redundancy, a house of cards that can't be fixed. The result is extremely inefficient and error-prone styling that punishes users and developers.
The PWA's CSS is generated on-demand by a JS framework that manages styles and outputs "atomic CSS". The framework can enforce strict constraints and perform optimisations, which is why the CSS is so much smaller and safer. Style conflicts and unbounded CSS growth are avoided.
How does the PWA do responsive design with 0 media queries? Modern responsive design is about conditionally rendering entire component trees, and making components adapt to their own dimensions. You need to use 'ResizeObserver' for that. Media queries in CSS aren't good enough.
In fact, putting state in CSS (:hover, @media, etc) is as much of a problem for dynamic web apps as putting state in the DOM. Removing state from style definitions simplifies coordinating changes to trees & styles, and opens the door to more native-feeling interactions.
The Twitter PWA is a good example of how a huge, highly dynamic app benefits from a simpler "styles in JavaScript" paradigm (powered by a subset of CSS) that is significantly more effective and reliable than working directly with CSS or CSS-in-JS.

Most Liked Replies

Dario Gieselaar:
I assume conditionally rendering trees only work in non-SSR environments?
zen:
Most interesting point raised right here!

ResizeObserver clearly seems the future, I hope we see more implementations and browsers making it rock solid - though it does seem likely now that JS will play that major role.
Sophie Alpert:
Why does every discussion like this omit the cost of referring to the styles in JS? The code indicating what element gets what styles might be smaller than before, but it’s gotta end up *somewhere*.
#tom:
Hi! I've got it in my mind to convince https://t.co/EV0xnTjEoO to move to CSS-in-JS. Good to see examples & stats - ta :)
Jacob 'KurtXTRM' Groß:
Can you elaborate on this? Would you rather style elements through a JS event than using :hover?
Aditya Agarwal:
Hi Nicolas, I'd like to know more of how you are doing this. Looks like a great solution

 

More than 20 Brazilian universities were invaded by the military police in the past 2 days. They confiscated material on the history of fascism, interrupted classes due to 'ideological content', removed anti-fascist banners and posters claiming that it was electoral propaganda.


In the state of Rio, the court ordered the UFF faculty to remove from the Law School facade a flag with the message "UFF Law Against Fascism". The judge even determined the arrest of the director unless the flag was removed within 12 hours.

UERJ also reported police forces removing flags in support of Marielle Franco and another one that reads "Anti-fascism UERJ". In Rio Grande do Sul, an event entitled "Against fascism, Pro Democracy" was also prohibited by the electoral court.

In Mato Grosso do Sul, a public class entitled "Crushing Fascism" was also censored. In Pará, a lecture was interrupted by the military police that questioned the professor about the ideological content of the class and threatened to arrest him.

Many other student movements and organizations reported military police forces inside classrooms, student units, academic directories, confiscating any sort of materials with 'anti-fascist' or 'pro-democracy' content.


Parece muito abstrato o conceito de RESISTÊNCIA. Então, nessa thread vou listar iniciativas que tornam essa resistência concreta. Você pode participar, compartilhar, ajudar, pedir ajuda, doar, RESISTIR.
(Se tiver sugestões me avisa que vou incluindo!)
RT, pfv!

https://t.co/dUEKMKG23o
Várias organizações se juntaram pra e tocar essa campanha imensa de financiamento coletivo pra apoiar grupos que acolhem pessoas que sofrem violência, intolerância, racismo, homofobia, transfobia e todo tipo de preconceito. #NiguémFicaPraTrás!

https://t.co/IrI9UR8lUz
https://t.co/6gT7u9QNMN
A ACODE é um grupo que usa o inbox do Facebook e do Instagram pra responder aos casos de violência política no Brasil. Participam da iniciativa: @AllOut, @defemde, Casa1, DIVAM, @conectas e ativistas do Brasil todo.


A @AllOut está se preparando pra lançar a All Out Brasil pra intensificar a luta por direitos, dignidade e segurança para todas as pessoas LGBT+ do Brasil. https://t.co/EJ0n2PmBKx


Tive que quebrar a thread.
Ela continua aqui:

Original Tweet