mirror of
https://github.com/vercel/next.js.git
synced 2026-09-20 02:25:18 +08:00
8669b07f19
### 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 #
56 lines
1.7 KiB
TypeScript
56 lines
1.7 KiB
TypeScript
import "./globals.css";
|
|
import { Inter } from "next/font/google";
|
|
import { EXAMPLE_PATH, CMS_NAME } from "@/lib/constants";
|
|
|
|
export const metadata = {
|
|
title: `Next.js and ${CMS_NAME} Example`,
|
|
description: `This is a blog built with Next.js and ${CMS_NAME}.`,
|
|
};
|
|
|
|
const inter = Inter({
|
|
variable: "--font-inter",
|
|
subsets: ["latin"],
|
|
display: "swap",
|
|
});
|
|
|
|
function Footer() {
|
|
return (
|
|
<footer className="bg-accent-1 border-t border-accent-2">
|
|
<div className="container mx-auto px-5">
|
|
<div className="py-28 flex flex-col lg:flex-row items-center">
|
|
<h3 className="text-4xl lg:text-5xl font-bold tracking-tighter leading-tight text-center lg:text-left mb-10 lg:mb-0 lg:pr-4 lg:w-1/2">
|
|
Built with Next.js.
|
|
</h3>
|
|
<div className="flex flex-col lg:flex-row justify-center items-center lg:pl-4 lg:w-1/2">
|
|
<a
|
|
href="https://nextjs.org/docs"
|
|
className="mx-3 bg-black hover:bg-white hover:text-black border border-black text-white font-bold py-3 px-12 lg:px-8 duration-200 transition-colors mb-6 lg:mb-0"
|
|
>
|
|
Read Documentation
|
|
</a>
|
|
<a
|
|
href={`https://github.com/vercel/next.js/tree/canary/examples/${EXAMPLE_PATH}`}
|
|
className="mx-3 font-bold hover:underline"
|
|
>
|
|
View on GitHub
|
|
</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</footer>
|
|
);
|
|
}
|
|
|
|
export default function RootLayout({ children }: LayoutProps<"/">) {
|
|
return (
|
|
<html lang="en" className={inter.variable}>
|
|
<body>
|
|
<section className="min-h-screen">
|
|
<main>{children}</main>
|
|
<Footer />
|
|
</section>
|
|
</body>
|
|
</html>
|
|
);
|
|
}
|