Last active
January 5, 2026 23:00
-
-
Save landry-fairwinds/8c289b879e2803b284ffa39dcd9a46c7 to your computer and use it in GitHub Desktop.
Next 16 Cache Components + Draft Mode
This file contains hidden or 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
| // page.tsx | |
| const slug = 'home' | |
| export default async function HomePage(_: PageProps<'/'>) { | |
| return ( | |
| <PageLayout breadcrumbs={<PageBreadcrumbs slug={slug} />} footer={<Footnotes />}> | |
| <ErrorBoundary FallbackComponent={ErrorFallback}> | |
| <HeroSlice slug={slug} /> | |
| <SliceRenderer slug={slug} /> | |
| </ErrorBoundary> | |
| </PageLayout> | |
| ) | |
| } | |
| export async function generateMetadata(_: PageProps<'/'>): Promise<Metadata> { | |
| const page = await getPageContentBySlug({ slug }) | |
| if (!page) { | |
| return {} | |
| } | |
| return pageToMetadata(page) | |
| } | |
| // hero-slice.tsx | |
| import { ErrorBoundary } from '@/components/error-boundary' | |
| import { ErrorFallback } from '@/components/error-fallback' | |
| import { CACHE_TAGS } from '@/config/constants' | |
| import { HeroLoader } from '@/features/cms/components/loaders/hero-loader' | |
| import { cacheLife, cacheTag } from 'next/cache' | |
| export async function HeroSlice({ slug }: { slug: string }) { | |
| 'use cache' | |
| cacheTag(CACHE_TAGS.CMS, slug) | |
| cacheLife('max') | |
| return ( | |
| <ErrorBoundary FallbackComponent={ErrorFallback}> | |
| <HeroLoader slug={slug} /> | |
| </ErrorBoundary> | |
| ) | |
| } | |
| // hero-loader.tsx | |
| import { Hero } from '@/features/cms/components/hero/hero' | |
| import { getPageContentBySlug } from '@/features/cms/server/get-page-content-by-slug' | |
| export async function HeroLoader({ slug }: { slug: string }) { | |
| const { isEnabled } = await draftMode() // THIS DOESN'T WORK SINCE IT REQUIRES DYNAMIC API | |
| const page = await getPageContentBySlug({ slug }) | |
| const entry = page?.fields.hero | |
| if (!entry) { | |
| return null | |
| } | |
| return <Hero entry={entry} /> | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment