fix: use lookup table for badges char widths when canvas not available#2487
fix: use lookup table for badges char widths when canvas not available#2487t128n wants to merge 2 commits intonpmx-dev:mainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
2 Skipped Deployments
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughSummary by CodeRabbit
WalkthroughReplaced heuristic character-width estimation using character sets and fallback width buckets with static per-character lookup tables ( Changes
Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
🔗 Linked issue
Resolves #1601
🧭 Context
In production, measuring text with canvas is crashing, resulting in inaccurate fallback measurements:
Introduced a character lookup table of "manually" measured character widths for more
accurate lookups.
📚 Description
Tweaked the
estimateTextWidthfunction to use a on-character level lookup table for more accurate results when the Canvas API from@napi-rs/canvasis unavailable.Lookup table derived from running
locally, where fonts and the API are available.
Using a generous fallback for characters that aren't in the map, such as emojis.
📷 Comparison
Overflow / Long Labels
Shields.io Style (
?style=shieldsio)Emojis
CJK Characters
Special & Punctuation Characters
iiiii)WWWWW)Badge Types Smoke Test
versionlicensedownloadssizetypesdeprecated