-
Notifications
You must be signed in to change notification settings - Fork 286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add better evicted cart support #341
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏼
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎄
/** | ||
* The Cart ID may change after each mutation. We need to update it each time in the session. | ||
*/ | ||
session.set('cartId', cartId); | ||
headers.set('Set-Cookie', await session.commit()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we wrap this in if (storedCartId !== cartId)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably could, but committing it every time is simpler and one less thing to reason about.
Co-authored-by: Fran Dios <[email protected]>
In #325, we attempted to solve an issue that exists today in the SFAPI Cart implementation: carts will be "evicted" from storage after X days of inactivity.
However, as discussed here:https://github.com/Shopify/core-issues/issues/48930 that would be solving the problem at the wrong layer. Clients like Hydrogen should not be concerned about this implementation detail.
Instead, the Cart API will be updated to "soft-404" for mutations against an evicted cart, and return a new Cart ID instead.
This PR:
cartId
is updated in the session after each mutation