Js-buy-sdk: Cart updates are not persisting (fetch cart returns stale data)

Created on 9 Apr 2019  路  11Comments  路  Source: Shopify/js-buy-sdk

Describe the bug
fetching a cart after altering it (whether by adding new items or changing quantities) will return stale data, with old line items, quantities, and updatedAt field. This is currently making shopping on our site basically impossible.

To Reproduce

  • Fetch an existing cart via id
  • Add an item to it, or change a quantity - response will show correctly updated cart (with one line item)
  • Fetch cart again, response will have cart without the added item

Fetching an existing cart:

{
    "query": "fragment VariantFragment on ProductVariant  { id,title,price,weight,available,sku,compareAtPrice,image { id,src,altText },selectedOptions { name,value } },fragment VariantWithProductFragment on ProductVariant  { ...VariantFragment,product { id } },fragment MailingAddressFragment on MailingAddress  { id,address1,address2,city,company,country,firstName,formatted,lastName,latitude,longitude,phone,province,zip,name,countryCode,provinceCode },fragment CheckoutFragment on Checkout  { id,ready,requiresShipping,note,paymentDue,webUrl,orderStatusUrl,taxExempt,taxesIncluded,currencyCode,totalTax,subtotalPrice,totalPrice,completedAt,createdAt,updatedAt,shippingAddress { ...MailingAddressFragment },shippingLine { handle,price,title },customAttributes { key,value },order { id,processedAt,orderNumber,subtotalPrice,totalShippingPrice,totalTax,totalPrice,currencyCode,totalRefunded,customerUrl,shippingAddress { ...MailingAddressFragment },lineItems (first: 250) { pageInfo { hasNextPage,hasPreviousPage },edges { cursor,node { title,variant { ...VariantWithProductFragment },quantity,customAttributes { key,value } } } } },lineItems (first: 250) { pageInfo { hasNextPage,hasPreviousPage },edges { cursor,node { id,title,variant { ...VariantWithProductFragment },quantity,customAttributes { key,value } } } } },query ($id:ID!)  { node (id: $id) { __typename,...CheckoutFragment } }",
    "variables": {
        "id": "Z2lkOi8vc2hvcGlmeS9DaGVja291dC8yNTJkOTRkMTI5ZjA4NTE1ZGU5NzYwYjVhNzdjYmEzNT9rZXk9NTQ3YWM1YjQ3NWU0NWY0YmU3MTYwM2Y3MTE0N2YwZTE="
    }
}

Response (X-Request-Id: 4a6fd268-755e-4d99-a21c-b634fadef123):

{
    "data": {
        "node": {
            "__typename": "Checkout",
            "id": "Z2lkOi8vc2hvcGlmeS9DaGVja291dC8yNTJkOTRkMTI5ZjA4NTE1ZGU5NzYwYjVhNzdjYmEzNT9rZXk9NTQ3YWM1YjQ3NWU0NWY0YmU3MTYwM2Y3MTE0N2YwZTE=",
            "ready": true,
            "requiresShipping": true,
            "note": null,
            "paymentDue": "216.88",
            "webUrl": "https://shop.mene.com/15925969/checkouts/252d94d129f08515de9760b5a77cba35?key=547ac5b475e45f4be71603f71147f0e1",
            "orderStatusUrl": null,
            "taxExempt": false,
            "taxesIncluded": false,
            "currencyCode": "USD",
            "totalTax": "0.00",
            "subtotalPrice": "216.88",
            "totalPrice": "216.88",
            "completedAt": null,
            "createdAt": "2019-04-09T09:39:56Z",
            "updatedAt": "2019-04-09T09:39:59Z",
            "shippingAddress": null,
            "shippingLine": null,
            "customAttributes": [],
            "order": null,
            "lineItems": {
                "pageInfo": {
                    "hasNextPage": false,
                    "hasPreviousPage": false
                },
                "edges": [
                    {
                        "cursor": "eyJsYXN0X2lkIjoiZjNhZWViZmI1Mzk3NTAyODY1YzlkNGI2NGQxOGI0NmIiLCJsYXN0X3ZhbHVlIjoiZjNhZWViZmI1Mzk3NTAyODY1YzlkNGI2NGQxOGI0NmIifQ==",
                        "node": {
                            "id": "Z2lkOi8vc2hvcGlmeS9DaGVja291dExpbmVJdGVtL2YzYWVlYmZiNTM5NzUwMjg2NWM5ZDRiNjRkMThiNDZiP2NoZWNrb3V0PTI1MmQ5NGQxMjlmMDg1MTVkZTk3NjBiNWE3N2NiYTM1",
                            "title": "Sunflower Charm",
                            "variant": {
                                "product": {
                                    "id": "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0LzE3ODc3ODk1MDg2NTc="
                                },
                                "id": "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0VmFyaWFudC8xNDI3Mzg3NDM5NTE4NQ==",
                                "title": "24K Gold",
                                "price": "216.88",
                                "weight": 3890,
                                "available": true,
                                "sku": "MC18.160B",
                                "compareAtPrice": null,
                                "image": {
                                    "id": "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0SW1hZ2UvNTU2MDI4ODgwNDkxMw==",
                                    "src": "https://cdn.shopify.com/s/files/1/1592/5969/products/MC18.160B-chm.st.c.jpg?v=1552323457",
                                    "altText": null
                                },
                                "selectedOptions": [
                                    {
                                        "name": "Component",
                                        "value": "24K Gold"
                                    }
                                ]
                            },
                            "quantity": 1,
                            "customAttributes": []
                        }
                    }
                ]
            }
        }
    }
}

