Skip to content

fix: 0 packages in user profile og image#3085

Open
WilhelmBerggren wants to merge 1 commit into
npmx-dev:mainfrom
WilhelmBerggren:wilhelm/userprofile-ogimage
Open

fix: 0 packages in user profile og image#3085
WilhelmBerggren wants to merge 1 commit into
npmx-dev:mainfrom
WilhelmBerggren:wilhelm/userprofile-ogimage

Conversation

@WilhelmBerggren

@WilhelmBerggren WilhelmBerggren commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

🔗 Linked issue

Resolves #2920

🧭 Context

The OG image for /~username was always showing package count as zero due to a data loading issue

📚 Description

Added a separate UserProfile.takumi.vue component to match the other OG images, instead of relying on a generic one. The cause of the bug was that data loading was happening non-blockingly, and the OG image returned a fallback number. I thought it was better to keep the ~[username]/index.vue component as is and define blocking data loading in this new component instead.

Before:
image

After:
image

@vercel

vercel Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

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

Project Deployment Actions Updated (UTC)
npmx.dev Ready Ready Preview, Comment Jul 26, 2026 1:45pm
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
docs.npmx.dev Ignored Ignored Preview Jul 26, 2026 1:45pm
npmx-lunaria Ignored Ignored Jul 26, 2026 1:45pm

Request Review

@coderabbitai

coderabbitai Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The user profile OG image accepts a username, resolves its package count through Algolia or the npm registry, handles lookup failures, and renders the result. The username profile route now uses this template, with tests covering lookup and rendering behaviour.

Changes

User profile OG image

Layer / File(s) Summary
OG route template wiring
app/pages/~[username]/index.vue
Switches the route to UserProfile.takumi and passes the resolved username.
Package count lookup and rendering
app/components/OgImage/UserProfile.takumi.vue, test/nuxt/components/OgImageUserProfile.spec.ts, test/unit/a11y-component-coverage.spec.ts
Adds username validation, Algolia and npm-registry lookups, fallback handling, pluralised package descriptions, conditional username rendering, related tests, and an explicit accessibility-coverage exclusion for the server-rendered OG image.

Sequence Diagram(s)

sequenceDiagram
  participant OGRequest
  participant UserProfileTakumi
  participant Algolia
  participant NPMRegistry
  OGRequest->>UserProfileTakumi: provide username
  UserProfileTakumi->>Algolia: query packages filtered by owner
  Algolia-->>UserProfileTakumi: return package count
  UserProfileTakumi->>NPMRegistry: query maintainer packages when Algolia is empty or fails
  NPMRegistry-->>UserProfileTakumi: return fallback package count
  UserProfileTakumi-->>OGRequest: render username and description
Loading

Suggested reviewers: ghostdevv

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR addresses the reported zero-package OG image by adding blocking data loading and fallback lookup for the user profile image.
Out of Scope Changes check ✅ Passed The added tests and accessibility skip support the OG image fix and do not appear unrelated to the issue.
Title check ✅ Passed The title clearly matches the main change: fixing the user profile OG image showing 0 packages.
Description check ✅ Passed The description is directly related to the change and explains the OG image fix and new component approach.
✨ 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.

@codecov

codecov Bot commented Jul 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 76.47059% with 4 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
app/components/OgImage/UserProfile.takumi.vue 76.47% 0 Missing and 4 partials ⚠️

📢 Thoughts on this report? Let us know!

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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)
test/nuxt/components/OgImageUserProfile.spec.ts (1)

21-26: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Keep the fallback mock type-safe.

Replace the any cast with typed mockResolvedValue / mockRejectedValue calls on the $fetch spy. As per coding guidelines, “Ensure you write strictly type-safe code”.

