fix: fix fallback not triggered for 0 measuredWidth#1584
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
2 Skipped Deployments
|
There was a problem hiding this comment.
Pull request overview
Updates badge SVG text measurement logic so the character-count fallback is triggered when the canvas text measurement returns 0, preventing badges from rendering with an incorrectly small width in that scenario.
Changes:
- Treat
measuredWidth === 0as an invalid measurement by requiringNumber.isFinite(measuredWidth) && measuredWidth > 0before using it.
| if (Number.isFinite(measuredWidth) && measuredWidth > 0) { | ||
| return Math.ceil(measuredWidth) |
There was a problem hiding this comment.
This change adjusts the fallback behavior when measureText() returns 0, but there’s no regression test covering the measuredWidth === 0 case (which is the bug being fixed). Consider adding a Vitest test that mocks @napi-rs/canvas (or getCanvasContext()) to return width: 0 for a non-empty string and asserts that the computed badge/text width uses the character-count fallback (i.e., grows beyond the minimum width for longer strings).
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
No actionable comments were generated in the recent review. 🎉 📝 WalkthroughWalkthroughThis PR modifies the validation logic in the Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ❌ 1❌ Failed checks (1 inconclusive)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. 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 |
Currently fallback does not work: https://npmx.dev/api/registry/badge/version/nuxt?label=thisisatest
with this PR, fallback still sucks but at least does not appear very broken:
https://npmxdev-git-improved-fallback-npmx.vercel.app/api/registry/badge/version/nuxt?label=thisisatest