Nicheloom visits: 58,069 all-time · 7,637 in the last 7 days

The opportunity tracker for new startups.

Today: 1,953 launches · Niche of the day: specialized calculation tools · See what launched today →

React hooks that predict text height before render, using font metrics

Get picks like this daily. Today's launch numbers, the top launches, AI and tech news, and a daily opportunity pick, straight to your inbox.

Want to reach these readers? Sponsor an issue.

I built @pretext-studio/core to solve a specific annoyance: the browser won't tell you how tall a text block is until after it renders. This forces you into either a render-then-measure cycle (which causes layout shift) or hacks like max-height: 9999px for accordion animations (which makes easing look wrong because the animation runs over 9999px, not the actual content height).The library wraps @chenglou/pretext, a pure-JS text layout engine that replicates the browser's line-breaking. algorithm using font metrics loaded once via the Font Metrics API. From there, computing height is arithmetic — no DOM, no getBoundingClientRect, no reflow. A prepare() call runs in ~0.03ms; a layout() call in under 0.01ms. Results are cached in a module-level LRU map so repeated calls for the same font/size pair are nearly free.The main hooks are useTextLayout (height + line count for a block at a given width), useBubbleMetrics (finds the tightest width that preserves line count, which eliminates the dead space you get from CSS fit-content), and useStableList (pre-computes heights for a list of items before paint, useful for virtualized lists and masonry layouts). There's also a MeasuredText drop-in component with a debug overlay that draws predicted line boundaries over actual rendered text so you can see where predictions diverge.The honest limitation: it only works with fonts you can load metrics for, so arbitrary system fonts or poorly-behaved variable fonts may drift. The isReady flag on every hook is false until font metrics load, so you need to gate renders on it when using web fonts. It also doesn't handle white-space: pre-wrap yet. Feedback welcome — especially if you've hit edge cases with font loading or non-Latin scripts.GitHub: https://github.com/ahmadparizaad/pretext-studio-core — npm: @pretext-studio/core

HN · launched Apr 4, 2026 · 8 upvotes (top 52%) · 0 views

Niche: ui component libraries · 312 launches, 18 in the last 7 days ▼ -38% · Explore this niche →

Category and tags

  • Horizontal
  • Dev tools
  • Developer
  • Not AI
  • Hobby / open-source project

Source listing ↗

Could you build this?

Yes Predicting text layout using font metrics (e.g. opentype.js or the Canvas API measureText method) within a React hook is a well-defined JavaScript utility library.

Discussion

2 comments analyzed.

Competitors mentioned: useLayoutEffect

Concerns raised: Browser compatibility and quirks across different browsers

Competitors

Other products that read as similar to this one : 180 launches clear the similarity bar, closest 8 shown.

Attention rank: #81 of 181 (itself plus its competitors, highest first, normalized so YC and Product Hunt are compared fairly).

Launched 140 days after the earliest competitor.

  • Font Size Converter · ph · 2026-10-31 · 2 upvotes · similarity 0.45
  • Docx-to-Markdown · hn · 2026-09-16 · 5 upvotes · similarity 0.44
  • Axisize · ph · 2026-10-06 · 9 upvotes · similarity 0.44
  • FontMeter · ph · 2026-10-24 · 6 upvotes · similarity 0.43
  • seal · github · 2026-10-16 · 10 upvotes · similarity 0.43
  • LocaleStress · ph · 2026-11-12 · 1 upvotes · similarity 0.42
  • Lobster.js · hn · 2026-03-08 · 7 upvotes · similarity 0.42
  • TypoSwap · ph · 2026-09-19 · 1 upvotes · similarity 0.41

The niche, labels, vibe code rating and competitor comparison on this page are analysis by Nicheloom. If you use them, please credit nicheloom.com. How you may use our data.