From 3d4479a0ca653b7bd84b01ff167970ee4a1de188 Mon Sep 17 00:00:00 2001 From: Jan Date: Wed, 24 Aug 2022 17:25:56 +0200 Subject: [PATCH] fix(react wrapper): set raw state also in bootstrap --- packages/storefront-react/src/context.tsx | 52 ++++++++++++++++------- 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/packages/storefront-react/src/context.tsx b/packages/storefront-react/src/context.tsx index c2e6c74..2960005 100755 --- a/packages/storefront-react/src/context.tsx +++ b/packages/storefront-react/src/context.tsx @@ -229,19 +229,25 @@ const ShopProvider: React.FC = ({ // load cart if not already loaded by the default cart get method if (cart === undefined && bootstrap.cart === true) { - const res = await client.cart - .getCart({ input: {} }) - .catch(() => ({ data: undefined, error: new Error('unknown error') })) + const res = await client.cart.getCart({ input: {} }).catch(() => ({ + data: undefined, + raw: undefined, + error: new Error('unknown error'), + })) setCart(res.data ?? null) + setRawCart(res.raw ?? null) } // load cart if not already loaded by the custom cart loader else if (cart === undefined && typeof bootstrap.cart === 'function') { - const res = await bootstrap - .cart() - .catch(() => ({ data: undefined, error: new Error('unknown error') })) + const res = await bootstrap.cart().catch(() => ({ + data: undefined, + raw: undefined, + error: new Error('unknown error'), + })) setCart(res.data ?? null) + setRawCart(res.raw ?? null) } // mark bootstrapping as completed @@ -262,19 +268,25 @@ const ShopProvider: React.FC = ({ // load user if not already loaded by the default user get method if (user === undefined && bootstrap.user === true) { - const res = await client.user - .getUser({ input: {} }) - .catch(() => ({ data: undefined, error: new Error('unknown error') })) + const res = await client.user.getUser({ input: {} }).catch(() => ({ + data: undefined, + raw: undefined, + error: new Error('unknown error'), + })) setUser(res.data ?? null) + setRawUser(res.raw ?? null) } // load user if not already loaded by the custom user loader else if (user === undefined && typeof bootstrap.user === 'function') { - const res = await bootstrap - .user() - .catch(() => ({ data: undefined, error: new Error('unknown error') })) + const res = await bootstrap.user().catch(() => ({ + data: undefined, + raw: undefined, + error: new Error('unknown error'), + })) setUser(res.data ?? null) + setRawUser(res.raw ?? null) } // mark bootstrapping as completed @@ -297,20 +309,28 @@ const ShopProvider: React.FC = ({ if (wishlist === undefined && bootstrap.wishlist === true) { const res = await client.wishlist .getWishlist({ input: {} }) - .catch(() => ({ data: undefined, error: new Error('unknown error') })) + .catch(() => ({ + data: undefined, + raw: undefined, + error: new Error('unknown error'), + })) setWishlist(res.data ?? null) + setRawWishlist(res.raw ?? null) } // load wishlist if not already loaded by the custom wishlist loader else if ( wishlist === undefined && typeof bootstrap.wishlist === 'function' ) { - const res = await bootstrap - .wishlist() - .catch(() => ({ data: undefined, error: new Error('unknown error') })) + const res = await bootstrap.wishlist().catch(() => ({ + data: undefined, + raw: undefined, + error: new Error('unknown error'), + })) setWishlist(res.data ?? null) + setRawWishlist(res.raw ?? null) } // mark bootstrapping as completed