Shopify / js-buy-sdk

The JS Buy SDK is a lightweight library that allows you to build ecommerce into any website. It is based on Shopify's API and provides the ability to retrieve products and collections from your shop, add products to a cart, and checkout.
https://shopify.github.io/js-buy-sdk
MIT License
987 stars 262 forks source link

FetchNextPage is not working since v2.17.0 #920

Closed jacksonwangdev closed 1 year ago

jacksonwangdev commented 1 year ago

Bug details

Describe the bug I have been using js-buy-sdk library in my React Native application Before update to v2.17.0, i could fetch all the collection's products by using fetchWithProducts and then FetchNextPage for pagination. But after the update, i get the following:

[TypeError: Cannot convert undefined value to object]

To Reproduce Steps to reproduce the behaviour:

The client is intialised as per normal:

var Shopify = Client.buildClient({
    domain: Constants.Shopify.url,
    storefrontAccessToken: Constants.Shopify.storefrontAccessToken,
});

Call the fetchWithProducts function:

fetchProductsByCollectionId: async (id, per_page) => {
        try {
            const responses = await Shopify.collection.fetchWithProducts(id, {productsFirst: per_page});
            return responses.products.map((item) => new Product(item));
        } catch (err) {
            console.log(err);
            return undefined;
        }
   }

And then call the FetchNextPage for pagination

fetchNextPage: async (list) => { // list is the output of fetchProductsByCollectionId function above
        if (!list) {return undefined;}
        try {
            const responses = await Shopify.fetchNextPage(list);
            if (responses) {
                const responseJson = responses.model;
                return responseJson.map((item) => new Product(item));
            }
            return undefined;
        } catch (err) {
            console.log(err);
            return undefined;
        }
    }

Expected behavior fetchNextPage working fine and i can load more data when i'm scrolling down the product list

Environment (please complete the following information):

https://github.com/Shopify/js-buy-sdk/issues/920#tasklist-block-07048f48-c3be-4cd6-a577-03d477369e08

melissaluu commented 1 year ago

This is now fixed in the latest SDK v2.17.1 - thanks for letting us know!