Proposed fix
 function mockNpmFallback(total: number | null) {
-  // eslint-disable-next-line `@typescript-eslint/no-explicit-any`
-  vi.spyOn(globalThis, '$fetch').mockImplementation((() =>
-    total === null ? Promise.reject(new Error('network')) : Promise.resolve({ total })) as any)
+  const fetchSpy = vi.spyOn(globalThis, '$fetch')
+  if (total === null)
+    fetchSpy.mockRejectedValue(new Error('network'))
+  else
+    fetchSpy.mockResolvedValue({ total })
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/nuxt/components/OgImageUserProfile.spec.ts` around lines 21 - 26, Update
mockNpmFallback to remove the explicit any cast and configure the global $fetch
spy using typed mockResolvedValue and mockRejectedValue calls. Preserve the
existing total-based behavior, resolving with the count object for non-null
totals and rejecting with the network error for null.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@app/components/OgImage/UserProfile.takumi.vue`:
- Around line 21-22: Update the Algolia error handling in
app/components/OgImage/UserProfile.takumi.vue around the outer catch so it
attempts the npm-registry lookup after an Algolia failure, using zero only when
that fallback also fails. Update test/nuxt/components/OgImageUserProfile.spec.ts
around the affected test to mock the registry response alongside the rejected
Algolia request and assert the fallback count.
- Around line 10-16: Validate and normalize the username before the Algolia and
npm registry lookups in the profile-loading flow. Require a canonical npm
username format and reject or safely handle invalid values before interpolating
it into owners.name and maintainer query parameters; preserve the existing
package-count lookup for valid usernames.

---

Nitpick comments:
In `@test/nuxt/components/OgImageUserProfile.spec.ts`:
- Around line 21-26: Update mockNpmFallback to remove the explicit any cast and
configure the global $fetch spy using typed mockResolvedValue and
mockRejectedValue calls. Preserve the existing total-based behavior, resolving
with the count object for non-null totals and rejecting with the network error
for null.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: a206a11f-8362-4b10-8147-38ce49196f31

📥 Commits

Reviewing files that changed from the base of the PR and between 2c78c40 and 8a38f8c.

📒 Files selected for processing (3)
  • app/components/OgImage/UserProfile.takumi.vue
  • app/pages/~[username]/index.vue
  • test/nuxt/components/OgImageUserProfile.spec.ts

Comment thread app/components/OgImage/UserProfile.takumi.vue Outdated
Comment thread app/components/OgImage/UserProfile.takumi.vue Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
test/nuxt/components/OgImageUserProfile.spec.ts (1)

142-156: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Skip-path tests don't guard against an accidental real $fetch call.

Since beforeEach runs vi.restoreAllMocks(), $fetch is back to its real implementation in these two tests. Per the retrieved learning, these tests run under Vitest browser mode with Playwright, so if a future regression in isValidNpmName/username gating accidentally triggers the npm fallback, this would fire a live network request instead of failing loudly and predictably.

Consider mocking $fetch (e.g., a rejecting/no-op mock) and asserting expect($fetch).not.toHaveBeenCalled() in both tests, mirroring the mockSearch assertion already present.

Based on learnings, tests under test/nuxt/ run in Vitest browser mode with Playwright (Chromium), so real fetch calls are possible if the fallback path is unexpectedly triggered.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/nuxt/components/OgImageUserProfile.spec.ts` around lines 142 - 156,
Protect both skip-path tests in the “skips the lookups for an invalid username”
and “renders a generic description and skips fetching when no username is given”
cases by mocking $fetch with a rejecting or no-op mock after beforeEach restores
mocks, then assert $fetch was not called alongside the existing mockSearch
assertions. Keep the tests’ current rendering expectations unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@test/nuxt/components/OgImageUserProfile.spec.ts`:
- Around line 142-156: Protect both skip-path tests in the “skips the lookups
for an invalid username” and “renders a generic description and skips fetching
when no username is given” cases by mocking $fetch with a rejecting or no-op
mock after beforeEach restores mocks, then assert $fetch was not called
alongside the existing mockSearch assertions. Keep the tests’ current rendering
expectations unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 43018076-d937-49cf-a237-ff94976b8d2c

📥 Commits

Reviewing files that changed from the base of the PR and between c0108d1 and 0e3a76d.

📒 Files selected for processing (4)
  • app/components/OgImage/UserProfile.takumi.vue
  • app/pages/~[username]/index.vue
  • test/nuxt/components/OgImageUserProfile.spec.ts
  • test/unit/a11y-component-coverage.spec.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • test/unit/a11y-component-coverage.spec.ts
  • app/pages/~[username]/index.vue
  • app/components/OgImage/UserProfile.takumi.vue

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.

user profile discord embed picture package count

1 participant