From f0105f9f594c1e2035b66af6bdee36adb3356e51 Mon Sep 17 00:00:00 2001 From: Lee Robinson Date: Tue, 26 Mar 2024 16:09:15 -0500 Subject: [PATCH] Suspense --- app/product/[handle]/page.tsx | 18 ++++++++++++------ components/layout/navbar/index.tsx | 11 +++++++---- components/layout/navbar/mobile-menu.tsx | 8 +++++--- components/layout/navbar/search.tsx | 14 ++++++++++++++ components/layout/search/filter/index.tsx | 11 +++++++---- components/product/product-description.tsx | 9 +++++++-- 6 files changed, 52 insertions(+), 19 deletions(-) diff --git a/app/product/[handle]/page.tsx b/app/product/[handle]/page.tsx index cf31f0021..a23f60e68 100644 --- a/app/product/[handle]/page.tsx +++ b/app/product/[handle]/page.tsx @@ -84,12 +84,18 @@ export default async function ProductPage({ params }: { params: { handle: string
- ({ - src: image.url, - altText: image.altText - }))} - /> + + } + > + ({ + src: image.url, + altText: image.altText + }))} + /> +
diff --git a/components/layout/navbar/index.tsx b/components/layout/navbar/index.tsx index 0058d5ec8..294b805a0 100644 --- a/components/layout/navbar/index.tsx +++ b/components/layout/navbar/index.tsx @@ -6,7 +6,7 @@ import { Menu } from 'lib/shopify/types'; import Link from 'next/link'; import { Suspense } from 'react'; import MobileMenu from './mobile-menu'; -import Search from './search'; +import Search, { SearchSkeleton } from './search'; const { SITE_NAME } = process.env; export default async function Navbar() { @@ -15,8 +15,9 @@ export default async function Navbar() { return (
@@ -41,7 +42,9 @@ export default async function Navbar() { ) : null}
- + }> + +
}> diff --git a/components/layout/navbar/mobile-menu.tsx b/components/layout/navbar/mobile-menu.tsx index 6d798370e..b913a23b9 100644 --- a/components/layout/navbar/mobile-menu.tsx +++ b/components/layout/navbar/mobile-menu.tsx @@ -3,11 +3,11 @@ import { Dialog, Transition } from '@headlessui/react'; import Link from 'next/link'; import { usePathname, useSearchParams } from 'next/navigation'; -import { Fragment, useEffect, useState } from 'react'; +import { Fragment, Suspense, useEffect, useState } from 'react'; import { Bars3Icon, XMarkIcon } from '@heroicons/react/24/outline'; import { Menu } from 'lib/shopify/types'; -import Search from './search'; +import Search, { SearchSkeleton } from './search'; export default function MobileMenu({ menu }: { menu: Menu[] }) { const pathname = usePathname(); @@ -72,7 +72,9 @@ export default function MobileMenu({ menu }: { menu: Menu[] }) {
- + }> + +
{menu.length ? (
    diff --git a/components/layout/navbar/search.tsx b/components/layout/navbar/search.tsx index 03d152ec9..100605204 100644 --- a/components/layout/navbar/search.tsx +++ b/components/layout/navbar/search.tsx @@ -41,3 +41,17 @@ export default function Search() { ); } + +export function SearchSkeleton() { + return ( +
    + +
    + +
    +
    + ); +} \ No newline at end of file diff --git a/components/layout/search/filter/index.tsx b/components/layout/search/filter/index.tsx index 33a36c6da..51869c24e 100644 --- a/components/layout/search/filter/index.tsx +++ b/components/layout/search/filter/index.tsx @@ -1,4 +1,5 @@ import { SortFilterItem } from 'lib/constants'; +import { Suspense } from 'react'; import FilterItemDropdown from './dropdown'; import { FilterItem } from './item'; @@ -25,11 +26,13 @@ export default function FilterList({ list, title }: { list: ListItem[]; title?: ) : null}
      - -
    + + +
    - -
+ + + ); diff --git a/components/product/product-description.tsx b/components/product/product-description.tsx index a81a6b02c..8c1e69cda 100644 --- a/components/product/product-description.tsx +++ b/components/product/product-description.tsx @@ -2,6 +2,7 @@ import { AddToCart } from 'components/cart/add-to-cart'; import Price from 'components/price'; import Prose from 'components/prose'; import { Product } from 'lib/shopify/types'; +import { Suspense } from 'react'; import { VariantSelector } from './variant-selector'; export function ProductDescription({ product }: { product: Product }) { @@ -16,7 +17,9 @@ export function ProductDescription({ product }: { product: Product }) { />
- + + + {product.descriptionHtml ? ( ) : null} - + + + ); }