An engineer just tackled a UI problem we’ve been struggling with for 30+ years. Text layout. Every time a web app needs to know: “How big is this text?” It asks the browser. And the browser: • pauses execution • recalculates layout (reflow) • then returns the measurement That means it’s not just measuring text it’s recalculating the entire page. This is one of the biggest reasons behind janky scrolling and unstable UI. ⸻ Now here’s the interesting part. Pretext.js takes a completely different approach. How it works Instead of asking the DOM, it computes layout independently. 1. Uses Canvas (measureText) • Gets accurate text metrics without triggering layout 2. Splits text into segments • Handles proper word boundaries 3. Measures once and caches 4. Computes layout using pure math • line breaks • wrapping • total height No DOM reads. No reflow. No blocking. ⸻ Why this matters • Predict layout before rendering • Eliminate layout thrashing • Smooth chat apps, feeds, and virtualized lists • Better performance at scale ⸻ Reality check • Not full CSS parity yet • Requires proper font handling • Minor differences vs actual DOM rendering But the direction is important. ⸻ Takeaway We’ve been asking the browser for layout. This shows we can compute it ourselves. —— GitHub https://lnkd.in/dx7eQnUw Demo credits • Work by Cheng Lou #javascript #frontend #webdevelopment #reactjs #performance #softwareengineering #webperf #uilayout
More Relevant Posts
-
Still just throwing a basic <img> tag into your code and calling it a day? If you are building modern, minimal web applications, relying solely on the standard <img> tag is a quick way to ruin your frontend performance and user experience. It’s time to level up to the <picture> element. Here is why wrapping your <img> inside a <picture> tag is a massive architectural upgrade for your frontend: 🚀 Next-Gen Formats on the Fly Instead of forcing every browser to download a heavy JPEG, the <picture> tag lets you offer .avif or .webp formats first. If a user is on an older browser that doesn't support them, it gracefully falls back to the standard <img> inside. You save massive amounts of bandwidth. 📱 True Art Direction Using CSS to scale a single desktop image down for mobile often results in a zoomed-out, unreadable mess. The <picture> element lets you use media queries to serve a completely different, tightly cropped image for mobile screens. Your UI stays crisp and intentional on every device. 📉 Crushing CLS (Cumulative Layout Shift) Ever visit a site, go to click a button, and the whole page jumps because an image finally loaded? That is terrible CLS. By defining specific <source> tags for different viewports, the browser knows exactly which image to fetch and reserves the perfect amount of space before it even loads. No more jumping content. The mental model is simple: You use <picture> as the wrapper, add your optimized <source> tags at the top, and put your classic <img> tag at the bottom as the reliable fallback. It takes a few extra lines of HTML, but the boost to your Core Web Vitals and perceived load speed is incredibly worth it. Do you write custom <picture> elements in your codebase, or do you rely on framework components (like Next.js <Image />) to handle the heavy lifting for you? Let’s discuss below! 👇 #43of21DayDevChallenge #21DayDevChallenge #WebDevelopment #Frontend #UIUX #WebPerformance #ReactJS #SoftwareEngineering #CleanCode #TechTips
To view or add a comment, sign in
-
-
🚨 Every time you measure text in the browser… you might be slowing your app down. Yes — rendering text efficiently on the web is still a surprisingly hard problem. I recently came across an incredible library called Pretext by Cheng Lou, and it completely changed how I think about frontend performance. 💥 The problem: Every time we measure text in the browser (like height, wrapping, layout), we rely on DOM APIs like: 👉 getBoundingClientRect() 👉 offsetHeight These trigger layout reflows — one of the most expensive operations in web performance. And the worst part? We often do this repeatedly… without realizing the cost. ⚡ The solution (and why it’s genius): Instead of relying on the DOM, Pretext builds its own text layout engine — purely in JavaScript. ✔️ Measures text using the browser’s font engine (via canvas) ✔️ Precomputes and caches text structure ✔️ Uses pure arithmetic for layout (no reflow!) ✔️ Supports multiple languages, emojis, and complex scripts As described in the repo, it “side-steps the need for DOM measurements… and avoids layout reflow entirely.” 🤯 Why this is fascinating: This unlocks things that were previously messy or unreliable: • Accurate text measurement without touching the DOM • Smooth virtualization (no guessing heights) • Custom layouts like masonry, dynamic flows, canvas rendering • Preventing layout shifts before content even loads Basically — you can now treat text layout like a deterministic system, not a browser side-effect. 🧠 What I learned from this: The biggest innovations don’t always come from adding complexity… they come from rethinking the fundamentals. Instead of asking: “How do we optimize DOM measurements?” This project asks: 👉 “What if we didn’t need them at all?” ⚡ Why this matters going forward: With AI-driven UIs, dynamic content, and complex interfaces becoming the norm — we need predictable, fast, and controllable layout systems. And this feels like a step in that direction. 👇 I’ve dropped some mind-blowing demos in the comments — highly recommend checking them out. 💬 Question for you: Do you think frontend performance issues are more about bad tooling… or outdated mental models of how the browser works? #ApplicationDevelopment #JavaScript #FullStackEngineering #Performance #React #Engineering #OpenSource #TechInnovation #Programming #UI #SoftwareEngineering
To view or add a comment, sign in
-
📸 "𝗥𝗲𝘀𝗽𝗼𝗻𝘀𝗶𝘃𝗲 𝗶𝗺𝗮𝗴𝗲𝘀" 𝗺𝗶𝗴𝗵𝘁 𝗯𝗲 𝗴𝗼𝗶𝗻𝗴 𝗮𝘄𝗮𝘆. Not because they failed... but because we don't need them anymore. 🧠 𝗧𝗵𝗲 𝗼𝗹𝗱 𝘄𝗮𝘆 We used: 🔹 `srcset` 🔹 `sizes` 🔹 `<picture>` To guess which image a device needed. ⚠️ 𝗧𝗵𝗲 𝗽𝗿𝗼𝗯𝗹𝗲𝗺 🔹 Complex markup 🔹 Multiple image versions 🔹 Hard to maintain 👉 We were solving a platform problem manually. 🚀 𝗪𝗵𝗮𝘁'𝘀 𝗰𝗵𝗮𝗻𝗴𝗶𝗻𝗴 🔹 Modern CSS (container queries, fluid layouts) 🔹 Smarter browsers 🔹 Image CDNs 👉 The platform now knows: 🔹 How big your image is 🔹 What resolution is needed 🔹 What to load 🧩 𝗧𝗵𝗲 𝘀𝗵𝗶𝗳𝘁 From: "Optimize images for devices" ➡️ to: "Let layout + browser handle it" 🧠 The real insight: Frontend evolution always follows the same pattern: 👉 We hack solutions 👉 The platform catches up 👉 Complexity disappears 🚀 The takeaway: 👉 The code you don't have to write anymore. 🔗 Source: https://lnkd.in/dwWHWCcb #Frontend #WebDevelopment #CSS #WebPerformance #UX
To view or add a comment, sign in
-
-
Most React component libraries give you buttons and cards. We got tired of shipping the same 4 security primitives on top of every one of them. So we built them in. TekiVex UI v2.6 is on npm with something no other React library has: a SecurityCore kernel baked into every component. → sanitizeHref() on every link prop — blocks javascript: and data: URI XSS by default → sanitizeUnicode() on every text input — defeats homoglyph + bidi-override attacks (CVE-2021-42574) → scrubPII() hook — redacts emails, phones, SSNs, credit cards before they hit your logs → Built-in rate limiting, Trusted Types installer, frame-buster Plus: 69 components, all WCAG 2.1 AAA. Alongside it, four companion packages now live source-available in the repo (security-core as standalone, audit CLI, scaffolder, figma-kit). We publish them to npm on demand — the code is production-ready, we just don't speculatively add maintenance commitments. Everything is MIT licensed. We built this because "security is the app team's job" is how shipped products end up on Have I Been Pwned. What's the one security check you wish your component library did for you by default? 🔗 https://lnkd.in/gacehJUN 🔗 https://lnkd.in/gd9PuB6A #ReactJS #WebSecurity #OpenSource #FrontendDevelopment
To view or add a comment, sign in
-
A year ago I told someone: "Let's build the React library we wish existed." TekiVex UI v2.6 hit npm today — and I think we actually did it. What's in v2.6, installable right now: 🛡 SecurityCore — a security kernel baked into every component. URL sanitization, Unicode homoglyph defense, PII scrubbing, rate limiting, Trusted Types. Not a plugin. Not an add-on. Default behavior. ♿ 69 components, all WCAG 2.1 AAA — not "we support a11y," actually audited. 🧩 Zero runtime deps in the security kernel. Alongside 2.6, four companion packages are now source-available. https://lnkd.in/g97w74YR #ui #uideveloper #tekivex TEKIVEX Citi UBS LinkedIn Google Amazon Tesla #ux #uxdesign w3schools.com GeeksforGeeks GitHub
Most React component libraries give you buttons and cards. We got tired of shipping the same 4 security primitives on top of every one of them. So we built them in. TekiVex UI v2.6 is on npm with something no other React library has: a SecurityCore kernel baked into every component. → sanitizeHref() on every link prop — blocks javascript: and data: URI XSS by default → sanitizeUnicode() on every text input — defeats homoglyph + bidi-override attacks (CVE-2021-42574) → scrubPII() hook — redacts emails, phones, SSNs, credit cards before they hit your logs → Built-in rate limiting, Trusted Types installer, frame-buster Plus: 69 components, all WCAG 2.1 AAA. Alongside it, four companion packages now live source-available in the repo (security-core as standalone, audit CLI, scaffolder, figma-kit). We publish them to npm on demand — the code is production-ready, we just don't speculatively add maintenance commitments. Everything is MIT licensed. We built this because "security is the app team's job" is how shipped products end up on Have I Been Pwned. What's the one security check you wish your component library did for you by default? 🔗 https://lnkd.in/gacehJUN 🔗 https://lnkd.in/gd9PuB6A #ReactJS #WebSecurity #OpenSource #FrontendDevelopment
To view or add a comment, sign in
-
Came across this article that explains why premium UIs like Linear and Stripe feel different — and it comes down to one decision most devs never consciously make. They never use pure neutrals. Instead of #F8F8F8 → they use #F5F7FF (white + a trace of brand blue) Instead of black shadows → brand color at low opacity Instead of flat grey text → grey that leans warm or cool The brand color doesn't sit on top of the design. It runs through it. Small shift. Big difference in how "premium" a UI feels. #frontend #css #uidesign #webdevelopment
To view or add a comment, sign in
-
𝘂𝘀𝗲𝗘𝗳𝗳𝗲𝗰𝘁 𝘃𝘀 𝘂𝘀𝗲𝗟𝗮𝘆𝗼𝘂𝘁𝗘𝗳𝗳𝗲𝗰𝘁 𝗶𝗻 𝗥𝗲𝗮𝗰𝘁 — 𝗖𝗵𝗼𝗼𝘀𝗶𝗻𝗴 𝘁𝗵𝗲 𝗥𝗶𝗴𝗵𝘁 𝗛𝗼𝗼𝗸 𝗮𝘁 𝘁𝗵𝗲 𝗥𝗶𝗴𝗵𝘁 𝗧𝗶𝗺𝗲 React gives developers powerful hooks to manage side effects, but understanding when each hook runs can make a significant difference in UI performance and user experience. Two commonly misunderstood hooks are: 🔹 𝘂𝘀𝗲𝗘𝗳𝗳𝗲𝗰𝘁() useEffect runs after the browser has painted the UI. This makes it the right choice for: • API requests • Event listeners • Subscriptions • Logging • Updating external systems Because it runs after paint, it does not block rendering, helping keep your application fast and responsive. 🔹 𝘂𝘀𝗲𝗟𝗮𝘆𝗼𝘂𝘁𝗘𝗳𝗳𝗲𝗰𝘁() useLayoutEffect runs immediately after the DOM updates but before the browser paints the screen. This makes it useful for: • Reading element dimensions • Measuring layout • Scroll position adjustments • Preventing visual flicker • Synchronizing DOM changes before display Since it runs before paint, users never see intermediate layout changes. 𝗪𝗵𝘆 𝗶𝘁 𝗺𝗮𝘁𝘁𝗲𝗿𝘀 Using the wrong hook can lead to: ❌ Layout shifts ❌ Flickering UI ❌ Incorrect measurements ❌ Less predictable rendering behavior Choosing the correct hook leads to: ✅ Smoother interfaces ✅ Better visual stability ✅ More predictable components 𝗦𝗶𝗺𝗽𝗹𝗲 𝗿𝘂𝗹𝗲 𝗼𝗳 𝘁𝗵𝘂𝗺𝗯 Use useEffect → for most side effects Use useLayoutEffect → when layout or visual updates must happen before paint Small React details like this often separate working code from polished frontend engineering. #React #JavaScript #FrontendDevelopment #WebDevelopment #SoftwareEngineering
To view or add a comment, sign in
-
-
Getting back into a rhythm after a long break isn't always glamorous. You open VS Code, stare at a blank file, and just start, no perfect conditions, no grand plan. That's been my approach lately, and it's working. Project 4 is done. Here's what it is: https://lnkd.in/dSYzJWbg Product Card UI - Add to Cart App A fully functional product listing page with a cart sidebar, the kind of UI you see on real e-commerce sites, built from scratch in React. What it does: → Displays a product grid with images, ratings, and categories → Add to cart with live quantity controls (+/−) → Cart persists across page refreshes via localStorage → Calculates and updates total price in real time → Checkout flow with a success confirmation screen Tech used: → React (Vite) — component-based architecture → Tailwind CSS — custom design tokens, dark theme → localStorage — client-side cart persistence → Custom React Hook (useCart) — all cart logic isolated What I learned: → Lifting state up — keeping cart state in App.jsx and passing it down via props, rather than scattering state across components → Custom hooks — extracting cart logic into useCart.js keeps components clean and focused on UI only → Component architecture — each component has one job. ProductCard displays. Cart renders. useCart thinks. → localStorage sync with useEffect — reading on mount, writing on every state change This is Project 4 of my structured React learning path. Building in public. More coming. #React #JavaScript #TailwindCSS #Frontend #WebDevelopment #BuildInPublic #MERN #Fullstack #Developer
To view or add a comment, sign in
-
🚀 Your Next.js App is Fast… But Why Does It Still Feel Slow? 🤯 Most developers say: 👉 “We are using SSR, so performance is good.” But here’s the uncomfortable truth: ⚠️ Fast HTML ≠ Fast Experience Let’s break what really happens in the browser 👇 🎭 1. The Illusion of Speed Request → Server → HTML → Screen Boom 💥 content appears instantly. But… 👉 That UI is just a static snapshot 👉 It looks interactive, but it’s not 🧠 2. The Hidden Reality (Main Thread) Main Thread = JS + Layout + Paint + Events Only ONE task at a time If something heavy runs: for (let i = 0; i < 500000000; i++) {} 👉 UI freezes 👉 Clicks don’t work 👉 Nothing paints 🎨 3. How Your Page Actually Appears HTML → DOM CSS → CSSOM → Render Tree → Layout (Reflow) → Paint FCP = first pixels LCP = biggest element ⚡ 4. The Biggest Trap: Hydration <button>Like</button> Looks clickable? Nope. JS loads → React runs → Events attached This is Hydration Large apps = heavy hydration = blocked main thread 🐢 5. Why It Feels Laggy (Even with SSR) HTML arrives fast ✅ BUT main thread busy ❌ Result: 😤 Click delay 🐌 Scroll lag ⚠️ Poor INP 🎯 6. INP — Real UX Metric Click → Wait → JS → Paint If JS blocks: Click → waiting… → waiting… → response Bad INP 🧱 7. Silent Killers element.style.width = "500px" → Reflow ❌ element.style.color = "red" → Repaint ✅ Reflow = layout recalculation → expensive 💣 8. Real Production Problem Ads (GPT / APS / PWT) Analytics Trackers Heavy JS → Main thread blocked → UI delayed 🧩 9. Real Timeline Request ↓ TTFB ↓ HTML ↓ Paint (FCP) ↓ LCP ↓ JS execution ↓ Hydration ↓ User interaction ↓ INP 💡 Final Insight Users don’t care when HTML arrives They care when UI responds 🔥 If you understand this, you’re thinking like a performance engineer. #NextJS #WebPerformance #Frontend #ReactJS #CoreWebVitals #INP #LCP
To view or add a comment, sign in
-
Whether you're building a complex dashboard or a simple search bar, UI jank is the ultimate vibe-killer. If you've ever felt like your app was "stuttering" because a heavy UI update was fighting with user input, useDeferredValue is about to become your new best friend. Here’s the breakdown of why this hook is a game-changer for React performance. 🚀 💡 The Problem: Blocking the Main Thread Normally, React updates are urgent. If a user types into an input and that input triggers a massive re-render (like filtering a list of 10,000 items), the typing feels "laggy" because React is too busy rendering the list to handle the keystrokes. ✨ The Solution: useDeferredValue This hook allows you to mark a piece of state as non-urgent. It tells React: "Hey, keep the input feeling snappy. Update the heavy UI when you have a spare moment." 🛠️ How it works: 1. React updates the "urgent" state (the input text) immediately. 2. It then attempts to render the "deferred" value in the background. 3. If the user types again before the background render finishes, React interrupts the old render and starts over with the new value. ⚡ When to use it? Expensive Re-renders: When a part of your UI is slow to render and there's no way to further optimize the component itself. Search/Filtering: Keeping the search input responsive while the results list "catches up." Third-party integrations: When you're passing data to a library that you don't have performance control over. Pro-Tip: For the best UX, pair it with React.memo on the component receiving the deferred value. This ensures the component only re-renders when the deferred value actually changes! Have you made the switch from traditional debouncing to useDeferredValue yet? Let’s talk about it in the comments! 👇 #ReactJS #WebDevelopment #Frontend #JavaScript #CodingTips #React18 #SoftwareEngineering
To view or add a comment, sign in
-
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
Great insight 💯