Created
January 14, 2021 18:11
-
-
Save wesbos/77359f617cac497c167b31a8e6b08581 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function update(cache, payload) { | |
cache.evict(cache.identify(payload.data.deleteCartItem)); | |
} | |
const [removeFromCart, { loading }] = useMutation(REMOVE_FROM_CART_MUTATION, { | |
variables: { id }, | |
update, | |
// When the optimistic response comes back, it seems to re-fetch every single query on the page, leaving `data` from queries undefined (and loading and error undefined as well), causing the layout to break. | |
// // The error itself comes from next.js, and it does seem that the item is evicted from the cache before that happens... | |
// optimisticResponse: { | |
// deleteCartItem: { | |
// __typename: 'CartItem', | |
// id, | |
// }, | |
// }, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, they fixed that bug in modern versions of @apollo/client (I am using 3.6.9), update it and it will work
or you can wrap evict inside setTimeout, like this:
setTimeout(() => { cache.evict(cache.identify(payload.data.deleteCartItem)); }, 0);
and it also will work with OptimisticResponse.