Skip to content

fix: use varying widths for compare bar chart skeleton loaders#2209

Open
thealxlabs wants to merge 3 commits intonpmx-dev:mainfrom
thealxlabs:fix/bar-chart-skeleton-widths
Open

fix: use varying widths for compare bar chart skeleton loaders#2209
thealxlabs wants to merge 3 commits intonpmx-dev:mainfrom
thealxlabs:fix/bar-chart-skeleton-widths

Conversation

@thealxlabs
Copy link

🔗 Linked issue

resolves #2106

🧭 Context

The compare page FacetBarChart skeleton loaders showed all bars at the same fixed width, giving an unrealistic loading placeholder. Real bar charts show bars of varying widths corresponding to different values.

📚 Description

Updated the skeleton loader in Compare/FacetBarChart.vue to compute per-bar widths using width: ${40 + (i * 17) % 40}% so adjacent bars have different lengths, producing a more realistic loading state. Also added aria-hidden="true" to skeleton containers and updated the heading/subtitle skeletons to more realistic widths.

A regression test (test/nuxt/components/compare/FacetBarChart.spec.ts) verifies that the width formula produces different values across packages and that all widths stay within the expected 40–79% range.

@vercel
Copy link

vercel bot commented Mar 22, 2026

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

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

Request Review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 22, 2026

📝 Walkthrough

Walkthrough

The PR updates the FacetBarChart.vue component's skeleton loading state with improved layout styling, adjusting margins, adding rounded corners, and implementing computed width values for skeleton bars. A new test suite is added to validate the skeleton rendering, including verifying that skeleton widths vary per package within expected bounds and that one row renders per package.

Possibly related PRs

Suggested labels

front, needs review

Suggested reviewers

  • alexdln
  • danielroe
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed The PR description is directly related to the changeset, explaining the skeleton loader improvements and width formula adjustments to the FacetBarChart component.
Linked Issues check ✅ Passed The PR addresses issue #2106 by implementing varying skeleton widths (via formula 40 + (i * 17) % 40), adjusting heading/subtitle skeleton dimensions, adding aria-hidden attributes, and including regression tests to verify the changes.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the FacetBarChart skeleton loader improvements and corresponding test coverage; no unrelated modifications were introduced.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

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: 2

🧹 Nitpick comments (1)
app/components/Compare/FacetBarChart.vue (1)

336-336: Extract the width formula to a shared helper to avoid drift.

The same inline formula appears in two places (Line 336 and Line 352). Keeping it in one helper will prevent accidental divergence between fallback branches.

♻️ Proposed refactor
<script setup lang="ts">
+const skeletonBarBaseWidth = 40
+const skeletonBarStep = 17
+const skeletonBarRange = 40
+
+function getSkeletonBarWidth(index: number): string {
+  return `${skeletonBarBaseWidth + ((index * skeletonBarStep) % skeletonBarRange)}%`
+}
</script>
-<SkeletonInline class="h-3 shrink-0" :style="{ width: `${40 + ((i * 17) % 40)}%` }" />
+<SkeletonInline class="h-3 shrink-0" :style="{ width: getSkeletonBarWidth(i) }" />

Also applies to: 352-352


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7610e178-e7ce-436b-846a-30a42384f02a

📥 Commits

Reviewing files that changed from the base of the PR and between 7f2fc1a and 06909d3.

📒 Files selected for processing (2)
  • app/components/Compare/FacetBarChart.vue
  • test/nuxt/components/compare/FacetBarChart.spec.ts

Comment on lines +30 to +39
it('skeleton bar label widths vary across packages (not all the same)', () => {
// The formula used is: width = `${40 + (i * 17) % 40}%`
// For 3 packages: i=0 -> 40%, i=1 -> 57%, i=2 -> 74%
const packages = ['react', 'vue', 'svelte']
const widths = packages.map((_, i) => `${40 + ((i * 17) % 40)}%`)

// Verify they are not all the same (the bug was all bars had the same width)
const uniqueWidths = new Set(widths)
expect(uniqueWidths.size).toBeGreaterThan(1)
})
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Regression test is detached from the component output.

Line 30 to Line 48 currently re-tests arithmetic in the spec itself, so it can still pass if the template no longer applies those widths. Please assert widths from rendered skeleton DOM/styles instead.

✅ Proposed test rewrite (DOM-coupled)
-  it('skeleton bar label widths vary across packages (not all the same)', () => {
-    // The formula used is: width = `${40 + (i * 17) % 40}%`
-    // For 3 packages: i=0 -> 40%, i=1 -> 57%, i=2 -> 74%
-    const packages = ['react', 'vue', 'svelte']
-    const widths = packages.map((_, i) => `${40 + ((i * 17) % 40)}%`)
-
-    // Verify they are not all the same (the bug was all bars had the same width)
-    const uniqueWidths = new Set(widths)
-    expect(uniqueWidths.size).toBeGreaterThan(1)
-  })
-
-  it('skeleton width formula produces values within 40-80% range', () => {
-    const indices = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
-    for (const i of indices) {
-      const width = 40 + ((i * 17) % 40)
-      expect(width).toBeGreaterThanOrEqual(40)
-      expect(width).toBeLessThan(80)
-    }
-  })
+  it('renders varying skeleton label widths within 40–79% for package rows', async () => {
+    const wrapper = await mountSuspended(FacetBarChart, { props: baseProps })
+    const rows = wrapper.findAll('div.flex.items-center.gap-3')
+    const widths = rows.map((row) => {
+      const style = row.find('span.h-3.shrink-0').attributes('style') || ''
+      const match = style.match(/width:\s*(\d+(?:\.\d+)?)%/)
+      return Number(match?.[1])
+    })
+
+    expect(new Set(widths).size).toBeGreaterThan(1)
+    for (const width of widths) {
+      expect(Number.isFinite(width)).toBe(true)
+      expect(width).toBeGreaterThanOrEqual(40)
+      expect(width).toBeLessThan(80)
+    }
+  })

As per coding guidelines, "Write unit tests for core functionality using vitest."

Also applies to: 41-48

Comment on lines +62 to +64
const rowMatches = html.match(/flex items-center gap-3/g)
expect(rowMatches).not.toBeNull()
})
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Assert exact row count, not only presence.

Line 63 only checks that at least one match exists. To verify “one row per package”, assert the exact number of rendered rows.

🎯 Tightened assertion
-    const rowMatches = html.match(/flex items-center gap-3/g)
-    expect(rowMatches).not.toBeNull()
+    const rowMatches = html.match(/flex items-center gap-3/g) ?? []
+    expect(rowMatches).toHaveLength(3)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const rowMatches = html.match(/flex items-center gap-3/g)
expect(rowMatches).not.toBeNull()
})
const rowMatches = html.match(/flex items-center gap-3/g) ?? []
expect(rowMatches).toHaveLength(3)
})

@codecov
Copy link

codecov bot commented Mar 22, 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!

Copy link
Contributor

@ghostdevv ghostdevv left a comment

Choose a reason for hiding this comment

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

Could you take a look at the coderabbit suggestions, and also show maybe a screenshot of the before/after?

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.

Improve skeleton loaders in compare page bar charts

2 participants