Skip to content

refactor(vendor): compute priceDisplay once per render - #279

Draft
dccakes wants to merge 1 commit into
mainfrom
claude/sharp-feynman-uoaa2v
Draft

dccakes wants to merge 1 commit into
mainfrom
claude/sharp-feynman-uoaa2v

Conversation

@dccakes

@dccakes dccakes commented Aug 27, 2026

Copy link
Copy Markdown
Owner

Daily Product Improvement — 2026-08-27

Automated improvement selected and implemented by the daily managed product improvement agent.

📝 TLDR

Convert priceDisplay from a called-twice function to a once-computed const in VendorCard.

📝 Description

During a codebase review, the daily improvement agent identified that VendorCard was calling priceDisplay() twice on every render — once as a truthiness guard and again to read the value inside the JSX. The function iterates over quote prices (min/max calculation, formatCurrency calls) both times, doing redundant work.

The fix converts the inline function to an IIFE-evaluated const so the result is computed exactly once and referenced twice.

This Change

  • priceDisplay is now const priceDisplay = (() => { … })() — an immediately-invoked function expression evaluated once at render time.
  • The JSX truthiness guard and value reference both read from the already-computed const: {priceDisplay && <span>…{priceDisplay}</span>}.
  • No behaviour changes; no new dependencies.

Recommendations Reviewed

The agent reviewed the following improvement candidates (all confirmed not covered by an existing open PR):

# Area Description Size
1 VendorCard priceDisplay() called twice per render (selected) Small
2 events-page-client Loading state uses plain text instead of <Loader2> spinner Small
3 GuestSearchFilter handleChangeOption calls setSelectedRsvpFilter redundantly before delegating to filterHouseholdsByInvitation which calls it again Small
4 GuestsView Duplicate literal DrawerDraft initial-state object defined inline Small

Why This Was Selected

The VendorCard double-call is the highest signal-to-noise fix: it is a clear correctness/efficiency issue with no ambiguity, touches a single self-contained expression, carries zero risk of regression, and leaves the component measurably cleaner. The other candidates are valid but either more debatable (spinner style is subjective) or require reading more state-management context to verify safely.

Future Recommendations

  • Events loading state (Small): Replace the plain <p>Loading events…</p> in events-page-client.tsx with a <Loader2 className="animate-spin" /> spinner consistent with other loading states in the app.
  • GuestSearchFilter redundant state set (Small): In handleChangeOption, remove the direct setSelectedRsvpFilter(option) call that precedes the filterHouseholdsByInvitation(option) call, since the latter already sets the same state.
  • GuestsView duplicate DrawerDraft object (Small): Extract the repeated DrawerDraft initial-state literal into a named const to avoid duplication.
  • Event card start-only time display (Medium): Currently event-card.tsx hides the time if only startTime is set and endTime is missing. Show startTime alone when endTime is absent (verify against PR fix(events): show start time even when no end time is set #260 which may address this).

🧪 Testing

  • Manually tested functionality — behaviour is identical; price display renders correctly when quotes exist, is absent when there are none
  • Added/updated tests — no automated tests cover this rendering path; no new tests warranted for this refactor

🧪 How to test as a user

  1. Navigate to the Vendors page in the app.
  2. Add a vendor with one or more quotes at different price points.
  3. Confirm the price range (e.g. $1,000 – $2,500) appears correctly on the vendor card.
  4. Confirm a vendor with no quotes shows no price on its card.

🎨 Style and code quality

  • Change is purely a refactor with no logic changes; Biome/TypeScript type-check passes (only a pre-existing baseUrl deprecation warning, unrelated to this change).

📦 Dependencies

  • No new dependencies introduced.

📝 Files Changed

  • src/components/vendor/vendor-card.tsx — convert priceDisplay function to IIFE const; update JSX references from priceDisplay() to priceDisplay.

Generated by Claude Code

Converts the `priceDisplay` function to an IIFE-computed const so the
quote-price range string is derived exactly once per render rather than
being called twice — once for the truthiness guard and again to read the
value in the JSX.
@vercel

vercel Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

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

Project Deployment Actions Updated (UTC)
scv Error Error Aug 27, 2026 2:17pm

@github-actions

Copy link
Copy Markdown
Contributor

Jest Test Coverage

Coverage Summary

Lines Statements Branches Functions
Coverage: 83%
83.09% (36209/43574) 82.09% (3796/4624) 69.41% (1069/1540)

This branch had an error being deployed

1 failed deployment
Preview — 3a77dfbb Deployed Aug 27, 2026 by vercel[bot]
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.

1 participant