Skip to content

Commit

Permalink
More defensive code to make product pages work
Browse files Browse the repository at this point in the history
  • Loading branch information
gbalint committed Jun 11, 2024
1 parent 8329f05 commit 4e3ca39
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
6 changes: 3 additions & 3 deletions app/routes/products.$handle/route.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export default function Product() {
<Suspense>
<Await resolve={solution}>
{(data) => (
<HighlightSolution data={data.product.solution.reference} />
data.product?.solution != null ? <HighlightSolution data={data.product.solution.reference} /> : null
)}
</Await>
</Suspense>
Expand All @@ -142,13 +142,13 @@ export default function Product() {
<Suspense>
<Await resolve={relatedProducts}>
{(data) => (
<Recommended data={data.product.relatedProducts.references.nodes} />
data.product?.relatedProducts != null ? <Recommended data={data.product.relatedProducts.references.nodes} /> : null
)}
</Await>
</Suspense>
<Suspense>
<Await resolve={spotlight}>
{(data) => <Spotlight data={data.product.spotlight.reference} />}
{(data) => data.product?.spotlight != null ? <Spotlight data={data.product.spotlight.reference} /> : null}
</Await>
</Suspense>
</>
Expand Down
6 changes: 3 additions & 3 deletions app/routes/products.$handle/sections/hero.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ function ProductSummary() {
const accordionData = [
{
title: 'Materials',
content: product.materials.value,
content: product.materials?.value,
},
{
title: 'Care Instructions',
content: product.care_guide.value,
content: product.care_guide?.value,
},
{
title: 'Fit',
content: product.fit.value,
content: product.fit?.value,
},
];

Expand Down
2 changes: 1 addition & 1 deletion app/routes/products.$handle/sections/highlight-details.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {Image} from '@shopify/hydrogen';
export default function HighlightDetails() {
const {details} = useLoaderData();

if (!details) return null;
if (details?.features == null) return null;

const {highlights} = JSON.parse(details.features.reference.content.value);

Expand Down
4 changes: 4 additions & 0 deletions app/routes/products.$handle/sections/reviews.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import {cva, cx} from '@h2/new/utils';
export default function Reviews({data}) {
const {review_count, review_avg, reviews} = data.reviews;

if (reviews == null) {
return null
}

const customerReviews = reviews.references.nodes;

return (
Expand Down

0 comments on commit 4e3ca39

Please sign in to comment.