fix: prevent new carts from being marked as stale in validateCart #2968
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 thevalidateCart
resolver. When a new cart was created (without an existingcartEtag
), the function was incorrectly marking it as stale by returningtrue
whenoldEtag == null
. This caused thevalidateCart
mutation to return the server's cart state instead ofnull
, which overrode the optimistic cart updates.The fix:
isOrderFormStale
function to treat new carts (without etag) as not staletrue
tofalse
whenoldEtag == null
Before:
After:
How to test it?
Manual Testing Steps:
http://localhost:3000
)Expected Behavior:
Starters Deploy Preview
References
packages/api/src/platforms/vtex/resolvers/validateCart.ts
Checklist
You may erase this after checking them all 😉
PR Title and Commit Messages
feat
,fix
,chore
,docs
,style
,refactor
,ci
andtest
PR Description
breaking change
,bug
,contributing
,performance
,documentation
..Dependencies
pnpm-lock.yaml
file when there were changes to the packagesDocumentation
@Mariana-Caetano
to review and update (Or submit a doc request)