Adding an item to the cart

{
    "query": "fragment VariantFragment on ProductVariant  { id,title,price,weight,available,sku,compareAtPrice,image { id,src,altText },selectedOptions { name,value } },fragment VariantWithProductFragment on ProductVariant  { ...VariantFragment,product { id } },fragment UserErrorFragment on UserError  { field,message },fragment MailingAddressFragment on MailingAddress  { id,address1,address2,city,company,country,firstName,formatted,lastName,latitude,longitude,phone,province,zip,name,countryCode,provinceCode },fragment CheckoutFragment on Checkout  { id,ready,requiresShipping,note,paymentDue,webUrl,orderStatusUrl,taxExempt,taxesIncluded,currencyCode,totalTax,subtotalPrice,totalPrice,completedAt,createdAt,updatedAt,shippingAddress { ...MailingAddressFragment },shippingLine { handle,price,title },customAttributes { key,value },order { id,processedAt,orderNumber,subtotalPrice,totalShippingPrice,totalTax,totalPrice,currencyCode,totalRefunded,customerUrl,shippingAddress { ...MailingAddressFragment },lineItems (first: 250) { pageInfo { hasNextPage,hasPreviousPage },edges { cursor,node { title,variant { ...VariantWithProductFragment },quantity,customAttributes { key,value } } } } },lineItems (first: 250) { pageInfo { hasNextPage,hasPreviousPage },edges { cursor,node { id,title,variant { ...VariantWithProductFragment },quantity,customAttributes { key,value } } } } },mutation ($checkoutId:ID!,$lineItems:[CheckoutLineItemInput!]!)  { checkoutLineItemsAdd (checkoutId: $checkoutId lineItems: $lineItems) { userErrors { ...UserErrorFragment },checkout { ...CheckoutFragment } } }",
    "variables": {
        "checkoutId": "Z2lkOi8vc2hvcGlmeS9DaGVja291dC8yNTJkOTRkMTI5ZjA4NTE1ZGU5NzYwYjVhNzdjYmEzNT9rZXk9NTQ3YWM1YjQ3NWU0NWY0YmU3MTYwM2Y3MTE0N2YwZTE=",
        "lineItems": [
            {
                "variantId": "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0VmFyaWFudC8xNDI3Mzg4NzY5ODk5Mw==",
                "quantity": 1,
                "customAttributes": []
            }
        ]
    }
}

response (X-Request-Id: 033dd495-4dc0-4241-8543-5e51827c73b6):

