Pretext JS: The DOM is Officially a Bottleneck
Cheng Lou just dropped Pretext, a library challenging how browsers have handled text layout and measurement for the past 30 years.
Headline: The DOM is officially a bottleneck. 馃く
Cheng Lou (former React core team) just dropped Pretext, and it is challenging how browsers have handled text layout for the past 30 years.
For decades, figuring out how much space a paragraph occupies meant rendering it in the browser and measuring it. This triggers layout reflows (using tools like getBoundingClientRect), which is one of the most expensive and thread-blocking operations in web development.
Enter Pretext: A pure JavaScript/TypeScript library that handles multiline text measurement without touching the DOM.
Here is why it is so powerful:
- Instead of relying on CSS rendering, it uses an off-screen Canvas and a clever two-phase API (
prepare()andlayout()) to pre-calculate word sizes using pure arithmetic. - The layout operations run in roughly 0.09ms.
- It natively supports platform-specific emojis, complex text directions (RTL), and different languages.
- It enables previously impossible UI effects, like text fluidly wrapping around moving, draggable obstacles in real-time.
The project rocketed past 10,000 GitHub stars in just days because it solves a massive performance hurdle for the next generation of spatial and interactive UIs.
Are we witnessing the start of developers bypassing CSS entirely for complex layouts? 馃憞
#WebDevelopment #JavaScript #TypeScript #Frontend #SoftwareEngineering #TechNews #UIUX