Add suspense to pages

This commit is contained in:
Henrik Larsson 2023-08-29 20:58:44 +02:00
parent 21bfa76db0
commit 11ff96c729

View File

@ -13,6 +13,7 @@ import type { Metadata } from 'next';
import { LiveQuery } from 'next-sanity/preview/live-query'; import { LiveQuery } from 'next-sanity/preview/live-query';
import { draftMode } from 'next/headers'; import { draftMode } from 'next/headers';
import { notFound } from 'next/navigation'; import { notFound } from 'next/navigation';
import { Suspense } from 'react';
export async function generateMetadata({ export async function generateMetadata({
params params
@ -107,10 +108,26 @@ export default async function Page({ params }: PageParams) {
as={PagePreview} as={PagePreview}
> >
<> <>
{docType === 'page' && <SinglePage data={data} />} {docType === 'page' && (
{docType === 'product' && <ProductPage data={data} />} <Suspense fallback={<div>Loading page...</div>}>
{docType === 'category' && <CategoryPage data={data} />} <SinglePage data={data} />
{docType === 'search' && <SearchPage data={data} />} </Suspense>
)}
{docType === 'product' && (
<Suspense fallback={<div>Loading product...</div>}>
<ProductPage data={data} />
</Suspense>
)}
{docType === 'category' && (
<Suspense fallback={<div>Loading category...</div>}>
<CategoryPage data={data} />
</Suspense>
)}
{docType === 'search' && (
<Suspense fallback={<div>Loading search...</div>}>
<SearchPage data={data} />
</Suspense>
)}
</> </>
</LiveQuery> </LiveQuery>
); );