For 30 years, we've been measuring text the same expensive way. Every React app. Every dashboard. Every UI you've shipped. When the browser needs to know where text ends, it calls getBoundingClientRect() — which halts everything, recalculates the entire page layout, and returns a number. That's layout reflow. It's costly, and we do it on every resize and every render. Meanwhile, magazines have flowed text around images for centuries. On the web? Not possible. The layout engine just doesn't work that way. A library called Pretext just changed that. The trick was canvas.measureText() — a Canvas API that's always been there. It measures text using the browser's own font engine, with zero DOM involvement. Nobody had built a full text layout engine on top of it. Pretext did. How it works: prepare() runs once — segments your text, measures glyph widths via canvas, caches everything. ~19ms for 500 texts. layout() is pure math over that cache. Zero DOM. ~0.09ms for 500 texts, every time after. The real unlock is layoutNextLine() — feed each line a different width as you go. Narrower beside an image. Full width below it. That's how magazine text wrapping works. First time it's possible on the web. What you can now build: → Text that wraps around floated images, line by line → Proper list virtualization — exact heights, no guessing → Multiline shrink-wrap — tightest container that fits your text → Render to DOM, Canvas, SVG, or WebGL Full language support — RTL, CJK, emojis, mixed-bidi, all handled. npm install @chenglou/pretext — Pure TypeScript. MIT. → https://lnkd.in/e_v6WBfE #webdev #javascript #typescript #frontend #opensource
Revolutionizing Text Layout with Pretext
More Relevant Posts
-
I got tired of building loading states. So I built a plugin to do it for me. 🤖⚡️ Every developer knows the drill: 1. Build a beautiful new UI feature. 2. Realize it looks broken while the data is fetching. 3. Spend 2 hours manually coding a "Skeleton" version of that same UI. 4. Realize you have to maintain TWO versions of the same layout forever. 🤦♂️ 5. Every time you change your UI, you have to remember to update the skeleton too I’m excited to share that I created AutoSkeleton — a zero-config engine that automatically mirrors your React and React Native layouts into beautiful shimmer placeholders. The Solution: AutoSkeleton introspects your real component tree and renders pixel-perfect placeholders that match your exact geometry (flexbox, margins, padding, and all). ✅ One API, Two Platforms: Works perfectly on both React (Web) and React Native. ✅ Zero Manual Markup: Just wrap your existing component and pass isLoading. ✅ Automatic Sync: If your UI changes, your skeleton updates automatically. ✅ Lightweight & Fast: Optimized for performance with smooth 60fps animations. Give it a star on GitHub or try it in your project: 📦 NPM: https://lnkd.in/gkjJDTvd npm install auto-skeleton-react-and-native Let’s make the "Loading..." spinner a thing of the past! 🥂 #ReactJS #ReactNative #WebDevelopment #MobileDevelopment #OpenSource #SoftwareEngineering #UXDesign #AutoSkeleton #JavaScript
To view or add a comment, sign in
-
-
My Next.js app's Lighthouse score went from 62 to 97. No paid tools. No infrastructure changes. Just 5 things I was doing wrong that most devs don't notice. Mistake 1: Loading Google Fonts via a link tag. External font requests are render-blocking. My CLS was 0.28. Switched to next/font and it downloads fonts at build time, self-hosts them, and auto-calculates fallback font metrics so there's zero layout shift. CLS dropped to 0.02. LCP improved by 400ms. Mistake 2: No priority on my hero image. My largest above-the-fold image was lazy-loading by default. The browser downloaded it last instead of first. Added priority prop to next/image. LCP went from 4.2s to 1.9s. One prop. 55% improvement. Mistake 3: Wrapping entire pages in 'use client'. I had 'use client' at the top of my page component because one button needed onClick. The entire page shipped as client JavaScript. I moved 'use client' to just the button component. JS bundle dropped 62%. Mistake 4: Barrel exports killing tree-shaking. export { Button } from './Button' in an index.ts file. Looks clean. But the bundler pulls in every component from that barrel file. Removed it, used direct imports. First Load JS went from 1.5MB to 200KB. Mistake 5: Testing Lighthouse in dev mode. Dev mode injects HMR code and error overlays. My dev score was 62. Production was 85 before any fixes. Always run next build && next start before measuring. After all 5 fixes: 62 to 97. Same server. Run Lighthouse on your site right now. What score did you get? #NextJS #WebPerformance #React #JavaScript #WebDev
To view or add a comment, sign in
-
We often focus on frameworks like React, but sometimes it’s good to look at how the browser actually works under the hood. I wrote a short post about the Browser Rendering Pipeline, the journey from HTML/CSS code to the pixels we see on our screens. It covers: - DOM & CSSOM: Building the structure. - Layout: Calculating positions. - Paint & Composite: Final drawing and layers. These concepts will help you understand why some web pages feel faster than others. If you're curious about the fundamentals, I’d love for you to check it out. Read more here: https://lnkd.in/dyRtAbMd #webdev #frontend #learning #javascript
To view or add a comment, sign in
-
**Next.js 15 Server Components — the end of client-side rendering?** Not quite. But it *does* feel like a major shift in how we build for the web. For years, frontend development leaned heavily on client-side rendering: - ship more JavaScript - fetch data in the browser - hydrate everything - hope performance holds up With **Server Components in Next.js 15**, the default mindset is changing: ✅ Fetch data on the server ✅ Keep sensitive logic off the client ✅ Send less JavaScript to the browser ✅ Improve performance and initial load times That’s a big deal. But let’s be clear: **client-side rendering isn’t dead**. We still need client components for: - interactivity - local state - animations - browser-only APIs - rich UI experiences What’s really happening is this: **We’re getting better boundaries.** Instead of treating the entire app like it needs to run in the browser, we can now choose: - **Server Components** for data-heavy, static, and secure parts - **Client Components** for interactive UX That means better performance *and* cleaner architecture. The real question isn’t **“Is this the end of client-side rendering?”** It’s: **“Why were we rendering so much on the client in the first place?”** Next.js 15 doesn’t kill CSR. It makes it **intentional**. And that’s probably the bigger evolution. #nextjs #react #webdevelopment #javascript #frontend #performance #servercomponents #fullstack #WebDevelopment #TypeScript #Frontend #JavaScript
To view or add a comment, sign in
-
-
#Task 29 – Random Generator App Today, I built a Random Generator Web App using HTML, CSS, and JavaScript. In this project, I focused on creating a fun and interactive UI that generates random colors and images dynamically using JavaScript. Key Features of the Project • 🎨 Random Color Generator on button click • 🖼 Random Image Generator using API (Picsum) • Smooth image transition effect • Clean UI with gradient background • Responsive card-based layout What I Learned (Main Focus) This project helped me improve my understanding of: • JavaScript DOM manipulation • Math.random() for random selection • Handling arrays and dynamic values • Working with images dynamically • Using setTimeout() for smooth effects Challenge I faced While building this project, I faced challenges in generating truly random outputs and updating UI smoothly without glitches. How I solved it I solved these issues by using random logic with arrays, proper DOM updates, and timing functions to create smooth transitions and dynamic changes. This project helped me build a strong understanding of JavaScript interactivity and creative UI development. Code Of School – Ritendra Gour || Avinash Gour #WebDevelopment #WebDeveloper #FrontendDeveloper #DeveloperIndia #CodingLife #HTML #CSS #JavaScript #DOM #WebDesign #UIDesign #UIUXDesign #FrontendProject #PortfolioProject #TechCreative #FrontendDevelopment #WebDevLife
To view or add a comment, sign in
-
🚀 Next.js Linking & Navigation Navigation in Next.js is faster, cleaner, and built for performance ⚡ Let’s break it down 👇 🧩 1. Basic Navigation (Using Link) 👉 Use <Link> for moving between pages import Link from "next/link"; export default function Home() { return ( <Link href="/about">Go to About</Link> ); } 💡 Why use it? ✔ Client-side navigation ✔ No full page reload ✔ Faster transitions 🔁 2. Programmatic Navigation (useRouter) 👉 Navigate using functions (button click, events) "use client"; import { useRouter } from "next/navigation"; export default function Page() { const router = useRouter(); return ( <button onClick={() => router.push("/about")}> Go to About </button> ); } 💡 Use when: ✔ On button click ✔ After form submission ✔ Conditional navigation ⚡ Key Advantages ✔ Client-side routing (SPA feel) ✔ Automatic prefetching ✔ Fast page transitions ✔ Better user experience 🧠 Simple Way to Remember • <Link>→ For UI navigation • useRouter() → For logic-based navigation 🔥 Modern apps rely heavily on smooth navigation — and Next.js makes it effortless. 💬 Which one do you use more — Link or Router? #NextJS #React #Frontend #WebDevelopment #JavaScript #Coding #SoftwareEngineering
To view or add a comment, sign in
-
-
🎨 My Frontend & Design Stack These are the technologies I use to build everything you see on screen. The visual layer, the interactions, and the structure of every app I create. 🌐 HTML5 — The skeleton of every webpage. Semantic structure that makes sites accessible and SEO-friendly. 🎨 CSS3 — The styling engine. Controls layout, spacing, colors and animations to make UIs look polished. ⚡ JavaScript — The brain of every interactive experience. Logic, events, and dynamic content. 🔷 TypeScript — JavaScript with strong typing. Catches bugs early and makes code more reliable. ⚛️ React.js — My core UI library. Reusable components and state management on every frontend I build. ▲ Next.js — The full-stack React framework. Fast, SEO-friendly, and production-ready out of the box. 💨 Tailwind CSS — Utility-first styling I use on every single project. Clean, fast and fully responsive. 🎬 Framer Motion — Smooth animations and micro-interactions that make UIs feel alive. Which of these do you use? Drop it below 👇 #MansurbCodes #Frontend #WebDevelopment #ReactJS #NextJS #JavaScript #TypeScript #TailwindCSS #FramerMotion #WebDesign #PakistaniDeveloper #Coding #LearnToCode
To view or add a comment, sign in
-
-
🌙 Your users' eyes will thank you. Here's how to build a dark mode toggle with pure CSS — no JavaScript needed. Dark mode isn't just a trend. It reduces eye strain, saves battery on OLED screens, and makes your UI feel polished and modern. And the best part? You don't need a single line of JavaScript to pull it off. Here's everything you need to know 👇 ✅ CSS Custom Properties are the foundation Define all your colors as --variables under :root, then override them inside [data-theme="dark"]. One attribute flip changes your entire UI instantly. ✅ The Checkbox Hack — pure CSS toggle A hidden input type="checkbox" combined with the :checked pseudo-class lets you switch themes with zero JavaScript. Clean, lightweight, effective. ✅ Respect the OS preference automatically Use @media (prefers-color-scheme: dark) to detect the user's system setting and apply dark styles before they even touch your toggle. ✅ Smooth transitions = professional feel Add transition: background 0.3s, color 0.3s on the body element. No jarring flashes — just butter-smooth theme switching. ✅ Persist the user's choice Save their preference to localStorage and restore it on page load. Nobody wants to re-toggle every single visit. ✅ Never skip accessibility Add aria-label="Toggle dark mode" and update aria-checked dynamically. Build for everyone, not just mouse users. The tech stack? Just HTML + CSS. That's it. Save this post for your next project 🔖 Drop a 🌙 in the comments if you've already shipped dark mode — or tag a developer who needs to see this! #CSS #WebDevelopment #FrontendDevelopment #DarkMode #HTMLandCSS #WebDesign #CSSVariables #UIDesign #100DaysOfCode #CodeNewbie #Programming #JavaScript #Frontend #DevTips #TechCommunity
To view or add a comment, sign in
-
-
I just published my npm package: @vishal4500/rich-text-editor While working on real-world projects, I often needed a powerful yet customizable rich text editor that works smoothly with React and Next.js—so I built one. Key highlights: • Built with React + Tiptap • Full formatting toolbar (fonts, colors, alignment, lists, tables) • Resizable images + link support • Outputs both HTML & JSON • SSR-safe (works with Next.js without hydration issues) • Scoped styling (no conflicts with your design system) • TypeScript support (ESM + CJS) Easy to use: npm install @vishal4500/rich-text-editor This package is designed to be plug-and-play, but also flexible enough for complex applications. Would really appreciate your feedback or suggestions 🙌 If you're building something with React, feel free to try it out. #reactjs #javascript #webdevelopment #frontend #opensource #npm #nextjs #typescript #tiptap #richtexteditor #ui #ux #softwareengineering #webdev #developers
To view or add a comment, sign in
-
Hi eveyone , After a few weeks of iteration, I'm excited to share my new developer portfolio: a single-page experience that's fast, animated, and intentionally a little extra. ✨ 🧱 The Stack Next.js 16.2 (App Router) + React 19 TypeScript end-to-end Tailwind CSS v4 for styling GSAP for scroll-triggered animations OGL for lightweight WebGL effects next-themes for seamless dark/light theming Sonner for toast notifications 🗂️ The Architecture I went with a feature-first folder structure instead of cramming everything into a generic components/ pile: src/ ├── app/ → Next.js App Router entry ├── features/ → Self-contained sections │ ├── hero/ │ ├── about/ │ ├── skills/ │ ├── projects/ → Custom carousel view │ ├── experience/ │ └── contact/ ├── components/ → Shared UI (Navbar, Cursor, etc.) ├── hooks/ → useGSAP, useScrollSpy └── lib/ → GSAP setup Each feature owns its own data and components — easy to maintain, easy to scale. 🎨 What I Built Animated liquid background — hand-crafted blob shader that adapts to theme Custom cursor that reacts to interactive elements Scroll spy navigation with smooth GSAP transitions Project carousel for showcasing work Theme toggle with persisted preference Section-by-section reveal animations powered by GSAP's ScrollTrigger Fully responsive and accessible 💡 Lessons learned Working with Next.js 16 + React 19 RSC required rethinking where state lives. Animation logic stays on the client, but content stays server-rendered for performance and SEO. The result: heavy visuals without the heavy load. Always shipping. Always learning. This the link of the portfolio, take a look and tell my your feedback 👀 : https://lnkd.in/d-c-YQJC #WebDevelopment #NextJS #React #TypeScript #FrontendDevelopment #GSAP #TailwindCSS #PortfolioProject
To view or add a comment, sign in
More from this author
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development