From 83341b64a678aee329c77f0cec9a383c58e416b1 Mon Sep 17 00:00:00 2001 From: Akarshit Wal Date: Thu, 28 Jan 2021 21:51:21 -0700 Subject: [PATCH 1/2] (bugfix): not pre-rendering cart with shop Signed-off-by: Akarshit Wal --- pages/[lang]/cart.js | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/pages/[lang]/cart.js b/pages/[lang]/cart.js index 2f3489fda6..aed8f03eec 100644 --- a/pages/[lang]/cart.js +++ b/pages/[lang]/cart.js @@ -16,7 +16,6 @@ import Router from "translations/i18nRouter"; import PageLoading from "components/PageLoading"; import { withApollo } from "lib/apollo/withApollo"; -import { locales } from "translations/config"; import fetchPrimaryShop from "staticUtils/shop/fetchPrimaryShop"; import fetchTranslations from "staticUtils/translations/fetchTranslations"; @@ -177,12 +176,12 @@ class CartPage extends Component { } /** - * Static props for the cart route + * Server props for the cart route * * @param {String} lang - the shop's language * @returns {Object} props */ -export async function getStaticProps({ params: { lang } }) { +export async function getServerSideProps({ params: { lang } }) { return { props: { ...await fetchPrimaryShop(lang), @@ -191,16 +190,4 @@ export async function getStaticProps({ params: { lang } }) { }; } -/** - * Static paths for the cart route - * - * @returns {Object} paths - */ -export async function getStaticPaths() { - return { - paths: locales.map((locale) => ({ params: { lang: locale } })), - fallback: false - }; -} - export default withApollo()(withStyles(styles)(withCart(inject("uiStore")(CartPage)))); From 19c3bee2bc2eb6be7ffe21254406d7145db605c0 Mon Sep 17 00:00:00 2001 From: Akarshit Wal Date: Fri, 29 Jan 2021 12:27:58 -0700 Subject: [PATCH 2/2] (bugfix): check shop variable for null Signed-off-by: Akarshit Wal --- pages/[lang]/index.js | 2 +- pages/[lang]/product/[...slugOrId].js | 2 +- pages/[lang]/tag/[slug].js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pages/[lang]/index.js b/pages/[lang]/index.js index a16e20bbb8..7b9bc3e310 100644 --- a/pages/[lang]/index.js +++ b/pages/[lang]/index.js @@ -98,7 +98,7 @@ export async function getStaticProps({ params: { lang } }) { const primaryShop = await fetchPrimaryShop(lang); const translations = await fetchTranslations(lang, ["common"]); - if (!primaryShop) { + if (!primaryShop?.shop) { return { props: { shop: null, diff --git a/pages/[lang]/product/[...slugOrId].js b/pages/[lang]/product/[...slugOrId].js index 291fbe13c1..1b08e17983 100644 --- a/pages/[lang]/product/[...slugOrId].js +++ b/pages/[lang]/product/[...slugOrId].js @@ -134,7 +134,7 @@ export async function getStaticProps({ params: { slugOrId, lang } }) { const productSlug = slugOrId && slugOrId[0]; const primaryShop = await fetchPrimaryShop(lang); - if (!primaryShop) { + if (!primaryShop?.shop) { return { props: { shop: null, diff --git a/pages/[lang]/tag/[slug].js b/pages/[lang]/tag/[slug].js index 15ac925fb7..7c11c7d9d6 100644 --- a/pages/[lang]/tag/[slug].js +++ b/pages/[lang]/tag/[slug].js @@ -161,7 +161,7 @@ class TagGridPage extends Component { export async function getStaticProps({ params: { lang, slug } }) { const primaryShop = await fetchPrimaryShop(lang); - if (!primaryShop) { + if (!primaryShop?.shop) { return { props: { shop: null,