microsoft / microsoft/GitHubCopilot_Customized

perf: Avoid redundant getTotalItems() calls in Navigation component

Open Beginner friendly
#14 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
66
Forks
38
Avg merge
21d 15h
Merged PRs (30d)
1

Description

User Story

As a shopper,
I want the cart item count badge in the navigation bar to update instantly and efficiently,
so that navigating the site feels snappy regardless of cart size.

Problem

In Navigation.tsx, getTotalItems() is called twice per render — once for the conditional check and once to display the value. Each call iterates the full cart items array via Array.reduce().

// Current — two reduce() calls per render
{getTotalItems() > 0 && (
  <span>
    {getTotalItems()}   {/* second call */}
  </span>
)}

Acceptance Criteria

  • getTotalItems() is called at most once per render in the Navigation component (store result in a variable)
  • The cart badge displays the correct total item count
  • If the total is 0, the badge remains hidden (same as current behavior)
  • No change to visible behavior for the user

Note: This issue is low complexity and a good candidate for a first contribution. It can be implemented in parallel with the other performance issues.

Files

  • frontend/src/components/Navigation.tsx

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Open frontend/src/components/Navigation.tsx and inspect how getTotalItems() is used during rendering. Store the result so the conditional and badge use one calculation, then verify the badge still shows the correct total and stays hidden when the total is 0.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend
Issue type
Refactor
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.