Skip to content

Commit

Permalink
chore: update draftMode() calls for async use
Browse files Browse the repository at this point in the history
  • Loading branch information
robp committed Nov 8, 2024
1 parent 2a6f245 commit e7f4520
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions app/[locale]/[[...slug]]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export default async function LandingPage(props: PageProps) {
setStaticParamsLocale(locale);
const slug = params.slug?.join('/') ?? 'home';

const { isEnabled: isDraftMode } = await draftMode();
const isDraftMode = (await draftMode()).isEnabled;

const pageData = await getPage(slug, getLocaleFromPath(locale), isDraftMode);

Expand Down Expand Up @@ -159,7 +159,7 @@ export async function generateMetadata(props: PageProps): Promise<Metadata> {
const params = await props.params;
const { locale } = params;
const slug = params.slug?.join('/') ?? 'home';
const { isEnabled: isDraftMode } = await draftMode();
const isDraftMode = (await draftMode()).isEnabled;
return getPageMetadata(slug, getLocaleFromPath(locale), isDraftMode);
}

Expand Down
2 changes: 1 addition & 1 deletion app/[locale]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default async function RootLayout(props: { children: React.ReactNode; par

const shouldInjectToolbar = process.env.NODE_ENV === 'development';
const { locale } = params;
const { isEnabled: isDraftMode } = await draftMode();
const isDraftMode = (await draftMode()).isEnabled;

const layoutQuery = graphql(
`
Expand Down
6 changes: 3 additions & 3 deletions components/site-header/site-header.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { draftMode, type UnsafeUnwrappedDraftMode } from 'next/headers';
import { draftMode } from 'next/headers';
import Link from 'next/link';

import { Navigation } from '#/components/navigation';

// TODO: Fix fragment unmasking to type navigationData, if possible.
export function SiteHeader(props: { navigationData: any }) {
const { isEnabled: isDraftMode } = draftMode() as unknown as UnsafeUnwrappedDraftMode;
export async function SiteHeader(props: { navigationData: any }) {
const isDraftMode = (await draftMode()).isEnabled;
return (
<>
{isDraftMode && (
Expand Down

0 comments on commit e7f4520

Please sign in to comment.