{
    "data": {
        "checkoutLineItemsAdd": {
            "userErrors": [],
            "checkout": {
                "id": "Z2lkOi8vc2hvcGlmeS9DaGVja291dC8yNTJkOTRkMTI5ZjA4NTE1ZGU5NzYwYjVhNzdjYmEzNT9rZXk9NTQ3YWM1YjQ3NWU0NWY0YmU3MTYwM2Y3MTE0N2YwZTE=",
                "ready": true,
                "requiresShipping": true,
                "note": null,
                "paymentDue": "622.21",
                "webUrl": "https://shop.mene.com/15925969/checkouts/252d94d129f08515de9760b5a77cba35?key=547ac5b475e45f4be71603f71147f0e1",
                "orderStatusUrl": null,
                "taxExempt": false,
                "taxesIncluded": false,
                "currencyCode": "USD",
                "totalTax": "0.00",
                "subtotalPrice": "622.21",
                "totalPrice": "622.21",
                "completedAt": null,
                "createdAt": "2019-04-09T09:39:56Z",
                "updatedAt": "2019-04-09T09:42:10Z",
                "shippingAddress": null,
                "shippingLine": null,
                "customAttributes": [],
                "order": null,
                "lineItems": {
                    "pageInfo": {
                        "hasNextPage": false,
                        "hasPreviousPage": false
                    },
                    "edges": [
                        {
                            "cursor": "eyJsYXN0X2lkIjoiOTkxYTQyYzE3MzEyZTFkMjhkMjU4MjkzMWJjYWRmNzQiLCJsYXN0X3ZhbHVlIjoiOTkxYTQyYzE3MzEyZTFkMjhkMjU4MjkzMWJjYWRmNzQifQ==",
                            "node": {
                                "id": "Z2lkOi8vc2hvcGlmeS9DaGVja291dExpbmVJdGVtLzk5MWE0MmMxNzMxMmUxZDI4ZDI1ODI5MzFiY2FkZjc0P2NoZWNrb3V0PTI1MmQ5NGQxMjlmMDg1MTVkZTk3NjBiNWE3N2NiYTM1",
                                "title": "Apple Charm",
                                "variant": {
                                    "product": {
                                        "id": "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0LzE3ODc3OTE0NzQ3Mzc="
                                    },
                                    "id": "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0VmFyaWFudC8xNDI3Mzg4NzY5ODk5Mw==",
                                    "title": "24K Gold",
                                    "price": "188.45",
                                    "weight": 3380,
                                    "available": true,
                                    "sku": "MC18.166A",
                                    "compareAtPrice": null,
                                    "image": {
                                        "id": "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0SW1hZ2UvNTQ3MzU0MzUyMDMwNQ==",
                                        "src": "https://cdn.shopify.com/s/files/1/1592/5969/products/MC18.166A_d.jpg?v=1550764151",
                                        "altText": null
                                    },
                                    "selectedOptions": [
                                        {
                                            "name": "Component",
                                            "value": "24K Gold"
                                        }
                                    ]
                                },
                                "quantity": 1,
                                "customAttributes": []
                            }
                        },
                        {
                            "cursor": "eyJsYXN0X2lkIjoiZjNhZWViZmI1Mzk3NTAyODY1YzlkNGI2NGQxOGI0NmIiLCJsYXN0X3ZhbHVlIjoiZjNhZWViZmI1Mzk3NTAyODY1YzlkNGI2NGQxOGI0NmIifQ==",
                            "node": {
                                "id": "Z2lkOi8vc2hvcGlmeS9DaGVja291dExpbmVJdGVtL2YzYWVlYmZiNTM5NzUwMjg2NWM5ZDRiNjRkMThiNDZiP2NoZWNrb3V0PTI1MmQ5NGQxMjlmMDg1MTVkZTk3NjBiNWE3N2NiYTM1",
                                "title": "Sunflower Charm",
                                "variant": {
                                    "product": {
                                        "id": "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0LzE3ODc3ODk1MDg2NTc="
                                    },
                                    "id": "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0VmFyaWFudC8xNDI3Mzg3NDM5NTE4NQ==",
                                    "title": "24K Gold",
                                    "price": "216.88",
                                    "weight": 3890,
                                    "available": true,
                                    "sku": "MC18.160B",
                                    "compareAtPrice": null,
                                    "image": {
                                        "id": "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0SW1hZ2UvNTU2MDI4ODgwNDkxMw==",
                                        "src": "https://cdn.shopify.com/s/files/1/1592/5969/products/MC18.160B-chm.st.c.jpg?v=1552323457",
                                        "altText": null
                                    },
                                    "selectedOptions": [
                                        {
                                            "name": "Component",
                                            "value": "24K Gold"
                                        }
                                    ]
                                },
                                "quantity": 2,
                                "customAttributes": []
                            }
                        }
                    ]
                }
            }
        }
    }
}

Fetching the cart again:

{
    "query": "fragment VariantFragment on ProductVariant  { id,title,price,weight,available,sku,compareAtPrice,image { id,src,altText },selectedOptions { name,value } },fragment VariantWithProductFragment on ProductVariant  { ...VariantFragment,product { id } },fragment MailingAddressFragment on MailingAddress  { id,address1,address2,city,company,country,firstName,formatted,lastName,latitude,longitude,phone,province,zip,name,countryCode,provinceCode },fragment CheckoutFragment on Checkout  { id,ready,requiresShipping,note,paymentDue,webUrl,orderStatusUrl,taxExempt,taxesIncluded,currencyCode,totalTax,subtotalPrice,totalPrice,completedAt,createdAt,updatedAt,shippingAddress { ...MailingAddressFragment },shippingLine { handle,price,title },customAttributes { key,value },order { id,processedAt,orderNumber,subtotalPrice,totalShippingPrice,totalTax,totalPrice,currencyCode,totalRefunded,customerUrl,shippingAddress { ...MailingAddressFragment },lineItems (first: 250) { pageInfo { hasNextPage,hasPreviousPage },edges { cursor,node { title,variant { ...VariantWithProductFragment },quantity,customAttributes { key,value } } } } },lineItems (first: 250) { pageInfo { hasNextPage,hasPreviousPage },edges { cursor,node { id,title,variant { ...VariantWithProductFragment },quantity,customAttributes { key,value } } } } },query ($id:ID!)  { node (id: $id) { __typename,...CheckoutFragment } }",
    "variables": {
        "id": "Z2lkOi8vc2hvcGlmeS9DaGVja291dC8yNTJkOTRkMTI5ZjA4NTE1ZGU5NzYwYjVhNzdjYmEzNT9rZXk9NTQ3YWM1YjQ3NWU0NWY0YmU3MTYwM2Y3MTE0N2YwZTE="
    }
}

Response (X-Request-Id: 1465c7f8-b7e2-43cf-ab81-7a96938a720c):

{
    "data": {
        "node": {
            "__typename": "Checkout",
            "id": "Z2lkOi8vc2hvcGlmeS9DaGVja291dC8yNTJkOTRkMTI5ZjA4NTE1ZGU5NzYwYjVhNzdjYmEzNT9rZXk9NTQ3YWM1YjQ3NWU0NWY0YmU3MTYwM2Y3MTE0N2YwZTE=",
            "ready": true,
            "requiresShipping": true,
            "note": null,
            "paymentDue": "216.88",
            "webUrl": "https://shop.mene.com/15925969/checkouts/252d94d129f08515de9760b5a77cba35?key=547ac5b475e45f4be71603f71147f0e1",
            "orderStatusUrl": null,
            "taxExempt": false,
            "taxesIncluded": false,
            "currencyCode": "USD",
            "totalTax": "0.00",
            "subtotalPrice": "216.88",
            "totalPrice": "216.88",
            "completedAt": null,
            "createdAt": "2019-04-09T09:39:56Z",
            "updatedAt": "2019-04-09T09:39:59Z",
            "shippingAddress": null,
            "shippingLine": null,
            "customAttributes": [],
            "order": null,
            "lineItems": {
                "pageInfo": {
                    "hasNextPage": false,
                    "hasPreviousPage": false
                },
                "edges": [
                    {
                        "cursor": "eyJsYXN0X2lkIjoiZjNhZWViZmI1Mzk3NTAyODY1YzlkNGI2NGQxOGI0NmIiLCJsYXN0X3ZhbHVlIjoiZjNhZWViZmI1Mzk3NTAyODY1YzlkNGI2NGQxOGI0NmIifQ==",
                        "node": {
                            "id": "Z2lkOi8vc2hvcGlmeS9DaGVja291dExpbmVJdGVtL2YzYWVlYmZiNTM5NzUwMjg2NWM5ZDRiNjRkMThiNDZiP2NoZWNrb3V0PTI1MmQ5NGQxMjlmMDg1MTVkZTk3NjBiNWE3N2NiYTM1",
                            "title": "Sunflower Charm",
                            "variant": {
                                "product": {
                                    "id": "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0LzE3ODc3ODk1MDg2NTc="
                                },
                                "id": "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0VmFyaWFudC8xNDI3Mzg3NDM5NTE4NQ==",
                                "title": "24K Gold",
                                "price": "216.88",
                                "weight": 3890,
                                "available": true,
                                "sku": "MC18.160B",
                                "compareAtPrice": null,
                                "image": {
                                    "id": "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0SW1hZ2UvNTU2MDI4ODgwNDkxMw==",
                                    "src": "https://cdn.shopify.com/s/files/1/1592/5969/products/MC18.160B-chm.st.c.jpg?v=1552323457",
                                    "altText": null
                                },
                                "selectedOptions": [
                                    {
                                        "name": "Component",
                                        "value": "24K Gold"
                                    }
                                ]
                            },
                            "quantity": 1,
                            "customAttributes": []
                        }
                    }
                ]
            }
        }
    }
}

Expected behavior
Fetching the same cart id returns the cart as I saw it in the response after adding items/altering quantites, especially the updatedAt field.

Environment (please complete the following information):

  • OS: MacOS
  • Browser: tested both on latest Chrome and Safari
  • SDK Version v1.4.0

Additional context
Problem as initially reported by our QA was complete impossibility of adding new items. We were able to reproduce, but it seems with carts created a few hours after the problem has shifted to "first add will be successful, but after every other change the cart will be returned as was after first add". I've also seen more inconsistent behaviour, notably when compiling the network data for this issue one cart suddenly updated after several minutes of returning stale content when fetched and showing 12 line items.

Once checkout has begun, cart contents is shown correctly on the checkout pages.

Bug Report Checklist

  • [x] I have read and agree to the CODE_OF_CONDUCT.md
  • [x] I have read the CONTRIBUTING.md guidelines.
  • [x] I have provided a detailed description of the bug, including code samples, and/or network data.
  • [x] I have provided information about my development environment, including SDK version.

Most helpful comment

@agos thank you the great details. I've identified the problem and a fix should be out soon. I'll update this issue when it's done.

All 11 comments

Seconding this post from @agos.

Noticed this exact behaviour on our sites today across production and staging.
Have raised and provided examples to our MSM to follow up with the technical team.

My suspicion is that the problem lies with the JS Buy SDK as fetching the same problematic checkout using graphql and the storefront AP alone returns fresh data with products added after the first one.

We are also noticing this same problem. Started yesterday. Or at least that鈥檚 when we first noticed it.

@agos thank you the great details. I've identified the problem and a fix should be out soon. I'll update this issue when it's done.

We are having the same issue and our shopping cart is completely unoperational. @swalkinshaw Any ETA on the fix?

@swalkinshaw Will this update come with a module upgrade or is it API side?

any news here? we are in one not good place right now haha

@swalkinshaw Will this update come with a module upgrade or is it API side?

My guess is that it'll be on the API side since it seems that most of us hadn't had any change in our code base when this issue arose.

Actually it seems like it's working again on our site. Still double-checking though.

Actually it seems like it's working again on our site. Still double-checking though.

I can confirm it's working on our website as well right now.

Actually it seems like it's working again on our site. Still double-checking though.

Working for us as well.

Yes the fix is purely on our side and it should be fixed now. I am very sorry for the disruption this issue caused and thank you to all of you for helping identify the problem.

Was this page helpful?
0 / 5 - 0 ratings