Skip to content

Conversation

wender
Copy link

@wender wender commented Jul 30, 2025

What's the purpose of this pull request?

Fixes a critical UX issue where the cart count in the minicart icon doesn't update immediately after adding products to the cart. This was causing confusion for users who couldn't see their cart updates in real-time, leading to a poor shopping experience.

How it works?

The issue was in the isOrderFormStale function within the validateCart resolver. When a new cart was created (without an existing cartEtag), the function was incorrectly marking it as stale by returning true when oldEtag == null. This caused the validateCart mutation to return the server's cart state instead of null, which overrode the optimistic cart updates.

The fix:

  • Modified the isOrderFormStale function to treat new carts (without etag) as not stale
  • Changed the logic from returning true to false when oldEtag == null
  • This allows optimistic updates to persist through validation

Before:

if (oldEtag == null) {
  return true  // ❌ New carts were marked as stale
}

After:

if (oldEtag == null) {
  return false  // ✅ New carts are not stale
}

How to test it?

Manual Testing Steps:

  1. Open a FastStore store (e.g., http://localhost:3000)
  2. Navigate to a product page
  3. Add a product to cart using the "Add to Cart" button
  4. Check the minicart icon - it should immediately show the updated count
  5. Add another product - the count should increment properly
  6. Open the cart - verify the items are there

Expected Behavior:

  • Before fix: Cart count wouldn't update immediately after adding items
  • After fix: Cart count should update instantly and persist

Starters Deploy Preview

References

  • Related Issue: Cart count in minicart icon doesn't update after adding products to cart
  • Files Changed: packages/api/src/platforms/vtex/resolvers/validateCart.ts
  • Impact: Better user experience with responsive cart feedback

Checklist

You may erase this after checking them all 😉

PR Title and Commit Messages

  • PR title and commit messages follow the Conventional Commits specification
    • Available prefixes: feat, fix, chore, docs, style, refactor, ci and test

PR Description

  • Added a label according to the PR goal - breaking change, bug, contributing, performance, documentation..

Dependencies

  • Committed the pnpm-lock.yaml file when there were changes to the packages

Documentation

  • PR description
  • For documentation changes, ping @Mariana-Caetano to review and update (Or submit a doc request)

- Fix isOrderFormStale function to not mark new carts as stale when cartEtag is null
- This prevents validateCart from returning server state and overriding optimistic updates
- Resolves issue where cart count in minicart icon doesn't update after adding items
- Add .gitignore entries to prevent development files from being committed
@wender wender requested a review from a team as a code owner July 30, 2025 21:04
@wender wender requested review from gabpaladino and renatamottam and removed request for a team July 30, 2025 21:04
Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@eduardoformiga
Copy link
Member

@wender, thank you for the PR! As we discussed, it looks like the problem doesn't exist anymore. Can we close this PR?

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