Skip to content

fix: badge label with empty string should not occupy width#1095

Merged
danielroe merged 1 commit intonpmx-dev:mainfrom
btea:fix/badge-empty-label
Feb 6, 2026
Merged

fix: badge label with empty string should not occupy width#1095
danielroe merged 1 commit intonpmx-dev:mainfrom
btea:fix/badge-empty-label

Conversation

@btea
Copy link
Contributor

@btea btea commented Feb 6, 2026

The left side is not rendered when the label result is an empty string.

@vercel
Copy link

vercel bot commented Feb 6, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
npmx.dev Ready Ready Preview, Comment Feb 6, 2026 2:15pm
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
docs.npmx.dev Ignored Ignored Preview Feb 6, 2026 2:15pm
npmx-lunaria Ignored Ignored Feb 6, 2026 2:15pm

Request Review

@codecov
Copy link

codecov bot commented Feb 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 6, 2026

📝 Walkthrough

Walkthrough

The pull request modifies the SVG badge generation logic to adjust how the left segment width is calculated. When the label text (finalLabel) is empty after trimming, the leftWidth is set to 0 instead of using the measured text width. This change prevents the SVG badge from rendering an unnecessary left segment when no label is present, affecting the overall badge composition and width calculations.

🚥 Pre-merge checks | ✅ 1
✅ Passed checks (1 passed)
Check name Status Explanation
Description check ✅ Passed The pull request description directly addresses the changeset: it explains that the left side should not be rendered when the label is empty, which aligns with the code change adjusting leftWidth calculation.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 | 🟡 Minor

The 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, userLabel will be "". Because "" is falsy, line 286's ternary (userLabel ? userLabel : ...) falls through to the default strategy label, so finalLabel never 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 distinguishing undefined (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.label

This way ?label= yields an empty finalLabel, and the line 295 guard correctly sets leftWidth to 0.

🧹 Nitpick comments (1)
server/api/registry/badge/[type]/[...pkg].get.ts (1)

303-316: When leftWidth is 0 the aria-label still 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}">

@danielroe danielroe added this pull request to the merge queue Feb 6, 2026
Merged via the queue into npmx-dev:main with commit 6bbbd85 Feb 6, 2026
18 checks passed
@btea btea deleted the fix/badge-empty-label branch February 6, 2026 23:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants