-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: wrap header and footer in suspense (#1388)
- Loading branch information
Showing
6 changed files
with
94 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@bigcommerce/catalyst-core": minor | ||
--- | ||
|
||
wraps header and footer in suspense boundaries |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,31 @@ | ||
import { unstable_setRequestLocale } from 'next-intl/server'; | ||
import { PropsWithChildren } from 'react'; | ||
import { PropsWithChildren, Suspense } from 'react'; | ||
|
||
import { getSessionCustomerId } from '~/auth'; | ||
import { client } from '~/client'; | ||
import { graphql } from '~/client/graphql'; | ||
import { revalidate } from '~/client/revalidate-target'; | ||
import { Footer } from '~/components/footer/footer'; | ||
import { FooterFragment } from '~/components/footer/fragment'; | ||
import { Header } from '~/components/header'; | ||
import { Header, HeaderSkeleton } from '~/components/header'; | ||
import { Cart } from '~/components/header/cart'; | ||
import { HeaderFragment } from '~/components/header/fragment'; | ||
import { LocaleType } from '~/i18n/routing'; | ||
|
||
interface Props extends PropsWithChildren { | ||
params: { locale: LocaleType }; | ||
} | ||
|
||
const LayoutQuery = graphql( | ||
` | ||
query LayoutQuery { | ||
site { | ||
...HeaderFragment | ||
...FooterFragment | ||
} | ||
} | ||
`, | ||
[HeaderFragment, FooterFragment], | ||
); | ||
|
||
export default async function DefaultLayout({ children, params: { locale } }: Props) { | ||
export default function DefaultLayout({ children, params: { locale } }: Props) { | ||
unstable_setRequestLocale(locale); | ||
|
||
const customerId = await getSessionCustomerId(); | ||
|
||
const { data } = await client.fetch({ | ||
document: LayoutQuery, | ||
fetchOptions: customerId ? { cache: 'no-store' } : { next: { revalidate } }, | ||
}); | ||
|
||
return ( | ||
<> | ||
<Header cart={<Cart />} data={data.site} /> | ||
<Suspense fallback={<HeaderSkeleton />}> | ||
<Header cart={<Cart />} /> | ||
</Suspense> | ||
|
||
<main className="flex-1 px-4 2xl:container sm:px-10 lg:px-12 2xl:mx-auto 2xl:px-0"> | ||
{children} | ||
</main> | ||
|
||
<Footer data={data.site} /> | ||
<Suspense> | ||
<Footer /> | ||
</Suspense> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { graphql } from '~/client/graphql'; | ||
import { FooterFragment } from '~/components/footer/fragment'; | ||
import { HeaderFragment } from '~/components/header/fragment'; | ||
|
||
export const LayoutQuery = graphql( | ||
` | ||
query LayoutQuery { | ||
site { | ||
...HeaderFragment | ||
...FooterFragment | ||
} | ||
} | ||
`, | ||
[HeaderFragment, FooterFragment], | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters