Skip to content

Commit

Permalink
Merge pull request #746 from reactioncommerce/fix-742-akarshit-empty-…
Browse files Browse the repository at this point in the history
…cart

Don't get shop to pre-render page
  • Loading branch information
Akarshit authored Feb 15, 2021
2 parents 03ee174 + b64722e commit a7d6383
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 18 deletions.
17 changes: 2 additions & 15 deletions pages/[lang]/cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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),
Expand All @@ -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))));
2 changes: 1 addition & 1 deletion pages/[lang]/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion pages/[lang]/product/[...slugOrId].js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion pages/[lang]/tag/[slug].js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit a7d6383

Please sign in to comment.