Unverified Commit 8669b07f authored by Manoraj K's avatar Manoraj K Committed by GitHub

fix(cms-contentful): await draftMode() and use Promise<> params type (#95631)

### What?
Fix the `cms-contentful` example to use the async APIs introduced in
Next.js 15:
- Await `draftMode()` in `app/page.tsx`, `app/posts/[slug]/page.tsx`,
and
  `app/api/disable-draft/route.ts`
  - Update `params` type to `Promise<{ slug: string }>` and await it in
  `app/posts/[slug]/page.tsx`

### Why?
In Next.js 15, `draftMode()` from `next/headers` became async and must
be awaited.
Page `params` are also now typed as a `Promise`. The example was using
the old
synchronous patterns, causing the build to fail and the app to not work
when running against the latest
version of Next.js -- this example project uses latest version of
next.js in the package.json.

### How?
Awaited `draftMode()` at each call site and updated the `params` type
signature to
  `Promise<{ slug: string }>` with a corresponding `await`.

Closes NEXT-
Fixes #
parent d3e41fb4
import { draftMode } from "next/headers";
export async function GET(request: Request) {
draftMode().disable();
(await draftMode()).disable();
return new Response("Draft mode is disabled");
}
......@@ -41,11 +41,7 @@ function Footer() {
);
}
export default function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
export default function RootLayout({ children }: LayoutProps<"/">) {
return (
<html lang="en" className={inter.variable}>
<body>
......
......@@ -77,7 +77,7 @@ function HeroPost({
}
export default async function Page() {
const { isEnabled } = draftMode();
const { isEnabled } = await draftMode();
const allPosts = await getAllPosts(isEnabled);
const heroPost = allPosts[0];
const morePosts = allPosts.slice(1);
......
......@@ -17,13 +17,10 @@ export async function generateStaticParams() {
}));
}
export default async function PostPage({
params,
}: {
params: { slug: string };
}) {
const { isEnabled } = draftMode();
const { post, morePosts } = await getPostAndMorePosts(params.slug, isEnabled);
export default async function PostPage({ params }: PageProps<"/posts/[slug]">) {
const { isEnabled } = await draftMode();
const { slug } = await params;
const { post, morePosts } = await getPostAndMorePosts(slug, isEnabled);
return (
<div className="container mx-auto px-5">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment