fix: badge label with empty string should not occupy width#1095
fix: badge label with empty string should not occupy width#1095danielroe merged 1 commit intonpmx-dev:mainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
2 Skipped Deployments
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
📝 WalkthroughWalkthroughThe pull request modifies the SVG badge generation logic to adjust how the left segment width is calculated. When the label text ( 🚥 Pre-merge checks | ✅ 1✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
server/api/registry/badge/[type]/[...pkg].get.ts (1)
286-295:⚠️ Potential issue | 🟡 MinorThe fix on line 295 is correct but may be incomplete —
userLabel === ""is swallowed on line 286.When a user passes
?label=(empty string) to explicitly request no label,userLabelwill be"". Because""is falsy, line 286's ternary (userLabel ? userLabel : ...) falls through to the default strategy label, sofinalLabelnever becomes empty via that path.The guard on line 295 is a fine safety net for whitespace-only labels (e.g.
?label=%20), but if the intent is to let users opt out of the label entirely with?label=, consider distinguishingundefined(not provided) from""(explicitly empty) on line 286:Suggested approach
- const finalLabel = userLabel ? userLabel : showName ? packageName : strategyResult.label + const finalLabel = userLabel !== undefined ? userLabel : showName ? packageName : strategyResult.labelThis way
?label=yields an emptyfinalLabel, and the line 295 guard correctly setsleftWidthto 0.
🧹 Nitpick comments (1)
server/api/registry/badge/[type]/[...pkg].get.ts (1)
303-316: WhenleftWidthis 0 thearia-labelstill emits a leading colon separator.With an empty label,
aria-label="${finalLabel}: ${finalValue}"produces something like": 1.0.0". Consider conditionally omitting the label portion for better accessibility:Suggested approach
- <svg xmlns="http://www.w3.org/2000/svg" width="${totalWidth}" height="${height}" role="img" aria-label="${finalLabel}: ${finalValue}"> + <svg xmlns="http://www.w3.org/2000/svg" width="${totalWidth}" height="${height}" role="img" aria-label="${finalLabel ? `${finalLabel}: ` : ''}${finalValue}">
The left side is not rendered when the label result is an empty string.