From ae016b79a93a49bb3db4c51127b226546ffbe27f Mon Sep 17 00:00:00 2001 From: Mike Murray Date: Wed, 1 Jul 2020 10:38:25 -0700 Subject: [PATCH 1/5] fix: unquote and hadolint ignore issues Signed-off-by: Mike Murray --- Dockerfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 2c98834fb7..eb4d60b962 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,7 +24,9 @@ USER node RUN yarn install --production=false --frozen-lockfile --ignore-scripts --non-interactive --no-cache ENV BUILD_ENV=production NODE_ENV=production -RUN export "$(grep -v '^#' .env.${NEXTJS_DOTENV:-prod} | xargs -0) && yarn build" + +# hadolint ignore=SC2046 +RUN export $(grep -v '^#' .env.${NEXTJS_DOTENV:-prod} | xargs -0) && yarn build # Install only prod dependencies now that we've built, to make the image smaller RUN rm -rf node_modules/* From b62cc32564fe94046bb0afa9d9d4304046dab49e Mon Sep 17 00:00:00 2001 From: Mike Murray Date: Thu, 2 Jul 2020 10:27:11 -0700 Subject: [PATCH 2/5] fix: return null shop to fix destructuring issues Signed-off-by: Mike Murray --- staticUtils/shop/fetchPrimaryShop.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/staticUtils/shop/fetchPrimaryShop.js b/staticUtils/shop/fetchPrimaryShop.js index d12615efe5..a0e072b567 100644 --- a/staticUtils/shop/fetchPrimaryShop.js +++ b/staticUtils/shop/fetchPrimaryShop.js @@ -10,5 +10,5 @@ import primaryShopQuery from "./primaryShop.js"; export default async function fetchPrimaryShop(language) { const data = await graphQLRequest(primaryShopQuery, { language }); - return data && data.primaryShop && { shop: data.primaryShop }; + return (data && data.primaryShop && { shop: data.primaryShop }) || { shop: null }; } From 4a8ebe66f7a588bd44af39de8f0736bdab4f72e6 Mon Sep 17 00:00:00 2001 From: Mike Murray Date: Thu, 2 Jul 2020 10:27:46 -0700 Subject: [PATCH 3/5] fix: guard request with try/catch Signed-off-by: Mike Murray --- staticUtils/graphQLRequest.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/staticUtils/graphQLRequest.js b/staticUtils/graphQLRequest.js index aebbd0a82c..5322302c4b 100644 --- a/staticUtils/graphQLRequest.js +++ b/staticUtils/graphQLRequest.js @@ -11,11 +11,11 @@ import appConfig from "../config"; export default async function graphQLRequest(query, variables) { const endpoint = appConfig.IS_BUILDING_NEXTJS === true ? appConfig.BUILD_GRAPHQL_URL : appConfig.INTERNAL_GRAPHQL_URL; - const graphQLClient = new GraphQLClient(endpoint, { - timeout: 20000 - }); - try { + const graphQLClient = new GraphQLClient(endpoint, { + timeout: 20000 + }); + const data = await graphQLClient.request(query, variables); return data; } catch (error) { From 30bc8b14676a8a942754b55718d61b16aedcec33 Mon Sep 17 00:00:00 2001 From: Mike Murray Date: Thu, 2 Jul 2020 10:28:33 -0700 Subject: [PATCH 4/5] fix: ensure page doesn't break if shop isn't available Signed-off-by: Mike Murray --- pages/[lang]/product/[...slugOrId].js | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/pages/[lang]/product/[...slugOrId].js b/pages/[lang]/product/[...slugOrId].js index 222d22fc93..a273865845 100644 --- a/pages/[lang]/product/[...slugOrId].js +++ b/pages/[lang]/product/[...slugOrId].js @@ -77,10 +77,15 @@ function buildJSONLd(product, shop) { function ProductDetailPage({ addItemsToCart, product, isLoadingProduct, shop }) { const router = useRouter(); const currencyCode = (shop && shop.currency.code) || "USD"; - const JSONLd = useMemo(() => buildJSONLd(product, shop), [product, shop]); + const JSONLd = useMemo(() => { + if (product && shop) { + return buildJSONLd(product, shop); + } + return null; + }, [product, shop]); if (isLoadingProduct || router.isFallback) return ; - if (!product) return Not Found; + if (!product && !shop) return Not Found; return ( @@ -127,10 +132,24 @@ ProductDetailPage.propTypes = { */ export async function getStaticProps({ params: { slugOrId, lang } }) { const productSlug = slugOrId && slugOrId[0]; + const primaryShop = await fetchPrimaryShop(lang); + + if (!primaryShop) { + return { + props: { + shop: null, + translations: null, + products: null, + tags: null + }, + // eslint-disable-next-line camelcase + unstable_revalidate: 1 // Revalidate immediately + }; + } return { props: { - ...await fetchPrimaryShop(lang), + ...primaryShop, ...await fetchTranslations(lang, ["common", "productDetail"]), ...await fetchCatalogProduct(productSlug), ...await fetchAllTags(lang) From a7ef4968e845a24c3458730133505b656526cc99 Mon Sep 17 00:00:00 2001 From: Mike Murray Date: Thu, 2 Jul 2020 10:29:05 -0700 Subject: [PATCH 5/5] fix: prevent page from breaking when shop null Signed-off-by: Mike Murray --- pages/[lang]/tag/[slug].js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/pages/[lang]/tag/[slug].js b/pages/[lang]/tag/[slug].js index b4aed850a5..15ac925fb7 100644 --- a/pages/[lang]/tag/[slug].js +++ b/pages/[lang]/tag/[slug].js @@ -109,7 +109,7 @@ class TagGridPage extends Component { const pageSize = routingStore.query && routingStore.query.limit ? parseInt(routingStore.query.limit, 10) : uiStore.pageSize; const sortBy = routingStore.query && routingStore.query.sortby ? routingStore.query.sortby : uiStore.sortBy; - if (!tag) { + if (!tag && !shop) { return (