-
Notifications
You must be signed in to change notification settings - Fork 687
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Fixes Cart page sign out error when cart does not exist in cache #2189
Conversation
|
gift_message | ||
} = cache.data.data[cartIdInCache]; | ||
const { include_gift_receipt, include_printed_card, gift_message } = | ||
cache.data.data[cartIdInCache] || {}; |
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.
I wonder what GraphQL suggests for client side caching/resolvers for this situation. We will likely run into it elsewhere - I wonder if there is some sort of "reset callback" that can reset the store to an initial state. After all, we call resetStore
on sign out which was effectively deleting the cache, causing this to throw. Maybe resetStore
takes a callback?
This is fine, by the way - just postulating.
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.
Yes, I tried that a while ago when I was developing gift options. The problem is our gift options are name spaced to a certain cart id. Reset store, at that time, would not know which cart id to use to reset the store with empty gift options.
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.
Oh yeah @revanth0212 I forgot about that. So instead of doing it on store reset we would have to know to set that initial state whenever a cart is created. Hmm interesting! I don't think we can do that with the way that carts are created right now.
Description
This PR provides a fallback empty object (
{}
) to avoid a destructuring exception thrown when the cart does not exist in our Apollo cache.This surfaced on the
/cart
page after the user signed out: the cache was cleared out using Apollo client'sresetStore
. ButresetStore
also causes all active queries to be refetched.GiftOptions
has one such query that was querying for the cart in the cache. Because it was just cleared out viaresetStore
, the query got backundefined
, which the code then attempted to destructure.Providing the fallback empty object in the case of
undefined
returns the expected result (undefined
values forinclude_gift_receipt
,include_printed_card
, andgift_message
), and results in the ability to sign out from the cart page without error.Related Issue
Closes PWA-368.
Acceptance
Verification Stakeholders
@revanth0212
Specification
Verification Steps
/cart
pageScreenshots / Screen Captures (if appropriate)
Checklist